yjh0410 / RT-ODLab

YOLO Tutorial

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

The dimension of rtcdet?

huihui308 opened this issue · comments

I fonud the dimension of rtcdet is [8400, 85] when I try to export rtcdet to onnx file,
I think the output dimension of rtcdet is [1,8400,85], Really?

@huihui308 In my setting, it should be [8400, 85] when the batch size is set to 1 during the ONNX inference.

Thank you for replying.
I want to deploy rtcdet on deepstream, but there is a segment fault when execute rtcdet engine, I think the output of model is [1,8400,85], could you give me a hint how to add this dimension?
Thank you.

@huihui308 In the onnx_inference.py, I think you could check the following code, especially the shape of output.

# inference
session = onnxruntime.InferenceSession(args.model)

ort_inputs = {session.get_inputs()[0].name: x[None, :, :, :]}
output = session.run(None, ort_inputs)
print("inference time: {:.1f} ms".format((time.time() - t0)*1000))

t0 = time.time()
# post process
bboxes, scores, labels = postprocess(output[0])
bboxes /= ratio

There is error when I execute onnx_inference.py.

$ python3 onnx_inference.py --model=./../../weights/onnx/11/rtcdet_p.onnx --image_path=./test.jpg 
Unable to init server: Could not connect: Connection refused
Unable to init server: 无法连接: Connection refused

(onnx_inference.py:209395): Gdk-CRITICAL **: 10:36:50.113: gdk_cursor_new_for_display: assertion 'GDK_IS_DISPLAY (display)' failed
inference time: 109.9 ms
3
Traceback (most recent call last):
  File "onnx_inference.py", line 67, in <module>
    bboxes, scores, labels = postprocess(output[0])
  File "/home/david/code/paper/PyTorch_YOLO_Tutorial/deployment/ONNXRuntime/../../utils/misc.py", line 385, in __call__
    labels = np.argmax(scores, axis=1)                      # [M,]
  File "<__array_function__ internals>", line 180, in argmax
  File "/home/david/.local/lib/python3.8/site-packages/numpy/core/fromnumeric.py", line 1216, in argmax
    return _wrapfunc(a, 'argmax', axis=axis, out=out, **kwds)
  File "/home/david/.local/lib/python3.8/site-packages/numpy/core/fromnumeric.py", line 57, in _wrapfunc
    return bound(*args, **kwds)
ValueError: attempt to get argmax of an empty sequence

The shape of scores is [8400, 0] in PostProcessor.

    def __call__(self, predictions):
        """
        Input:
            predictions: (ndarray) [n_anchors_all, 4+1+C]
        """
        print(type(predictions))
        bboxes = predictions[..., :4]
        scores = predictions[..., 4:]
        print(type(scores), bboxes.shape, scores.shape)

The error is as following.

$ python3 onnx_inference.py --model=./../../weights/onnx/11/rtcdet_p.onnx --image_path=./test.jpg 
Unable to init server: Could not connect: Connection refused
Unable to init server: 无法连接: Connection refused

(onnx_inference.py:209910): Gdk-CRITICAL **: 10:51:07.741: gdk_cursor_new_for_display: assertion 'GDK_IS_DISPLAY (display)' failed
inference time: 114.6 ms
3
<class 'numpy.ndarray'>
<class 'numpy.ndarray'> (8400, 4) (8400, 0)
Traceback (most recent call last):
  File "onnx_inference.py", line 67, in <module>
    bboxes, scores, labels = postprocess(output[0])
  File "/home/david/code/paper/PyTorch_YOLO_Tutorial/deployment/ONNXRuntime/../../utils/misc.py", line 388, in __call__
    scores = scores[(np.arange(scores.shape[0]), labels)]   # [M,]
IndexError: shape mismatch: indexing arrays could not be broadcast together with shapes (8400,) (0,) 

@huihui308 I just tried to export the rtcdet_s to onnx file and run the onnx_inference.py withou any error to detect the test image. I think you might check the format of the onnx file you export.

@huihui308 I just tried to export the rtcdet_s to onnx file and run the onnx_inference.py withou any error to detect the test image. I think you might check the format of the onnx file you export.

Yes, the onnx file has some mistakes.
I add batch dimension by modifing models/detectors/rtcdet/rtcdet.py.
Thank you.