Skip to content

YOLOv3 shows ArgumentOutOfRangeException #4578

Closed

Description

@priyankagupta639

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?

Activity

  1. gartangh commented on Feb 4, 2020

    @gartangh

    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.)

  2. BobLd commented on Oct 30, 2020

    @BobLd
  3. matouskozak commented on Aug 31, 2026

    @matouskozak
    Member

    The question appears to be answered in the comments. @priyankagupta639 I'll close this issue as resolved. Please let us know if it is not the case.

  4. locked and limited conversation to collaborators on Oct 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions