error while loading model in transfer learning

Hi

I’m following Hello AI world and start the transfer learning with Pytorch.
https://github.com/dusty-nv/jetson-inference/blob/master/docs/pytorch-collect.md

Jetson nano is able to retrain the model with my own datset and covert it to ONNX. However, when I try to run the model I encounted a problem. It shows the ONNX model can not be parsed.

So my question is, how to fix the error?
BTW, pytorch is 1.1.0 and torchvision is 0.3.0.

following is the error message in terminal.

[TRT] 185:Conv -> (512, 7, 7)
[TRT] 186:BatchNormalization -> (512, 7, 7)
[TRT] 187:Add -> (512, 7, 7)
[TRT] 188:Relu -> (512, 7, 7)
[TRT] 189:GlobalAveragePool -> (512, 1, 1)
[TRT] 190:Constant ->
[TRT] 191:Shape -> (4)
WARNING: Your ONNX model has been generated with INT64 weights, while TensorRT does not natively support INT64. Attempting to cast down to INT32.
Successfully casted down to INT32.
While parsing node number 69 [Gather]:
ERROR: onnx2trt_utils.hpp:277 In function convert_axis:
[8] Assertion failed: axis >= 0 && axis < nbDims
[TRT] failed to parse ONNX model ‘test_3/resnet18.onnx’
[TRT] device GPU, failed to load test_3/resnet18.onnx
[TRT] failed to load test_3/resnet18.onnx
[TRT] imageNet – failed to initialize.
jetson.inference – imageNet failed to load built-in network ‘googlenet’
PyTensorNet_Dealloc()
Traceback (most recent call last):
File “/usr/local/bin/imagenet-camera.py”, line 47, in
net = jetson.inference.imageNet(opt.network, sys.argv)
Exception: jetson.inference – imageNet failed to load network

Hi gongl16, it requires a patch to torchvision package, please refer to this post for the fix:

https://devtalk.nvidia.com/default/topic/1057960/jetson-nano/failed-to-parse-onnx-model/post/5365088/#5365088

yes, it works. Thank you!

Hi, dusty_nv

it is working when I load the trained resnet. however it reports error when I load the retrained alexnet or googlenet. The error messages are listed as follows. Is there something wrong with my configuration? do you konw how to fix it. thanks

Googlenet
[TRT] 346:Gather -> (224, 224)
[TRT] /home/erisuser/p4sw/sw/gpgpu/MachineLearning/DIT/release/5.1/parsers/onnxOpenSource/builtin_op_importers.cpp:1981: Unsqueezing from (224, 224) to (224, 1, 224)
[TRT] 347:Unsqueeze -> (224, 1, 224)
[TRT] 348:Constant ->
While parsing node number 4 [Mul]:
ERROR: builtin_op_importers.cpp:353 In function importScaleOp:
[8] Assertion failed: get_shape_size(weights.shape) == get_shape_size(dims)
[TRT] failed to parse ONNX model ‘test_google/googlenet.onnx’
[TRT] device GPU, failed to load test_google/googlenet.onnx
[TRT] failed to load test_google/googlenet.onnx
[TRT] imageNet – failed to initialize.
jetson.inference – imageNet failed to load built-in network ‘googlenet’

alexnet
WARNING: Your ONNX model has been generated with INT64 weights, while TensorRT does not natively support INT64. Attempting to cast down to INT32.
Successfully casted down to INT32.
While parsing node number 16 [Gather]:
ERROR: onnx2trt_utils.hpp:277 In function convert_axis:
[8] Assertion failed: axis >= 0 && axis < nbDims
[TRT] failed to parse ONNX model ‘test_alex_2/alexnet.onnx’
[TRT] device GPU, failed to load test_alex_2/alexnet.onnx
[TRT] failed to load test_alex_2/alexnet.onnx
[TRT] imageNet – failed to initialize.
jetson.inference – imageNet failed to load built-in network ‘googlenet’
PyTensorNet_Dealloc()
Traceback (most recent call last):
File “/usr/local/bin/imagenet-camera.py”, line 47, in
net = jetson.inference.imageNet(opt.network, sys.argv)
Exception: jetson.inference – imageNet failed to load network

Hi gongl16, it appears that these other models require some patching to their model definitions in torchvision to be compliant with ONNX parser that TensorRT uses for loading the models. I would stick with using the ResNet variants for now (e.g. resnet18, resnet34, resnet50) as they should have improved accuracy.

Hi dusty_nv,
yes, I tested the other networks and found only resnet working.I know the reason now. Thank you!