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(); }
public async Task <ImageDetectResult> DetectObjects(Bitmap image) { var modelDir = MLUtils.ModelFolder; ImageDetectResult result = null; var inceptionPb = Path.Combine(modelDir.FullName, "tensorflow_inception_graph.pb"); var labelsTxt = Path.Combine(modelDir.FullName, "imagenet_comp_graph_label_strings.txt"); if (!File.Exists(inceptionPb)) { Logging.LogError($"Image classification TF model was not found at {inceptionPb}"); return(null); } if (!File.Exists(inceptionPb)) { Logging.LogError($"Image classification TF labels not found at {labelsTxt}"); return(null); } try { var imagesFolder = string.Empty; // TODO var modelScorer = new TFModelScorer(imagesFolder, inceptionPb, labelsTxt); modelScorer.Score(null); } catch (Exception ex) { Logging.LogError($"Exception during image classification processing: {ex}"); } return(result); }
public async Task <IActionResult> Index(IFormFile image) { string assetsRelativePath = @"../../../assets"; string assetsPath = GetAbsolutePath(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"); try { var filePath = Path.GetTempFileName(); //Save image using (var ms = new FileStream(filePath, FileMode.Create)) { await image.CopyToAsync(ms); } var modelScorer = new TFModelScorer(tagsTsv, imagesFolder, inceptionPb, labelsTxt); var prediction = (ImageNetDataProbability)modelScorer.Score(new ImageNetData() { ImagePath = filePath, Label = "" }); ViewBag.PredictedLabel = prediction.PredictedLabel; ViewBag.Probability = prediction.Probability; } catch { return(View()); } return(View()); }
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(); }
private RecognizedObjects DoRecognizeObject(string imagePath) { var assets = Path.GetFullPath("assets"); var tagsTsv = Path.Combine(assets, "inputs", "images", "tags.tsv"); var imagesFolder = Path.Combine(assets, "inputs", "images"); var inceptionPb = Path.Combine(assets, "inputs", "inception", "tensorflow_inception_graph.pb"); var labelsTxt = Path.Combine(assets, "inputs", "inception", "imagenet_comp_graph_label_strings.txt"); var model = new TFModelScorer(); var predictionEngine = model.LoadModel(tagsTsv, imagesFolder, inceptionPb); var prediction = model.PredictSingleImageDataUsingModel( imagePath, labelsTxt, predictionEngine); switch (prediction.PredictedLabel) { case "orange": return(RecognizedObjects.Orange); case "banana": return(RecognizedObjects.Banana); case "apple": case "Granny Smith": return(RecognizedObjects.Apple); case "strawberry": return(RecognizedObjects.Strawberry); default: return(RecognizedObjects.Unrecognized); } }
public void PredictImage(string imagePath) { try { var modelScorer = new TFModelScorer(tagsTsv, imagesFolder, inceptionPb, labelsTxt); Debug.WriteLine(imagePath);// A ENLEVER ImagePrediction.Add(modelScorer.ScoreImage(imagePath)[0]); ValueProgress += 1; } catch (Exception e) { Console.WriteLine(e.StackTrace); } }
public MainWindow() { 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"); Model = new TFModelScorer(); PredictionEngine = Model.LoadModel(tagsTsv, imagesFolder, inceptionPb); _worker.DoWork += WorkerOnDoWork; _worker.RunWorkerCompleted += WorkerCompleted; Model = new TFModelScorer(); PredictionEngine = Model.LoadModel(tagsTsv, imagesFolder, inceptionPb); Directory.CreateDirectory("pictures"); }
static void Main(string[] args) { string assetsRelativePath = @"../../../assets";//Relative path string assetsPath = GetAbsolutePath(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"); try { var modelScorer = new TFModelScorer(tagsTsv, imagesFolder, inceptionPb, labelsTxt); //modelScorer.Score(); } catch { } }
public string Classificate() { string assetsRelativePath = @"../../../inputs"; string assetsPath = GetAbsolutePath(assetsRelativePath); var tagsTsv = Path.Combine(assetsPath, "images", "tags.tsv"); var imagesFolder = Path.Combine(assetsPath, "images"); var inceptionPb = Path.Combine(assetsPath, "inception", "tensorflow_inception_graph.pb"); var labelsTxt = Path.Combine(assetsPath, "inception", "imagenet_comp_graph_label_strings.txt"); try { var modelScorer = new TFModelScorer(tagsTsv, imagesFolder, inceptionPb, labelsTxt); return(modelScorer.Score()); } catch (Exception ex) { return(ex.Message); } }
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(); }