Skip to content

Commit 220b7e3

Browse files
authored
Update README.md
1 parent 17b522b commit 220b7e3

File tree

1 file changed

+25
-16
lines changed

1 file changed

+25
-16
lines changed

README.md

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
`NeuralNetwork.NET` is a .NET Standard 2.0 library that implements a Convolutional Neural Network with customizable layers, built from scratch with C#.
55
It provides simple APIs to define a CNN structure and to train the network using Stochastic Gradient Descent, as well as methods to save/load a network and its metadata and more.
66

7-
There's also a secondary .NET Framework 4.7.1 library available, `NeuralNetwork.NET.Cuda` that leverages the GPU and the cuDNN toolkit to greatly increase the performances when training or using a neural network.
7+
The library also exposes Cuda-accelerated layers with more advanced features that leverage the GPU and the cuDNN toolkit to greatly increase the performances when training or using a neural network.
88

99
# Table of Contents
1010

@@ -22,21 +22,21 @@ Training a neural network is pretty straightforward - just use the methods in th
2222

2323
```C#
2424
// A convolutional neural network to use with the MNIST dataset
25-
INeuralNetwork network = NetworkManager.NewNetwork(TensorInfo.CreateForGrayscaleImage(28, 28),
26-
t => NetworkLayers.Convolutional(t, (5, 5), 20, ActivationFunctionType.Identity),
27-
t => NetworkLayers.Pooling(t, ActivationFunctionType.LeakyReLU),
28-
t => NetworkLayers.Convolutional(t, (3, 3), 40, ActivationFunctionType.Identity),
29-
t => NetworkLayers.Pooling(t, ActivationFunctionType.LeakyReLU),
30-
t => NetworkLayers.FullyConnected(t, 125, ActivationFunctionType.LeakyReLU),
31-
t => NetworkLayers.FullyConnected(t, 64, ActivationFunctionType.LeakyReLU),
32-
t => NetworkLayers.Softmax(t, 10));
25+
INeuralNetwork network = NetworkManager.NewSequential(TensorInfo.CreateForGrayscaleImage(28, 28),
26+
NetworkLayers.Convolutional((5, 5), 20, ActivationFunctionType.Identity),
27+
NetworkLayers.Pooling(ActivationFunctionType.LeakyReLU),
28+
NetworkLayers.Convolutional((3, 3), 40, ActivationFunctionType.Identity),
29+
NetworkLayers.Pooling(ActivationFunctionType.LeakyReLU),
30+
NetworkLayers.FullyConnected(125, ActivationFunctionType.LeakyReLU),
31+
NetworkLayers.FullyConnected(64, ActivationFunctionType.LeakyReLU),
32+
NetworkLayers.Softmax(10));
3333

3434
// Train the network using Adadelta and 0.5 dropout probability
3535
TrainingSessionResult result = NetworkManager.TrainNetwork(network,
3636
dataset, // A (float[,], float[,]) tuple with the training samples and labels
3737
60, // The expected number of training epochs to run
3838
100, // The size of each training mini-batch
39-
TrainingAlgorithmsInfo.CreateForAdadelta(), // The training algorithm to use
39+
TrainingAlgorithmsInfo.Adadelta(), // The training algorithm to use
4040
0.5f, // Dropout probability
4141
new TestParameters(test, new Progress<BackpropagationProgressEventArgs>(p =>
4242
{
@@ -48,17 +48,26 @@ TrainingSessionResult result = NetworkManager.TrainNetwork(network,
4848

4949
### GPU acceleration
5050

51-
When using the `NeuralNetwork.NET.Cuda` additional library, it is possible to use a different implementation of the available layers that leverages the cuDNN toolkit and parallelizes most of the work on the available CUDA-enabled GPU. To do that, just create a network using the layers from the `CuDnnNetworkLayers` class to enable the GPU processing mode.
51+
When running on a supported framework (.NET Framework, Xamarin or Mono), it is possible to use a different implementation of the available layers that leverages the cuDNN toolkit and parallelizes most of the work on the available CUDA-enabled GPU. To do that, just create a network using the layers from the `CuDnnNetworkLayers` class to enable the GPU processing mode.
5252

5353
Some of the cuDNN-powered layers support additional options than the default layers. Here's an example:
5454

5555
```C#
56-
INetworkLayer convolutional = CuDnnNetworkLayers.Convolutional(
57-
TensorInfo.CreateForRgbImage(32, 32),
58-
ConvolutionInfo.New(ConvolutionMode.CrossCorrelation, 1, 1, 2, 2), // Custom mode, padding and stride
59-
(10, 10), 20, ActivationFunctionType.ReLU);
56+
// A cuDNN convolutional layer, with custom mode, padding and stride
57+
LayerFactory convolutional = CuDnnNetworkLayers.Convolutional(
58+
ConvolutionInfo.New(ConvolutionMode.CrossCorrelation, 2, 2),
59+
(5, 5), 20, ActivationFunctionType.ReLU);
60+
61+
// An inception module, from the design of the GoogLeNet network
62+
LayerFactory inception = CuDnnNetworkLayers.Inception(InceptionInfo.New(
63+
10, // 1x1 convolution kernels
64+
20, 10, // 1x1 + 3x3 convolution pipeline kernels
65+
20, 10, // 1x1 + 5x5 convolution pipeline kernels
66+
PoolingMode.AverageExcludingPadding, 10)); // Pooling mode and 1x1 convolution kernels
6067
```
6168

69+
These `LayerFactory` instances can be used to create a new network just like in the CPU example.
70+
6271
### Serialization and deserialization
6372

6473
The `INeuralNetwork` interface exposes a `Save` method that can be used to serialize any network at any given time.
@@ -82,4 +91,4 @@ The `NeuralNetwork.NET` library requires .NET Standard 2.0 support, so it is ava
8291

8392
In addition to the frameworks above, you need an IDE with C# 7.2 support to compile the library on your PC.
8493

85-
The `NeuralNetwork.NET.Cuda` library requires .NET Framework >= 4.7.1 and a CUDA enabled GPU.
94+
The cuDNN layers require .NET Framework, Xamarin or Mono and a CUDA enabled GPU.

0 commit comments

Comments
 (0)