private static void Example() { NumberImage[] number = new NumberImage[50]; int countOfCorrectlyRecognized = 0; LoadAndSaveData.GetInstance().LoadNS(NN); for (int order = 0; order < 5; order++) { for (int num = 0; num < 10; num++) { number[order * 10 + num] = LoadAndSaveData.GetInstance().LoadNumberImage(num, order); int answer = NN.GetAnswer(number[order * 10 + num].GetPixels()); Console.WriteLine(order + "" + num + ".png = " + answer); if (num == answer) { countOfCorrectlyRecognized++; } } Console.WriteLine(); } Console.WriteLine((double)countOfCorrectlyRecognized / 50 * 100 + "%\n"); }
public NumberImage[] LoadDataMNIST(string pixelFile, string labelFile, int numImages = 1000) { NumberImage[] result = new NumberImage[numImages]; FileStream pixelsStream = new FileStream(pixelFile, FileMode.Open); FileStream labelsStream = new FileStream(labelFile, FileMode.Open); BinaryReader brImages = new BinaryReader(pixelsStream); BinaryReader brLabels = new BinaryReader(labelsStream); var magicNumber1 = brImages.ReadInt32(); var numberoOfImages = brImages.ReadInt32(); var numberOfRows = brImages.ReadInt32(); int numberOfColumns = brImages.ReadInt32(); int magicNumber2 = brLabels.ReadInt32(); int numberOfItems = brLabels.ReadInt32(); double[][] pixels = new double[28][]; for (int i = 0; i < pixels.Length; ++i) { pixels[i] = new double[28]; } for (int k = 0; k < numImages; ++k) { for (int i = 0; i < 28; ++i) { for (int j = 0; j < 28; ++j) { double byteOnPixel = brImages.ReadByte(); pixels[i][j] = byteOnPixel / 255; } } byte label = brLabels.ReadByte(); NumberImage dImage = new NumberImage(28, 28, pixels, label); result[k] = dImage; } pixelsStream.Close(); labelsStream.Close(); brImages.Close(); brLabels.Close(); return(result); }