Ejemplo n.º 1
0
        public void Train(MnistImageReader reader)
        {
            // Randomize network's parameters
            RandomizeWeights();
            RandomizeBiases();

            var batchSize  = 1;
            var iterations = reader.ImagesCount / batchSize;
            var matches    = 0;

            Console.WriteLine("Training started");
            var stopwatch = new Stopwatch();

            stopwatch.Restart();

            for (int i = 0; i < iterations; i++)
            {
                if (TrainBatch(batchSize, i, reader))
                {
                    matches++;
                }

                Console.Clear();
                Console.WriteLine($"{(double)(i+1)/iterations*100:F}%");
            }

            stopwatch.Stop();
            var elapsedTime = stopwatch.Elapsed;

            Console.WriteLine($"Trained on {reader.ImagesCount} images in {elapsedTime.Minutes}:{elapsedTime.Seconds}.{elapsedTime.Milliseconds}s.");
        }
Ejemplo n.º 2
0
        private bool TrainBatch(int batchSize, int iteration, MnistImageReader reader)
        {
            int i = 0, matches = 0;

            while (i < batchSize)
            {
                var(image, label) = reader.ReadImage();

                // Upload image into input layer
                UploadImage(image);

                // Create expected results vector
                var expectedResults = new double[activations[^ 1].Length];
Ejemplo n.º 3
0
        public int Recognize(MnistImageReader reader, int numberOfImages)
        {
            int matches = 0;

            for (int i = 0; i < numberOfImages; i++)
            {
                var(image, label) = reader.ReadImage();

                var result = Recognize(image);

                var match = result == label;
                Console.WriteLine($"{i+1}: match={match}, in={label}, out={result}");
                if (match)
                {
                    matches++;
                }
            }

            Console.WriteLine($"RESULT: {((double)matches/(double)numberOfImages*100.0):F}% ({matches}/{numberOfImages})");

            return(numberOfImages);
        }