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); } }
public ImageWithLabelPrediction(ImagePrediction pred, string label) { Label = label; Score = pred.Score; PredictedLabelValue = pred.PredictedLabelValue; }