Yolov5-TensorRT icon indicating copy to clipboard operation
Yolov5-TensorRT copied to clipboard

UNSUPPORTED_NODE: Assertion failed: scales.is_weights() && "Resize scales must be an initializer!"

Open PeterKim1 opened this issue 2 years ago • 3 comments

Hi.

Thank you for your great works.

For converting custom ONNX model to TensorRT model, i used your codes.

But cannot convert.

Error message is below:

[TensorRT] WARNING: onnx2trt_utils.cpp:362: Your ONNX model has been generated with INT64 weights, while TensorRT does notnatively support INT64. Attempting to cast down to INT32. In node 251 (importResize): UNSUPPORTED_NODE: Assertion failed: scales.is_weights() && "Resize scales must be an initializer!" [TensorRT] ERROR: 4: [network.cpp::validate::2411] Error Code 4: Internal Error (Network must have at least one output) Traceback (most recent call last): File "convert.py", line 78, in convert_onnx_to_trt(opt.weights, File "convert.py", line 29, in convert_onnx_to_trt convert(np.random.randint(0, 255, image_shape).astype("float")) File "/usr/local/lib/python3.8/dist-packages/cvu/detector/yolov5/core.py", line 106, in call outputs = self._model(processed_inputs) File "/usr/local/lib/python3.8/dist-packages/cvu/detector/yolov5/backends/yolov5_tensorrt.py", line 307, in call self._load_model(self._weight) File "/usr/local/lib/python3.8/dist-packages/cvu/detector/yolov5/backends/yolov5_tensorrt.py", line 141, in _load_model self._engine = self._build_engine(weight, engine_path, File "/usr/local/lib/python3.8/dist-packages/cvu/detector/yolov5/backends/yolov5_tensorrt.py", line 262, in _build_engine trt_engine_file.write(engine.serialize()) AttributeError: 'NoneType' object has no attribute 'serialize'

How to fix it?

I don't know well about TensorRT and yolov5, so i need your help.

Thanks.

PeterKim1 avatar Jan 03 '23 01:01 PeterKim1

@PeterKim1 could you share the model? If you could share the torch model we could take a deeper look because it seems there is something wrong with the ONNX model.

If you cannot share the model: FYI, TensorRT only support scale factor as constant weights, that’s why the error happened. So, run your ONNX model through netron to see if your scale factor is constant in whichever layer(BatchNorm) it is used.

makaveli10 avatar Jan 06 '23 14:01 makaveli10

@PeterKim1 more discussion here:

  • https://github.com/NVIDIA/TensorRT/issues/825
  • https://github.com/WongKinYiu/yolov7/issues/812
  • https://forums.developer.nvidia.com/t/assertion-failed-scales-is-weights-resize-scales-must-be-an-initializer/147342

-> you might want to change the opset and see if it helps

Hyrtsi avatar Apr 03 '23 09:04 Hyrtsi

@PeterKim1 I had the same issue, I used the trtexec utility from tensorrt to convert onnx to trt and it worked. Maybe you can try that

naga24 avatar Sep 22 '23 06:09 naga24