Quantcast
Channel: AI Beta - Unity Discussions
Viewing all articles
Browse latest Browse all 109

Exporting YOLOv8 to ONNX

$
0
0

Hello, I’m wondering if my procedure to use a YOLOv8 model in Sentis is correct. I export the model to ONNX format with Ultralytics package like this:

model = YOLO('weights/best.pt')  # load an official model
path = model.export(format="onnx", opset=15)  # export the model to ONNX format, opset_version=15 is the ONNX version Unity needs

Then I load the model (“Optimize Model” = true) into a Sentis 1.0.3 project and I have no errors:

Clicking on “Serialize to StreamingAssets”, I now have a .sentis model in my StreamingAssets folder which I use.


Unfortunately, the detections do not work. Using the example in HuggingFace, I get IndexOutOfRangeException when drawing the bounding box:

//Draw the bounding boxes
        for (int n = 0; n < output.shape[0]; n++)
        {
            var box = new BoundingBox
            {
                centerX = ((output[n, 1] + output[n, 3])*scaleX - displayWidth) / 2,
                centerY = ((output[n, 2] + output[n, 4])*scaleY - displayHeight) / 2,
                width = (output[n, 3] - output[n, 1])*scaleX,
                height = (output[n, 4] - output[n, 2])*scaleY,
                label = labels[(int)output[n, 5]],
                confidence = Mathf.FloorToInt(output[n, 6] * 100 + 0.5f)
            };
            DrawBox(box, n);
        }

5 posts - 2 participants

Read full topic


Viewing all articles
Browse latest Browse all 109

Trending Articles