Exemplo n.º 1
0
        public void MainPass3()
        {
            // Batch size
            ICharacterGenerator characterGenerator = new MyCharacterGenerator(24, 24);

            Console.WriteLine("{0,18} {1,18} {2,18} {3,18}", "Batch size", "Total samples", "Avg train loss", "Accuracy [%]");
            for (int batchSize = 1; batchSize <= 20; batchSize++)
            {
                var hiddenLayerSizes = new List <int>()
                {
                    32, 16
                };
                IOCRModel ocrModel      = new MyOCRModel(characterGenerator, hiddenLayerSizes);
                int       batches       = 65536 / batchSize;
                int       itersPerBatch = 1;
                float     learningRate  = 0.40f;
                var       trainRes      = ocrModel.TrainModel(batches, batchSize, itersPerBatch, learningRate);
                var       testRes       = ocrModel.TestModel(10000);
                Console.WriteLine("{0,18:N2} {1,18} {2,18:N4} {3,18:N2}",
                                  batchSize, trainRes.TotalSamples, trainRes.BatchErrors.Average(), testRes.Accuracy * 100.0);
            }
        }
Exemplo n.º 2
0
        public void MainPass1()
        {
            // Iterations per batch
            ICharacterGenerator characterGenerator = new MyCharacterGenerator(24, 24);

            Console.WriteLine("{0,18} {1,18} {2,18} {3,18}", "Iters per batch", "Total samples", "Avg train loss", "Accuracy [%]");
            for (int itersPerBatch = 1; itersPerBatch <= 256; itersPerBatch *= 2)
            {
                var hiddenLayerSizes = new List <int>()
                {
                    32, 16
                };
                IOCRModel ocrModel     = new MyOCRModel(characterGenerator, hiddenLayerSizes);
                int       batchSize    = 4;
                int       batches      = (65536 / (itersPerBatch * batchSize));
                float     learningRate = 0.20f;
                var       trainRes     = ocrModel.TrainModel(batches, batchSize, itersPerBatch, learningRate);
                var       testRes      = ocrModel.TestModel(10000);
                Console.WriteLine("{0,18} {1,18} {2,18:N4} {3,18:N2}",
                                  itersPerBatch, trainRes.TotalSamples, trainRes.BatchErrors.Average(), testRes.Accuracy * 100.0);
            }
        }
Exemplo n.º 3
0
        public void MainPass4()
        {
            // First hidden layer size (1 HL)
            ICharacterGenerator characterGenerator = new MyCharacterGenerator(24, 24);

            Console.WriteLine("{0,18} {1,18} {2,18} {3,18}", "HL1 size", "Total samples", "Avg train loss", "Accuracy [%]");
            for (int i = 10; i <= 60; i += 2)
            {
                var hiddenLayerSizes = new List <int>()
                {
                    i
                };
                IOCRModel ocrModel      = new MyOCRModel(characterGenerator, hiddenLayerSizes);
                int       batches       = 16384;
                int       batchSize     = 4;
                int       itersPerBatch = 1;
                float     learningRate  = 0.40f;
                var       trainRes      = ocrModel.TrainModel(batches, batchSize, itersPerBatch, learningRate);
                var       testRes       = ocrModel.TestModel(10000);
                Console.WriteLine("{0,18} {1,18} {2,18:N4} {3,18:N2}",
                                  i, trainRes.TotalSamples, trainRes.BatchErrors.Average(), testRes.Accuracy * 100.0);
            }
        }