Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

System.IndexOutOfRangeException: 'Index was outside the bounds of the array.' #58

Open
masgh21 opened this issue May 27, 2022 · 3 comments

Comments

@masgh21
Copy link

masgh21 commented May 27, 2022

Hello EveryOne
I want to test my onnx model but I git this Error

my models
Models File

image

@masgh21
Copy link
Author

masgh21 commented May 27, 2022

public class TestModel1: YoloModel
{
public override int Width { get; set; } = 640;
public override int Height { get; set; } = 640;
public override int Depth { get; set; } = 3;

    public override int Dimensions { get; set; } = 6;

    public override int[] Strides { get; set; } = new int[] { 8, 16, 32, 64 };

    public override int[][][] Anchors { get; set; } = new int[][][]
    {
        new int[][] { new int[] { 009, 011 }, new int[] { 021, 019 }, new int[] { 017, 041 } },
        new int[][] { new int[] { 043, 032 }, new int[] { 039, 070 }, new int[] { 086, 064 } },
        new int[][] { new int[] { 065, 131 }, new int[] { 134, 130 }, new int[] { 120, 265 } },
        new int[][] { new int[] { 282, 180 }, new int[] { 247, 354 }, new int[] { 512, 387 } }
    };

    public override int[] Shapes { get; set; } = new int[] { 80, 40, 20, 10 };

    public override float Confidence { get; set; } = 0.20f;
    public override float MulConfidence { get; set; } = 0.25f;
    public override float Overlap { get; set; } = 0.45f;

    public override string[] Outputs { get; set; } = new[] { "output" };

    public override List<YoloLabel> Labels { get; set; } = new List<YoloLabel>()
    {
    
        new YoloLabel { Id = 1, Name = "helmet" }
    };

    public override bool UseDetect { get; set; } = true;

    public TestModel1()
    {

    }
}

@PLMDTK
Copy link

PLMDTK commented Jun 13, 2022

I ran into the same problem using my own training results.

@zzzdddyyy
Copy link

I get this problem all the time.
But I found the cause of the problem and came up with a solution.

The key cause of the problem:
Wrong dimension set in model file.

image

So how do we get the dimensions right?

1st:
Open this website: https://netron.app/

Open your xxx.onnx file in this page

2nd
Find the output result like this:

image
The output array :[1,25200,7] in my sample

3th
Run the Yolo5NetApp,Set a breakpoint at the point where the program reported an error.

Get run results
image

The output array's length is 277200 in my sample

4th
The right dimensions = 277022/25200 = 11

5th

Modify your dimensions in model file ,you can run this app.

Last
There may be a better solution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants