static void LoadAndPrediction() { MLContext mlContext = new MLContext(seed: 1); // Load the model ITransformer loadedModel = mlContext.Model.Load(imageClassifierZip, out var modelInputSchema); // Make prediction function (input = ImageNetData, output = ImageNetPrediction) var predictor = mlContext.Model.CreatePredictionEngine <ImageNetData, ImageNetPrediction>(loadedModel); DirectoryInfo testdir = new DirectoryInfo(TestDataFolder); foreach (var jpgfile in testdir.GetFiles("*.jpg")) { ImageNetData image = new ImageNetData(); image.ImagePath = jpgfile.FullName; var pred = predictor.Predict(image); Console.WriteLine($"Filename:{jpgfile.Name}:\tPredict Result:{pred.PredictedLabelValue}"); } }
static void LoadAndPrediction() { MLContext mlContext = new MLContext(seed: 1); // Load the model ITransformer loadedModel; using (var f = new FileStream(imageClassifierZip, FileMode.Open)) loadedModel = mlContext.Model.Load(f); var predictor = loadedModel.CreatePredictionEngine <ImageNetData, ImageNetPrediction>(mlContext); DirectoryInfo testdir = new DirectoryInfo(TestDataFolder); foreach (var jpgfile in testdir.GetFiles("*.jpg")) { ImageNetData image = new ImageNetData(); image.ImagePath = jpgfile.FullName; var pred = predictor.Predict(image); Console.WriteLine($"Filename:{jpgfile.Name}:\tPredict Result:{pred.PredictedLabelValue}"); } }