Machine Learning library for .NET Core.
PM> Install-Package Ann
var network = new Network(LossFunctionType.CrossEntropy, new Flat(0.001), 5);
Creates a neural network object with a Cross-Entropy loss function, flat learning rate 0.001 and 5 output classes
Add layers to network configuration:
network.AddInputLayer(128, 1);
network.AddConvolutionLayer(16, 5);
network.AddActivationLayer(ActivatorType.Relu);
network.AddPoolingLayer(2);
network.AddFlattenLayer();
network.AddDenseLayer(256, true);
network.AddSoftMaxLayer();
AddInputLayer(128, 1)
input layer, which expect input with dimensions 128x128x1
AddConvolutionLayer(16, 5)
convolution layer with 16 filters of size 5x5xD, where D is the depth of the output from a previous layer
AddActivationLayer(ActivatorType.Relu)
activation layer with ReLU activation function
AddPoolingLayer(2)
pooling layer with a vertical and horizontal stride 2
AddFlattenLayer()
flattens the result
AddDenseLayer(256, true)
fully connected layer with biases
AddSoftMaxLayer()
SoftMax activation
model.TrainModel(input, target);
First argument of the TrainModel()
method accepts System.Array. The dimensions of the array must match with a input layer configuration.
Second argument accepts bool[]. The length of the array must match number of classes provided to Network
constructor.
Weights and biases will be adjasted using Stochastic Gradient Descent with backpropagation.
After you are done with trainig you can save the model in JSON file for a later use:
var model = network.BuildModel();
model.Save("model.json");
var model = new Model("model.json");
double[] prediction = model.Predict(input);
TrainModel()
method accepts System.Array, the dimensions of the array must match with a input layer configuration.
There are two sample projects:
- Ann.Mnist
- Ann.Fingers
Pavel koryakin [email protected]
This project is licensed under the MIT License - see the LICENSE.md for details.