void Predict() { var image = reader.Read(currentImageIndex); viewPort.Source = image.Inverse().ToBitmapSource(reader.NumberOfColumns, reader.NumberOfRows); var result = ira.Predict(prepareInput(image)); prediction.Text = result.IndexOfMax().ToString(); expected.Text = lablesReader.Read(currentImageIndex).ToString(); }
void drawMNIST() { var ira = new IRINA_NN(new int[] { 784, 200, 10 }, 0.2); var imageReader = new MNISTDataReader.ImageDataReader(@"D:\NeuralNetworks\DataSets\MNIST\train-images.idx3-ubyte"); var labelReader = new MNISTDataReader.LabelDataReader(@"D:\NeuralNetworks\DataSets\MNIST\train-labels.idx1-ubyte"); var itemsCount = imageReader.ItemsCount; var random = new Random(); Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); for (int epoch = 0; epoch < count; ++epoch) { //var errors = new List<double>(); for (int sample = 0; sample < samplesInBatch; ++sample) { var realIndex = random.Next(0, itemsCount); var input = prepareInput(imageReader.Read(realIndex)); var label = labelReader.Read(realIndex); var target = prepareTarget(label); ira.Train(input, target); //var predicted = ira.Predict(input); //errors.Add(0.99 - predicted[label]); } //SeriesCollection[0].Values.Add(errors.Average()); } stopwatch.Stop(); IRINA_NN.Export(ira, @"mnist.nn"); MessageBox.Show($"Complete { count } epochs, { samplesInBatch } samples per one. Estimated time: { stopwatch.ElapsedMilliseconds }ms"); }