onnx / models

A collection of pre-trained, state-of-the-art models in the ONNX format
http://onnx.ai/models/
Apache License 2.0
7.89k stars 1.4k forks source link

An inference error about tiny yolov3 #383

Open mokiya opened 4 years ago

mokiya commented 4 years ago

Ask a Question

Question

Hi

I'm referring to a link below.

Also I downloaded onnx file (tiny-yolov3-11.onnx) from a link above.

Here is a sample to inference with this onnx file.

session = onnxruntime.InferenceSession('tiny-yolov3-11.onnx')
img = Image.open('images/bus.jpg')

img_data = preprocess(img)
img_size = np.array([img.size[1], img.size[0]], dtype=np.float32).reshape(1, 2)

boxes, scores, indices = session.run(None, {"input_1": img_data, "image_shape":img_size})

This is an error what I encountered.

Boxes: (1, 2535, 4)
Scores: (1, 80, 2535)
Indices: (1, 2, 3)
Traceback (most recent call last):
  File "yolov3_object_detection_onnxmodelzoo_onnxruntime_inference.py", line 115, in <module>
    out_boxes, out_scores, out_classes, objects_identified = postprocess(boxes, scores, indices)
  File "yolov3_object_detection_onnxmodelzoo_onnxruntime_inference.py", line 37, in postprocess
    out_classes.append(classes[idx_[1]])
TypeError: only integer scalar arrays can be converted to a scalar index

I wonder why indices is 1x3. I supposed it should be 1x2 like Indices: (4, 3). Would you please give me suspicious points which I missed?

Thanks

MuhammadAsadJaved commented 3 years ago

@mokiya I am trying to use yolov3.onnx model for inference. Have you done this work? if yes then can you please share the complete code? as the yolov3 example only describes image pre and post-process steps.

dk-teknologisk-mlnn commented 3 years ago

The first number is your image number in the batch. Say you fed two images, you may find 2 objects in image 1 and 1 object in image 2.

(1,20,454)
(1,3,2075)
(2,60,52)