static void Main(string[] args)
        {
            string assetsRelativePath = @"..\..\..\assets";
            string assetsPath         = GetDataSetAbsolutePath(assetsRelativePath);

            var tagsTsv      = Path.Combine(assetsPath, "inputs", "images", "tags.tsv");
            var imagesFolder = Path.Combine(assetsPath, "inputs", "images");
            var inceptionPb  = Path.Combine(assetsPath, "inputs", "inception", "tensorflow_inception_graph.pb");
            var labelsTxt    = Path.Combine(assetsPath, "inputs", "inception", "imagenet_comp_graph_label_strings.txt");

            var customInceptionPb = Path.Combine(assetsPath, "inputs", "inception_custom", "model_tf.pb");
            var customLabelsTxt   = Path.Combine(assetsPath, "inputs", "inception_custom", "labels.txt");

            try
            {
                var modelScorer = new TFModelScorer(tagsTsv, imagesFolder, inceptionPb, labelsTxt);
                modelScorer.Score();
            }
            catch (Exception ex)
            {
                ConsoleHelpers.ConsoleWriteException(ex.Message);
            }

            ConsoleHelpers.ConsolePressAnyKey();
        }
Example #2
0
        static void Main(string[] args)
        {
            var assetsPath = ModelHelpers.GetAssetsPath(@"..\..\..\assets");

            var tagsTsv      = Path.Combine(assetsPath, "inputs", "images", "tags.tsv");
            var imagesFolder = Path.Combine(assetsPath, "inputs", "images");
            var inceptionPb  = Path.Combine(assetsPath, "inputs", "custom-vision-tensorflow", "model.pb");
            var labelsTxt    = Path.Combine(assetsPath, "inputs", "custom-vision-tensorflow", "labels.txt");

            //var inceptionPb = Path.Combine(assetsPath, "inputs", "inception", "tensorflow_inception_graph.pb");
            //var labelsTxt = Path.Combine(assetsPath, "inputs", "inception", "imagenet_comp_graph_label_strings.txt");

            var customInceptionPb = Path.Combine(assetsPath, "inputs", "inception_custom", "model_tf.pb");
            var customLabelsTxt   = Path.Combine(assetsPath, "inputs", "inception_custom", "labels.txt");

            try
            {
                var modelScorer = new TFModelScorer(tagsTsv, imagesFolder, inceptionPb, labelsTxt);
                modelScorer.Predict();
            }
            catch (Exception ex)
            {
                ConsoleHelpers.ConsoleWriteException(ex.Message);
            }

            ConsoleHelpers.ConsolePressAnyKey();
        }
Example #3
0
        static void Main()
        {
            string assetsPath = Path.Combine(new FileInfo(typeof(Program).Assembly.Location).Directory.FullName, "assets");

            var    trainingImages       = Path.GetFullPath("../../../assets/inputs/train"); // "C:\\repo\\Image-classification-transfer-learning\\grocery\\train2\\";
            var    testingImages        = Path.GetFullPath("../../../../ImageClassification.Test/assets/test/thor");
            var    featurizerModel      = Path.Combine(assetsPath, "inputs", "inception", "tensorflow_inception_graph.pb");
            string trainedModelLocation = Path.GetFullPath("../../../imageClassifier.zip");

            //Train model
            try
            {
                var modelBuilder = new ModelBuilder(trainingImages, featurizerModel, trainedModelLocation);
                modelBuilder.Train();
            }
            catch (Exception ex)
            {
                ConsoleHelpers.ConsoleWriteException(ex.Message);
            }

            //Test model
            ConsoleHelpers.ConsoleWriteHeader("Test model with few sample images");
            try
            {
                ConsoleHelpers.ConsoleWriteHeader("Load saved model");
                TrainedModel model = new TrainedModel(trainedModelLocation);

                ImagePrediction         prediction = new ImagePrediction();
                List <PredictionResult> results    = new List <PredictionResult>();

                List <ImageData> imageList = DataHelper.ReadFromFolder(testingImages);
                foreach (ImageData image in imageList)
                {
                    prediction = model.predictor.Predict(image);

                    PredictionResult result = new PredictionResult(Path.GetFileName(image.ImagePath).ToString(), prediction.PredictedLabelValue, prediction.Score.Max());
                    results.Add(result);
                }

                var output = JsonConvert.SerializeObject(results, Formatting.Indented);
                Console.WriteLine(output);
            }
            catch (Exception ex)
            {
                ConsoleHelpers.ConsoleWriteException(ex.Message);
            }
        }
Example #4
0
        static void Main(string[] args)
        {
            string assetsRelativePath = @"../../../assets";
            string assetsPath         = GetAbsolutePath(assetsRelativePath);

            var tagsTsv      = Path.Combine(assetsPath, "inputs", "zakladki", "image_list.tsv");
            var imagesFolder = Path.Combine(assetsPath, "inputs", "zakladki", "images");
            var labelsTxt    = Path.Combine(assetsPath, "inputs", "zakladki", "labels.txt");
            var pathToModel  = @"D:\Files\GitHub\BinaryImageClassifier\BinaryImageClassifier\models\mobileNetV2\1564031768";

            try
            {
                var modelScorer = new TFModelScorer(tagsTsv, imagesFolder, pathToModel, labelsTxt);
                modelScorer.Score();
            }
            catch (Exception ex)
            {
                ConsoleHelpers.ConsoleWriteException(ex.ToString());
            }

            ConsoleHelpers.ConsolePressAnyKey();
        }