private static void PrettyPrint()
        {
            while (true)
            {
                PrintPrettyPrintOptions();

                SharedConsoleCommands.YourInput();
                var input = Colorful.Console.ReadLine();
                ITrainingDatasetDefinition datasetDefinition;
                switch (input)
                {
                case EXIT_CHOICE:
                    return;

                case DIGITS_CHOICE:
                    datasetDefinition = new EMNISTDigitDataset();
                    break;

                case LETTERS_CHOICE:
                    datasetDefinition = new EMNISTLetterDataset();
                    break;

                case UPPERCASE_LETTERS_CHOICE:
                    datasetDefinition = new EMNISTUppercaseLetterDataset();
                    break;

                default:
                    SharedConsoleCommands.InvalidCommand(input);
                    continue;
                }

                try
                {
                    Colorful.Console.WriteLine("Choose line:", Color.Gray);
                    CntkDatasetRow prettyPrintInput = null;
                    try
                    {
                        var inputLineNum = Int32.Parse(Colorful.Console.ReadLine());
                        prettyPrintInput =
                            new CntkEmnistDatasetStreamFetcher().GetRowFromDefinition(datasetDefinition, inputLineNum);
                    }
                    catch (Exception ex) when(ex is ArgumentNullException || ex is FormatException)
                    {
                        Colorful.Console.WriteLine($"Not a valid line number!", Color.IndianRed);
                        continue;
                    }
                    new CntkEmnistDatasetStreamPrinter().PrettyPrint(prettyPrintInput);
                }
                catch (InvalidEmnistDatasetFeatureLengthException)
                {
                    Colorful.Console.WriteLine($"Feature stream is not of length 28*28. Cannot pretty print it.", Color.Gray);
                }
            }
        }
Exemple #2
0
        private static void RunEmnistTraining(string choice)
        {
            ITrainingDatasetDefinition datasetDefinition = null;

            switch (choice)
            {
            case LETTERS_CHOICE:
                datasetDefinition = new EMNISTLetterDataset();
                break;

            case DIGITS_CHOICE:
                datasetDefinition = new EMNISTDigitDataset();
                break;

            case UPPERCASE_LETTERS_CHOICE:
                datasetDefinition = new EMNISTUppercaseLetterDataset();
                break;

            default:
                SharedConsoleCommands.InvalidCommand(choice);
                return;
            }

            TrainingSessionStart(choice);
            var msgPrinter = new ConsolePrinter();

            var outputDir             = $"./{DateTime.Now.ToString("yyyyMMddHHmmss", CultureInfo.InvariantCulture)}/";
            var device                = DeviceDescriptor.GPUDevice(0);
            var trainingConfiguration = new TrainingSessionConfiguration
            {
                Epochs = 200,
                DumpModelSnapshotPerEpoch  = true,
                ProgressEvaluationSeverity = EvaluationSeverity.PerEpoch,
                MinibatchConfig            = new MinibatchConfiguration
                {
                    MinibatchSize = 64,
                    HowManyMinibatchesPerSnapshot      = (60000 / 32),
                    HowManyMinibatchesPerProgressPrint = 500,
                    DumpModelSnapshotPerMinibatch      = false,
                    AsyncMinibatchSnapshot             = false
                },
                PersistenceConfig = TrainingModelPersistenceConfiguration.CreateWithAllLocationsSetTo(outputDir)
            };

            msgPrinter.PrintMessage("\n" + trainingConfiguration + "\n");

            using (var runner = new ConvolutionalNeuralNetworkRunner(device, trainingConfiguration, msgPrinter))
            {
                runner.RunUsing(datasetDefinition);
            }

            EmnistTrainingDone(choice);
        }