예제 #1
0
        private void EvaluateDigitFromFile()
        {
            var openFileDialog = new OpenFileDialog
            {
                InitialDirectory = digitsFolder
            };

            DialogResult result = openFileDialog.ShowDialog();

            if (result == DialogResult.OK)
            {
                digitsFolder = Path.GetDirectoryName(openFileDialog.FileName);

                Bitmap digitImage = (Bitmap)Image.FromFile(openFileDialog.FileName);
                digitPictureBox.Image = digitImage;

                string     digitLabel    = Path.GetFileNameWithoutExtension(openFileDialog.FileName).First().ToString();
                int        correctAnswer = int.Parse(digitLabel);
                InputDigit input         = InputDigit.FromImage(correctAnswer, digitImage);

                double[] normalizedPixels = input.Pixels.Select(p => NormalizeGrayScaleValue(p)).ToArray();
                double[] responses        = network.Query(normalizedPixels);

                DisplayAnswer(responses);
            }
        }
예제 #2
0
        private void ReadHandwrittenDigit()
        {
            Bitmap handwrittenDigit = new Bitmap(writingPanel.Width, writingPanel.Height);

            writingPanel.DrawToBitmap(handwrittenDigit, new Rectangle(0, 0, writingPanel.Width, writingPanel.Height));

            InputDigit input = InputDigit.FromImage(0, handwrittenDigit);

            double[] normalizedPixels = input.Pixels.Select(p => NormalizeGrayScaleValue(p)).ToArray();
            double[] responses        = network.Query(normalizedPixels);

            DisplayAnswer(responses);
        }
예제 #3
0
        private List <DigitTestResult> QueryNetwork(NeuralNetwork network)
        {
            synchronizationContext.Post(obj =>
            {
                testStatusText.Text = @"Reading test examples...";
            }, null);

            string[][] testDigits = ReadTestDigitsFrom(Path.Combine(dataFolder, "mnist_test.csv"));

            var testResults = new List <DigitTestResult>();

            foreach (string[] input in testDigits)
            {
                string[] inputDigitPixels = input.Skip(1).ToArray();
                double[] normalizedInput  = NormalizeInput(inputDigitPixels);
                double[] response         = network.Query(normalizedInput);

                double max           = response.Max(x => x);
                int    networkAnswer = response.ToList().IndexOf(max);

                int correctAnswer = int.Parse(input[0]);

                int[]      invertedPixels = inputDigitPixels.Select(int.Parse).ToArray();
                InputDigit inputDigit     = InputDigit.FromInvertedPixels(correctAnswer, invertedPixels);

                var testResult = new DigitTestResult(correctAnswer, networkAnswer, inputDigit.Image);
                testResults.Add(testResult);

                int totalTests         = testResults.Count;
                int correctAnswerCount = testResults.Count(result => result.IsCorrect);

                synchronizationContext.Post(obj =>
                {
                    var testDigitResult       = (DigitTestResult)obj;
                    testDigitPictureBox.Image = testDigitResult.Bitmap;
                    testStatusText.Text       = $@"Total: {totalTests} ; Wrong: {totalTests - correctAnswerCount}";
                }, testResult);
            }

            return(testResults);
        }