[TensorRT] ERROR: (Unnamed Layer* 0) [Convolution]: at least 5 dimensions are required for input - on Jetson Xavier

I have created an onnx model that successfully with TensorRT 7 on my host machine, but it gives the following error on AGX Xavier.

[TensorRT] ERROR: (Unnamed Layer* 0) [Convolution]: at least 5 dimensions are required for input
Traceback (most recent call last):
File “run.py”, line 49, in
engine = backend.prepare(model, device=‘CUDA:0’)
File “/home/yaak/onnx-tensorrt/onnx_tensorrt/backend.py”, line 200, in prepare
return TensorRTBackendRep(model, device, **kwargs)
File “/home/yaak/onnx-tensorrt/onnx_tensorrt/backend.py”, line 86, in init
raise RuntimeError(msg)
RuntimeError: While parsing node number 1:
builtin_op_importers.cpp:695 In function importBatchNormalization:
[6] Assertion failed: scale_weights.shape == weights_shape

On AGX Xavier, I have followed the instructions at https://github.com/onnx/onnx-tensorrt/tree/6.0-full-dims
and I have also installed the TensorRT 6.0 open source libaries and onnx 1.5.0.

The model is open source (r2plus1d_34_clip32_ft_kinetics_from_ig65m-ade133f1.pth] and is taken from https://github.com/moabitcoin/ig65m-pytorch

I have converted the .pth to .onnx using torch 1.2.0 (also using the 1.3 gives the same error)
And used the following script to build a trt engine for it:

import onnx
import onnx_tensorrt.backend as backend
import numpy as np

model = onnx.load(“r2plus1d_34_clip32_ft_kinetics_from_ig65m-10f4c3bf.onnx”)
engine = backend.prepare(model, device=‘CUDA:0’)
input_data = np.random.random(size=(1, 3, 32, 224, 224)).astype(np.float32)
output_data = engine.run(input_data)[0]
print(output_data)
print(output_data.shape)

I appreciate it if you can help me resolving this error.

Thanks
Nasim

Hi,

It looks like you meet the similar error of this issue:

Would you mind to check if the suggestion also works for you first?
Thanks.

Hi AastaLLL,

Yes, I did go through the solutions proposed in this link.
I have installed TensorRT OSS v6.0 as well and have also tried to run the code with explicit batch flag. This is the script that I used with explicit batch flag:

import tensorrt as trt

def build_engine(onnx_path, engine_path):
  TRT_LOGGER = trt.Logger()
  with trt.Builder(TRT_LOGGER) as builder:
    builder.max_workspace_size = 1 << 30 # 1GB
    builder.max_batch_size = 1
    builder.fp16_mode = True

    #with builder.create_network() as network:
    explicit_batch_flag = 1 << int(trt.NetworkDefinitionCreationFlag.EXPLICIT_BATCH)
    with builder.create_network(explicit_batch_flag) as network:
      with trt.OnnxParser(network, TRT_LOGGER) as parser:
        with open(onnx_path, 'rb') as model:
          print('here')
          parser.parse(model.read())
          print('here')
          network.mark_output(network.get_layer(network.num_layers-1).get_output(0))
          engine = builder.build_cuda_engine(network)

      with open(engine_path, "wb") as f:
        f.write(engine.serialize())
  return engine

if __name__ == '__main__':
  build_engine('model.onnx', 'model.engine')

The solution has not worked for me unfortunately. I still get the same error:

[TensorRT] ERROR: (Unnamed Layer* 0) [Convolution]: at least 5 dimensions are required for input
[TensorRT] WARNING: Setting layouts of network and plugin input/output tensors to linear, as 3D operators are found and 3D non-linear IO formats are not supported, yet.
[TensorRT] ERROR: (Unnamed Layer* 0) [Convolution]: at least 5 dimensions are required for input
Traceback (most recent call last):
File “run3.py”, line 26, in
build_engine(‘model.onnx’, ‘model.engine’)
File “run3.py”, line 22, in build_engine
f.write(engine.serialize())
AttributeError: ‘NoneType’ object has no attribute ‘serialize’

Hi,

To give a further suggestion, would you mind to share your onnx model with us?
Thanks.

The model that I am using is [r2plus1d_34_clip32_ft_kinetics_from_ig65m-10f4c3bf.pb] taken from


Link to the model:
https://github.com/moabitcoin/ig65m-pytorch/releases/download/v1.0.0/r2plus1d_34_clip32_ft_kinetics_from_ig65m-10f4c3bf.pb

The extension should be changed to .onnx instead of .pb (it is a typo). The onnx file is generated using the script at

Hi AastaLLL,

Any update on this? Please let me know if you need further information to reproduce the issue.

There is no update from you for a period, assuming this is not an issue any more.
Hence we are closing this topic. If need further support, please open a new one. Thanks

Hi,

Sorry for the late update.
Would you mind to share the onnx file with us directly?

Thanks.