|
2 | 2 |
|
3 | 3 | ## What is it? |
4 | 4 | `NeuralNetwork.NET` is a .NET Standard 2.0 library that implements a Convolutional Neural Network with customizable layers, built from scratch with C#. |
5 | | -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 in JSON/binary format and more. |
| 5 | +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. |
6 | 6 |
|
7 | 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. |
8 | 8 |
|
9 | 9 | # Table of Contents |
10 | 10 |
|
11 | 11 | - [Quick start](#quick-start) |
12 | 12 | - [Supervised learning](#supervised-learning) |
| 13 | + - [GPU acceleration](#gpu-acceleration) |
13 | 14 | - [Serialization and deserialization](#serialization-and-deserialization) |
14 | | -- [GPU acceleration](#gpu-acceleration) |
15 | 15 | - [Requirements](#requirements) |
16 | 16 |
|
17 | 17 | # Quick start |
@@ -46,18 +46,32 @@ TrainingSessionResult result = NetworkManager.TrainNetwork(network, |
46 | 46 |
|
47 | 47 | **Note:** the `NetworkManager` methods are also available as asynchronous APIs. |
48 | 48 |
|
49 | | -### Serialization and deserialization |
| 49 | +### GPU acceleration |
50 | 50 |
|
51 | | -The `INeuralNetwork` interface exposes a `SerializeAsJson` method that can be used to serialize any network at any given time. |
52 | | -In order to get a new network instance from a serialized JSON string, just use the `NeuralNetworkLoader.TryLoadJson` method: it will parse the input text and automatically return a neural network with the original parameters. |
| 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. |
53 | 52 |
|
54 | | -There's also an additional `Save` method to save a neural network to a binary file. This provides a small, easy to share file that contains all the info on the current network. |
| 53 | +Some of the cuDNN-powered layers support additional options than the default layers. Here's an example: |
55 | 54 |
|
56 | | -# GPU acceleration |
| 55 | +```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); |
| 60 | +``` |
| 61 | + |
| 62 | +### Serialization and deserialization |
57 | 63 |
|
58 | | -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. |
| 64 | +The `INeuralNetwork` interface exposes a `Save` method that can be used to serialize any network at any given time. |
| 65 | +In order to get a new network instance from a saved file or stream, just use the `NeuralNetworkLoader.TryLoad` method. |
| 66 | + |
| 67 | +As multiple layer types have different implementations across the available libraries, you can specify the layer providers to use when loading a saved network. For example, here's how to load a network using the cuDNN layers, when possible: |
| 68 | + |
| 69 | +```C# |
| 70 | +FileInfo file = new FileInfo(@"C:\...\MySavedNetwork.nnet"); |
| 71 | +INeuralNetwork network = NeuralNetworkLoader.TryLoad(file, CuDnnNetworkLayersDeserializer.Deserializer); |
| 72 | +``` |
59 | 73 |
|
60 | | -Just create a network using the layers from the `CuDnnNetworkLayers` class to enable the GPU processing mode. |
| 74 | +There's also an additional `SaveMetadataAsJson` method to export the metadata of an `INeuralNetwork` instance. |
61 | 75 |
|
62 | 76 | # Requirements |
63 | 77 |
|
|
0 commit comments