Skip to content

Neural nets in SharpLearning

Mads Dabros edited this page Jul 9, 2017 · 6 revisions

Introduction

This guide provides a short introduction to using SharpLearning.Neural for learning and using neural nets.

SharpLearning.Neural contains layers for constructing standard fully-connected neural networks and convolutaional neural networks.

To create a NeuralNetLearner, the neural net architecture first has to be defined. This is done using the NeuralNet class together with the layer classes. Following the NeuralNet has to be parsed to a NeuralNetLearner in order to train the network. An example showing how to create a convolutional neural network can be seen below:

// define the neural net architecture
var net = new NeuralNet();
net.Add(new InputLayer(28, 28, 1));
net.Add(new Conv2DLayer(5, 5, 32));
net.Add(new MaxPool2DLayer(2, 2));
net.Add(new Conv2DLayer(5, 5, 32));
net.Add(new MaxPool2DLayer(2, 2));
net.Add(new DropoutLayer(0.5));
net.Add(new DenseLayer(256, Activation.Relu));
net.Add(new DropoutLayer(0.5));
net.Add(new SoftMaxLayer(numberOfClasses));

// Create a classification neural net learner
var learner = new ClassificationNeuralNetLearner(net, loss: new LogLoss());

After the learner is created, it is used in exactly the same way as all the other learners in SharpLearning.

// train the neural network model
var model = learner.Learn(observations, targets);
// Use the model for predicting new observations.
var predictions = model.Predict(testObservations);

There is support for classification and regression using the ClassificationNeuralNetLearner and the RegressionNeuralNetLearner.

More examples on how to use the neural net learners can be found in SharpLearning.Examples/NeuralNets

Data layout

Clone this wiki locally