Error Running ONNX Model "Non-zero status code returned while running NonMaxSuppression node.

#8
by khaitam2001 - opened

I've tried running this ONNX model but I've ran into a problem. Am I perhaps giving the wrong input?

import onnxruntime
import numpy as np
from PIL import Image

Load the ONNX model

onnx_model_path = "yolow-l.onnx"
ort_session = onnxruntime.InferenceSession(onnx_model_path)

Prepare input data

input_image_path = "images/price_tag_image/c17daf41-de8f-4af0-b4df-20af49c04216.jpg"
input_image = Image.open(input_image_path)
input_image = input_image.resize((640, 640)) # Resize as needed
input_data = np.array(input_image, dtype=np.float32)
input_data = np.transpose(input_data, (2, 0, 1)) # Channels first
input_data = np.expand_dims(input_data, axis=0) # Add batch dimension

Run inference

outputs = ort_session.run(['num_dets', 'boxes', 'scores', 'labels'], {"images": input_data})

2024-04-15 14:12:44.339192 [E:onnxruntime:, sequential_executor.cc:514 ExecuteKernel] Non-zero status code returned while running NonMaxSuppression node. Name:'/NonMaxSuppression' Status Message: non_max_suppression.cc:87 PrepareCompute boxes and scores should have same spatial_dimension.

Fail Traceback (most recent call last)
Cell In[597], line 10
7 input_data = np.expand_dims(input_data, axis=0) # Add batch dimension
9 # Run inference
---> 10 outputs = ort_session.run(['num_dets', 'boxes', 'scores', 'labels'], {"images": input_data})

File /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/onnxruntime/capi/onnxruntime_inference_collection.py:217, in Session.run(self, output_names, input_feed, run_options)
215 output_names = [output.name for output in self._outputs_meta]
216 try:
--> 217 return self._sess.run(output_names, input_feed, run_options)
218 except C.EPFail as err:
219 if self._enable_fallback:

Fail: [ONNXRuntimeError] : 1 : FAIL : Non-zero status code returned while running NonMaxSuppression node. Name:'/NonMaxSuppression' Status Message: non_max_suppression.cc:87 PrepareCompute boxes and scores should have same spatial_dimension.

Try rebuild onnx model maybe with different classes. I was experiencing same issue with model generated from demo on hf.

Did you find the solution
How did you do handle the pre and post process?

Sign up or log in to comment