Examples
The following examples can be found in the Knet/examples directory.
LinReg
LinReg
— Module.LinReg is a simple linear regression example using artificially generated data. You can run the demo using julia linreg.jl
on the command line or julia> LinReg.main()
at the Julia prompt. Use julia linreg.jl --help
or julia> LinReg.main("--help")
for a list of options. The quadratic loss will be printed at every epoch and optimized parameters will be returned.
Housing
Housing
— Module.This example uses the Housing dataset from the UCI Machine Learning Repository to demonstrate a linear regression model. The dataset has housing related information for 506 neighborhoods in Boston from 1978. Each neighborhood has 14 attributes, the goal is to use the first 13, such as average number of rooms per house, or distance to employment centers, to predict the 14’th attribute: median dollar value of the houses.
You can run the demo using julia housing.jl
. Use julia housing.jl --help
for a list of options. The dataset will be automatically downloaded and randomly split into training and test sets. The quadratic loss for the training and test sets will be printed at every epoch and optimized parameters will be returned.
MNIST
MNIST
— Module.This example learns to classify hand-written digits from the MNIST dataset. There are 60000 training and 10000 test examples. Each input x consists of 784 pixels representing a 28x28 image. The pixel values are normalized to [0,1]. Each output y is converted to a ten-dimensional one-hot vector (a vector that has a single non-zero component) indicating the correct class (0-9) for a given image. 10 is used to represent 0.
You can run the demo using julia mnist.jl
on the command line or julia> MNIST.main()
at the Julia prompt. Options can be used like julia mnist.jl --epochs 3
or julia> MNIST.main("--epochs 3")
. Use julia mnist.jl --help
for a list of options. The dataset will be automatically downloaded. By default a softmax model will be trained for 10 epochs. You can also train a multi-layer perceptron by specifying one or more –hidden sizes. The accuracy for the training and test sets will be printed at every epoch and optimized parameters will be returned.
LeNet
LeNet
— Module.This example learns to classify hand-written digits from the MNIST dataset. There are 60000 training and 10000 test examples. Each input x consists of 784 pixels representing a 28x28 image. The pixel values are normalized to [0,1]. Each output y is converted to a ten-dimensional one-hot vector (a vector that has a single non-zero component) indicating the correct class (0-9) for a given image. 10 is used to represent 0.
You can run the demo using julia lenet.jl
at the command line or julia> LeNet.main()
at the Julia prompt. Use julia lenet.jl --help
or julia> LeNet.main("--help")
for a list of options. The dataset will be automatically downloaded. By default the LeNet convolutional neural network model will be trained for 10 epochs. The accuracy for the training and test sets will be printed at every epoch and optimized parameters will be returned.
CharLM
CharLM
— Module.This example implements an LSTM network for training and testing character-level language models inspired by "The Unreasonable Effectiveness of Recurrent Neural Networks" from the Andrej Karpathy blog. The model can be trained with different genres of text, and can be used to generate original text in the same style.
Example usage:
julia charlm.jl
: trains a model using its own code.julia charlm.jl --data foo.txt
: uses foo.txt to train instead.julia charlm.jl --data foo.txt bar.txt
: uses foo.txt for training and bar.txt for validation. Any number of files can be specified, the first two will be used for training and validation, the rest for testing.julia charlm.jl --best foo.jld --save bar.jld
: saves the best model (according to validation set) to foo.jld, last model to bar.jld.julia charlm.jl --load foo.jld --generate 1000
: generates 1000 characters from the model in foo.jld.julia charlm.jl --help
: describes all available options.
VGG
VGG
— Module.julia vgg.jl image-file-or-url
This example implements the VGG model from `Very Deep Convolutional Networks for Large-Scale Image Recognition', Karen Simonyan and Andrew Zisserman, arXiv technical report 1409.1556, 2014. This example works for D and E models currently. VGG-D is the default model if you do not specify any model.
Paper url: https://arxiv.org/abs/1409.1556
Project page: http://www.robots.ox.ac.uk/~vgg/research/very_deep
MatConvNet weights used here: http://www.vlfeat.org/matconvnet/pretrained
ResNet
ResNet
— Module.julia resnet.jl image-file-or-url
This example implements the ResNet-50, ResNet-101 and ResNet-152 models from 'Deep Residual Learning for Image Regocnition', Kaiming He, Xiangyu Zhang, Shaoqing Ren, Jian Sun, arXiv technical report 1512.03385, 2015.
Paper url: https://arxiv.org/abs/1512.03385
Project page: https://github.com/KaimingHe/deep-residual-networks
MatConvNet weights used here: http://www.vlfeat.org/matconvnet/pretrained
Optimizers
Optimizers
— Module.This example demonstrates the usage of stochastic gradient descent(sgd) based optimization methods. We train LeNet model on MNIST dataset similar to lenet.jl
.
You can run the demo using julia optimizers.jl
. Use julia optimizers.jl --help
for a list of options. By default the LeNet convolutional neural network model will be trained using sgd for 10 epochs. At the end of the training accuracy for the training and test sets for each epoch will be printed and optimized parameters will be returned.
Hyperband
hyperband
— Function.hyperband(getconfig, getloss, maxresource=27, reduction=3)
Hyperparameter optimization using the hyperband algorithm from (Lisha et al. 2016). You can try a simple MNIST example using hyperband(getconfig1,getloss1)
after loading this example.
Arguments
getconfig()
returns random configurations with a user defined type and distribution.getloss(c,n)
returns loss for configurationc
and number of resources (e.g. epochs)n
.maxresource
is the maximum number of resources any one configuration should be given.reduction
is an algorithm parameter (see paper), 3 is a good value.
Overfitting, underfitting, regularization, dropout
softmax.ipynb is an IJulia notebook demonstrating overfitting, underfitting, regularization, and dropout.