コード例 #1
0
ファイル: Program.cs プロジェクト: maacpiash/Connery
        static void Main(string[] args)
        {
            // Load Data
            IEnumerable <ModelInput> images = ModelInput.LoadImagesFromDirectory(Constants.AssetsRelativePath);
            IDataView trainingDataView      = mlContext.Data.LoadFromEnumerable(images);

            // Build training pipeline
            IEstimator <ITransformer> trainingPipeline = BuildTrainingPipeline(mlContext);

            // Evaluate quality of Model
            Evaluate(mlContext, trainingDataView, trainingPipeline);

            // Train Model
            ITransformer mlModel = TrainModel(mlContext, trainingDataView, trainingPipeline);

            // Save model
            if (!Directory.Exists(Constants.WorkspaceRelativePath))
            {
                Directory.CreateDirectory(Constants.WorkspaceRelativePath);
            }
            SaveModel(mlContext, mlModel, Constants.ModelPath, trainingDataView.Schema);

            Console.WriteLine("Finished task. Press any key to exit.");
            Console.ReadKey();
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: maacpiash/Connery
        static void Main(string[] args)
        {
            NumberOfLabels = Constants.Labels.Length;
            var images = ModelInput.LoadImagesFromDirectory(Constants.TestImagesRelativePath, false);

            WriteLine($"Total number of images for testing: {images.Count()}");
            confusionMatrix = new int[NumberOfLabels, NumberOfLabels];
            labels          = new Dictionary <string, int>();
            foreach (var label in Constants.Labels)
            {
                labels.Add(label, Array.IndexOf(Constants.Labels, label));
            }
            NumberOfImages = 0;
            WriteLine("Actual label\tPredicted Label\tScore");
            foreach (var image in images)
            {
                var prediction = ConsumeModel.Predict(image, Constants.ModelPath);
                WriteLine($"{image.Label}\t{prediction.Prediction}\t{prediction.Score.Max()}");
                // Format: `confusionMatrix[predictedLabel, actualLabel]`
                confusionMatrix[labels[prediction.Prediction], labels[image.Label]]++;
                NumberOfImages++;
            }

            WriteLine($"Categorized {NumberOfImages} images in {NumberOfLabels} classes.");

            PrintConfusionMatrix();

            PrintPrecisionRecall();
        }