public void DetectObjectsUsingModel(ImageInputData imageInputData) { var probs = predictionEngine.Predict(imageInputData).PredictedLabels; List <BoundingBox> boundingBoxes = outputParser.ParseOutputs(probs); filteredBoxes = outputParser.FilterBoundingBoxes(boundingBoxes, 5, .5F); }
public List <BoundingBox> DetectObjectsUsingModel(ImageInputData imageInputData) { var labels = customVisionPredictionEngine?.Predict(imageInputData).PredictedLabels ?? tinyYoloPredictionEngine?.Predict(imageInputData).PredictedLabels; var boundingBoxes = outputParser.ParseOutputs(labels); var filteredBoxes = outputParser.FilterBoundingBoxes(boundingBoxes, 5, 0.5f); return(filteredBoxes); }
public void Test1() { var onnxPath = @"../../../../TinyYolo/Data/TinyYolo2_model.onnx"; var testDataPath = @"../../../Data"; var ml = new MLContext(); var train = new Train(ml); var yolo = new TinyYoloModel(CommonHelper.GetAbsolutionPath(onnxPath, typeof(TinyYoloModel))); var transformer = train.LoadOnnx(yolo); var testImage = Path.Combine(testDataPath, "Image1.jpg" /** Image file here */); testImage = CommonHelper.GetAbsolutionPath(testImage, typeof(UnitTest1)); var image = Image.FromFile(testImage); var bitmap = (Bitmap)image; var testImageData = new ImageNetData { Image = bitmap }; var objectDetection = ml.Model.CreatePredictionEngine <ImageNetData, TinyYoloPrediction>(transformer); TinyYoloPrediction result = new TinyYoloPrediction(); objectDetection.Predict(testImageData, ref result); OnnxOutputParser parser = new OnnxOutputParser(yolo); var boxes = parser.ParseOutputs(result.PredictedLabels); boxes = parser.FilterBoundingBoxes(boxes, 3, .5f); if (boxes.Any()) { var saveLocation = CommonHelper.GetAbsolutionPath(testDataPath + "/result", typeof(UnitTest1)); CommonHelper.DrawRect(testDataPath, saveLocation, "Image1.jpg", boxes); } else { Assert.False(true); } }