Ejemplo n.º 1
0
        public static void OpenAndTest(string location)
        {
            string imageFileName = @"C:\Users\user\source\Repos\NumberRecognitionNN\Neural Network\Neural Network\t10k-images.idx3-ubyte";
            string labelFileName = @"C:\Users\user\source\Repos\NumberRecognitionNN\Neural Network\Neural Network\t10k-labels.idx1-ubyte";

            byte[] imageFile = File.ReadAllBytes(imageFileName);
            byte[] labelFile = File.ReadAllBytes(labelFileName);

            NeuralNetwork network = NeuralNetwork.Load(location);

            int imagesIndex = 16;
            int labelIndex  = 8;

            int totalImage   = 0;
            int totalCorrect = 0;

            while (imagesIndex < imageFile.Length)
            {
                double[] imageFeed = new double[784];
                for (int i = 0; i < 784; i++)
                {
                    imageFeed[i] = (imageFile[imagesIndex]) / 256.0;
                    imagesIndex++;
                }

                //imageFeedPrint(imageFeed);
                network.Feed(imageFeed);
                //network.printNeuralNetwork();
                int answer = labelFile[labelIndex];
                int guess  = getIndexOfMax(network.getOutput());
                Console.Write("answer " + answer + " guess " + guess + "\n");
                if (answer == guess)
                {
                    totalCorrect++;
                }
                totalImage++;
                labelIndex++;
            }

            Console.Write("\n" + totalCorrect + "/" + totalImage + "\n");
        }