Example #1
0
        private static void TrainModel(Network model, Func <Image, Array> getInput)
        {
            int total   = 10000;
            int current = 0;

            using (var pbar = new ProgressBar(total, "Training Model"))
            {
                foreach (var image in MnistReader.ReadTrainingData(total))
                {
                    var target = Helper.CreateTarget(image.Label, NumberOfClasses);
                    model.TrainModel(getInput(image), target);
                    pbar.Tick($"Training Model: {++current} of {total}");
                }
            }
        }
Example #2
0
        private static double TestModel(Model model, Func <Image, Array> getInput)
        {
            var results = new List <double>();
            int total   = 1000;
            int current = 0;

            using (var pbar = new ProgressBar(total, "Testing Model"))
            {
                foreach (var image in MnistReader.ReadTestData(total))
                {
                    var res = model.Predict(getInput(image));
                    results.Add(Helper.IntegerFromOutput(res) == image.Label ? 1 : 0);
                    pbar.Tick($"Testing Model: {++current} of {total}");
                }
            }

            return(results.Average());
        }