dotnet / machinelearning

ML.NET is an open source and cross-platform machine learning framework for .NET.
https://dot.net/ml
MIT License
9k stars 1.88k forks source link

YOLOv3 shows ArgumentOutOfRangeException #4578

Open priyankagupta639 opened 4 years ago

priyankagupta639 commented 4 years ago

Hello I'm working on the latest version of Visual Studio 2019 on Windows 10 I have tried to work on object detection using yolov3 model. The yolov3.onnx file has been downloaded from https://github.com/onnx/models/tree/master/vision/object_detection_segmentation/yolov3

Below is the snippet of the error shown on the console screen. consoleError

This is the image of the output. output error

The code is similar as used for object detection using tiny-yolov2. Following are the changes made in the code.

1.) ImageNetPrediction.cs file public class ImageNetPrediction { [ColumnName("yolonms_layer_1/ExpandDims_3:0")] public float[] PredictedLabels; }

2.) YoloOutputParser.cs public const int ROW_COUNT = 13; public const int COL_COUNT = 13; public const int CHANNEL_COUNT = 125; public const int BOXES_PER_CELL = 5; public const int BOX_INFO_FEATURE_COUNT = 5; public const int CLASS_COUNT = 80; public const float CELL_WIDTH = 32; public const float CELL_HEIGHT = 32; . . . private string[] labels = new string[] { "person", "bicycle", "car", "motorbike", "aeroplane", "bus", "train", "truck", "boat", "traffic light", "fire hydrant", "stop sign", "parking meter", "bench", "bird", "cat", "dog", "horse", "sheep", "cow", "elephant", "bear", "zebra", "giraffe", "backpack", "umbrella", "handbag", "tie", "suitcase", "frisbee", "skis", "snowboard", "sports ball", "kite", "baseball bat", "baseball glove", "skateboard", "surfboard", "tennis racket", "bottle", "wine glass", "cup", "fork", "knife", "spoon", "bowl", "banana", "apple", "sandwich", "orange", "broccoli", "carrot", "hot dog", "pizza", "donut", "cake", "chair", "sofa", "pottedplant", "bed", "diningtable", "toilet", "tvmonitor", "laptop", "mouse", "remote", "keyboard", "cell phone", "microwave", "oven", "toaster", "sink", "refrigerator", "book", "clock", "vase", "scissors", "teddy bear", "hair drier", "toothbrush" };

3.) OnnxModelScorer.cs public struct TinyYoloModelSettings { public const string ModelInput = "input_1"; public const string ModelOutput = "yolonms_layer_1/ExpandDims_3:0"; } . . . var pipeline = mlContext.Transforms.LoadImages(outputColumnName: "image", imageFolder: "", inputColumnName: nameof(ImageNetData.ImagePath)) .Append(mlContext.Transforms.ResizeImages(outputColumnName: "image", imageWidth: ImageNetSettings.imageWidth, imageHeight: ImageNetSettings.imageHeight, inputColumnName: "input_1")) .Append(mlContext.Transforms.ExtractPixels(outputColumnName: "image")) .Append(mlContext.Transforms.ApplyOnnxModel(modelFile: modelLocation, outputColumnNames: new[] { TinyYoloModelSettings.ModelOutput }, inputColumnNames: new[] { TinyYoloModelSettings.ModelInput })); . . . public static void Main() { var assetsRelativePath = @"../../../assets"; string assetsPath = GetAbsolutePath(assetsRelativePath); var modelFilePath = Path.Combine(assetsPath, "Model", "yolov3.onnx"); var imagesFolder = Path.Combine(assetsPath, "images"); var outputFolder = Path.Combine(assetsPath, "images", "output");

Also, how should I carry out the Preprocessing and Postprocessing steps?

gartangh commented 4 years ago

This might be an answer to your question, or introduce an additional question: The YOLOv3 model you downloaded, has ONNX version 1.5 and operation set (opset) 10. From this site, I assume that using that model will not work (yet). I would also be interested in using YOLOv3 object detection in C#, so if someone knows how to get this to work, please react here.

(By the way, the link in your question points to https://github.com/dotnet/machinelearning/issues/url instead of https://github.com/onnx/models/tree/master/vision/object_detection_segmentation/yolov3.)

BobLd commented 3 years ago

see here for using the YOLO v3 onnx/model in ML.Net: https://github.com/BobLd/YOLOv3MLNet/tree/master/YOLOV3MLNetSO