public void JsonMetadataSerialization()
        {
            INeuralNetwork network = NetworkManager.NewSequential(TensorInfo.Image <Rgb24>(120, 120),
                                                                  NetworkLayers.Convolutional((10, 10), 20, ActivationType.AbsoluteReLU),
                                                                  NetworkLayers.Convolutional((5, 5), 20, ActivationType.ELU),
                                                                  NetworkLayers.Convolutional((10, 10), 20, ActivationType.Identity),
                                                                  NetworkLayers.Pooling(ActivationType.ReLU),
                                                                  NetworkLayers.Convolutional((10, 10), 20, ActivationType.Identity),
                                                                  NetworkLayers.Pooling(ActivationType.Identity),
                                                                  NetworkLayers.BatchNormalization(NormalizationMode.Spatial, ActivationType.ReLU),
                                                                  NetworkLayers.FullyConnected(125, ActivationType.Tanh),
                                                                  NetworkLayers.Softmax(133));
            string metadata1 = network.SerializeMetadataAsJson();

            Assert.IsTrue(metadata1.Length > 0);
            Assert.IsTrue(metadata1.Equals(network.Clone().SerializeMetadataAsJson()));
            network.Layers.First().To <INetworkLayer, ConvolutionalLayer>().Weights[0] += 0.1f;
            Assert.IsFalse(metadata1.Equals(network.SerializeMetadataAsJson()));
        }
        public static async Task Main()
        {
            // Create the network
            INeuralNetwork network = NetworkManager.NewSequential(TensorInfo.Image <Alpha8>(28, 28),
                                                                  CuDnnNetworkLayers.Convolutional((5, 5), 20, ActivationType.Identity),
                                                                  CuDnnNetworkLayers.Pooling(ActivationType.LeakyReLU),
                                                                  CuDnnNetworkLayers.Convolutional((3, 3), 40, ActivationType.Identity),
                                                                  CuDnnNetworkLayers.Pooling(ActivationType.LeakyReLU),
                                                                  CuDnnNetworkLayers.FullyConnected(125, ActivationType.LeCunTanh),
                                                                  CuDnnNetworkLayers.Softmax(10));

            // Prepare the dataset
            ITrainingDataset trainingData = await Mnist.GetTrainingDatasetAsync(400); // Batches of 400 samples

            ITestDataset testData = await Mnist.GetTestDatasetAsync(p => Printf($"Epoch {p.Iteration}, cost: {p.Result.Cost}, accuracy: {p.Result.Accuracy}"));

            if (trainingData == null || testData == null)
            {
                Printf("Error downloading the datasets");
                Console.ReadKey();
                return;
            }

            // Setup and network training
            CancellationTokenSource cts = new CancellationTokenSource();

            Console.CancelKeyPress += (s, e) => cts.Cancel();
            TrainingSessionResult result = await NetworkManager.TrainNetworkAsync(network,
                                                                                  trainingData,
                                                                                  TrainingAlgorithms.AdaDelta(),
                                                                                  20, 0.5f,
                                                                                  TrackBatchProgress,
                                                                                  testDataset : testData, token : cts.Token);

            // Save the training reports
            string
                timestamp = DateTime.Now.ToString("yy-MM-dd-hh-mm-ss"),
                path      = Path.GetDirectoryName(Path.GetFullPath(Assembly.GetExecutingAssembly().Location)),
                dir       = Path.Combine(path ?? throw new InvalidOperationException("The dll path can't be null"), "TrainingResults", timestamp);

            Directory.CreateDirectory(dir);
            File.WriteAllText(Path.Combine(dir, $"{timestamp}_cost.py"), result.TestReports.AsPythonMatplotlibChart(TrainingReportType.Cost));
            File.WriteAllText(Path.Combine(dir, $"{timestamp}_accuracy.py"), result.TestReports.AsPythonMatplotlibChart(TrainingReportType.Accuracy));
            network.Save(new FileInfo(Path.Combine(dir, $"{timestamp}{NetworkLoader.NetworkFileExtension}")));
            File.WriteAllText(Path.Combine(dir, $"{timestamp}.json"), network.SerializeMetadataAsJson());
            File.WriteAllText(Path.Combine(dir, $"{timestamp}_report.json"), result.SerializeAsJson());
            Printf($"Stop reason: {result.StopReason}, elapsed time: {result.TrainingTime}");
            Console.ReadKey();
        }