yolov3-tiny for parsing a onnx model: concat error

Hi,

I tried to convert the yolov3-tiny model which trained in darknet to tensorrt , I referred the yolov3_onnx sample in tensorrt and modified the yolov3_to_onnx.py , I removed the _make_shortcut_node function and added a _make_maxpool_node function , it was successfully generated the onnx model , but when I ran the onnx_to_tensorrt.py , the error occurred:

Beginning ONNX file parsing
[TensorRT] ERROR: (Unnamed Layer* 44) [Concatenation]: all concat input tensors must have the same dimensions except on the concatenation axis


When I tried with the trtexec , it showed :

ONNX IR version: 0.0.3
Opset version: 8
Producer name: NVIDIA TensorRT sample
Producer version:
Domain:
Model version: 0
Doc string:

(Unnamed Layer* 44) [Concatenation]: all concat input tensors must have the same dimensions except on the concatenation axis
While parsing node number 45 [Conv → “024_convolutional”]:
ERROR: /home/erisuser/p4sw/sw/gpgpu/MachineLearning/DIT/release/5.0/parsers/onnxOpenSource/builtin_op_importers.cpp:535 In function importConv:
[8] Assertion failed: dims.nbDims == 3
failed to parse onnx file
Engine could not be created
Engine could not be created


the _make_maxpool_node function I wrote is fllowing:

def _make_maxpool_node(self, layer_name, layer_dict):
“”"Create an ONNX Add node with the maxpool properties from
the DarkNet-based graph.

    Keyword arguments:
    layer_name -- the layer's name (also the corresponding key in layer_configs)
    layer_dict -- a layer parameter dictionary (one element of layer_configs)
    """
    previous_node_specs = self._get_previous_node_specs()
    inputs = [previous_node_specs.name]
    kernel_size = layer_dict['size']
    stride = layer_dict['stride']
    channels = previous_node_specs.channels
    kernel_shape = [kernel_size, kernel_size]
    strides = [stride, stride]

    assert inputs
    assert channels > 0

    maxpool_node = helper.make_node(
        'MaxPool',
        inputs=inputs,
        outputs=[layer_name],
        kernel_shape=kernel_shape,
        strides=strides,
        name=layer_name,
    )

    self._nodes.append(maxpool_node)

    return layer_name, channels

Is the code I wrote wrong? or something else? Did anyone converted the yolov3-tiny to tensorrt successfully?

Any suggestions are needed!Thank you!

hello,

Converting from yolov3-tiny to trt requires several customized plugin. Here is our tutorial for YOLO2 and YOLO3 with TensorRT for your reference: https://github.com/vat-nvidia/deepstream-plugins

Yo help us debug, can you share a small repro containing the parsing code and model that demonstrate the error you are seeing? You can DM me the files.

I have the same issue related to the conversion from yolov3-tiny to trt. I followed the python guide in the link:
[url]https://docs.nvidia.com/deeplearning/sdk/tensorrt-sample-support-guide/index.html#yolov3_onnx[/url]

Similarly, I changed the file yolov3_to_onnx.py with a new function _make_maxpool_node to support the layer of maxpool in yolov3-tiny model. The onnx file was generated successfully. But the file onnx_to_tensorrt.py was failed to generate trt model.
[TensorRT] ERROR: (Unnamed Layer* 38) [Concatenation]: all concat input tensors must have the same dimensions except on the concatenation axis

I think it is related to the trt.OnnxParser. Can you help investigate the issue? Thanks.

By the way, I have tried the yolo apps following the specified link. It is working for yolov3 and yolov3-tiny. Thanks.
[url]https://github.com/NVIDIA-AI-IOT/deepstream_reference_apps/tree/master/yolo#trt-yolo-app[/url]

@bobzeng
Hi,

In my case,I changed the code :

maxpool_node = helper.make_node(
‘MaxPool’,
inputs=inputs,
outputs=[layer_name],
kernel_shape=kernel_shape,
strides=strides,
name=layer_name,
)

to:

maxpool_node = helper.make_node(
‘MaxPool’,
inputs=inputs,
outputs=[layer_name],
kernel_shape=kernel_shape,
strides=strides,
auto_pad=‘SAME_UPPER’,
name=layer_name,
)

and it solved my problem…you can try with it , wish it could help you too!

@779661456

It fixed my issue. Thank you very much.

Hi

I am unable to parse yolov3-tiny.cfg model. I get the below error:

File “/home/Downloads/TensorRT-5.0.2.6/samples/python/yolov3_onnx/yolov3_to_onnx.py”, line 133, in _next_layer
layer_param_block, remainder = remainder.split(‘\n\n’, 1)
ValueError: need more than 1 value to unpack

This is my yolov3-tiny.cfg file:

[net]

Testing

batch=1
subdivisions=1

Training

batch=64

subdivisions=2

width=416
height=416
channels=3
momentum=0.9
decay=0.0005
angle=0
saturation = 1.5
exposure = 1.5
hue=.1

learning_rate=0.001
burn_in=1000
max_batches = 500200
policy=steps
steps=400000,450000
scales=.1,.1

[convolutional]
batch_normalize=1
filters=16
size=3
stride=1
pad=1
activation=leaky

[maxpool]
size=2
stride=2

[convolutional]
batch_normalize=1
filters=32
size=3
stride=1
pad=1
activation=leaky

[maxpool]
size=2
stride=2

[convolutional]
batch_normalize=1
filters=64
size=3
stride=1
pad=1
activation=leaky

[maxpool]
size=2
stride=2

[convolutional]
batch_normalize=1
filters=128
size=3
stride=1
pad=1
activation=leaky

[maxpool]
size=2
stride=2

[convolutional]
batch_normalize=1
filters=256
size=3
stride=1
pad=1
activation=leaky

[maxpool]
size=2
stride=2

[convolutional]
batch_normalize=1
filters=512
size=3
stride=1
pad=1
activation=leaky

[maxpool]
size=2
stride=1

[convolutional]
batch_normalize=1
filters=1024
size=3
stride=1
pad=1
activation=leaky

###########

[convolutional]
batch_normalize=1
filters=256
size=1
stride=1
pad=1
activation=leaky

[convolutional]
batch_normalize=1
filters=512
size=3
stride=1
pad=1
activation=leaky

[convolutional]
size=1
stride=1
pad=1
filters=255
activation=linear

[yolo]
mask = 3,4,5
anchors = 10,14, 23,27, 37,58, 81,82, 135,169, 344,319
classes=80
num=6
jitter=.3
ignore_thresh = .7
truth_thresh = 1
random=1

[route]
layers = -4

[convolutional]
batch_normalize=1
filters=128
size=1
stride=1
pad=1
activation=leaky

[upsample]
stride=2

[route]
layers = -1, 8

[convolutional]
batch_normalize=1
filters=256
size=3
stride=1
pad=1
activation=leaky

[convolutional]
size=1
stride=1
pad=1
filters=255
activation=linear

[yolo]
mask = 0,1,2
anchors = 10,14, 23,27, 37,58, 81,82, 135,169, 344,319
classes=80
num=6
jitter=.3
ignore_thresh = .7
truth_thresh = 1
random=1

Did you also faced similar issue? If yes, how did you fixed it ?

Any help is appreciated.

Thanks

Anyone tried to run tiny yolo in INT8 ?

@adit_bhrgv

Hi,

This may be a format issue,try to change the last [yolo]:

[convolutional]
size=1
stride=1
pad=1
filters=255
activation=linear

[yolo]
mask = 0,1,2
anchors = 10,14, 23,27, 37,58, 81,82, 135,169, 344,319
classes=80
num=6
jitter=.3
ignore_thresh = .7
truth_thresh = 1
random=1

to:

[convolutional]
size=1
stride=1
pad=1
filters=255
activation=linear

[yolo]
mask = 0,1,2
anchors = 10,14, 23,27, 37,58, 81,82, 135,169, 344,319
classes=80
num=6
jitter=.3
ignore_thresh = .7
truth_thresh = 1
random=1

Formats elsewhere may also need to be changed,check them…

It is a format issue, I had the same problem, be careful you have to add an empty row totally at the end of your .cfg file, which does not appear here, (line 183):

[net]
# Testing
batch=1
subdivisions=1
# Training
# batch=64
# subdivisions=2
width=608
height=608
channels=3
momentum=0.9
decay=0.0005
angle=0
saturation = 1.5
exposure = 1.5
hue=.1

learning_rate=0.001
burn_in=1000
max_batches = 500200
policy=steps
steps=400000,450000
scales=.1,.1

[convolutional]
batch_normalize=1
filters=16
size=3
stride=1
pad=1
activation=leaky

[maxpool]
size=2
stride=2

[convolutional]
batch_normalize=1
filters=32
size=3
stride=1
pad=1
activation=leaky

[maxpool]
size=2
stride=2

[convolutional]
batch_normalize=1
filters=64
size=3
stride=1
pad=1
activation=leaky

[maxpool]
size=2
stride=2

[convolutional]
batch_normalize=1
filters=128
size=3
stride=1
pad=1
activation=leaky

[maxpool]
size=2
stride=2

[convolutional]
batch_normalize=1
filters=256
size=3
stride=1
pad=1
activation=leaky

[maxpool]
size=2
stride=2

[convolutional]
batch_normalize=1
filters=512
size=3
stride=1
pad=1
activation=leaky

[maxpool]
size=2
stride=1

[convolutional]
batch_normalize=1
filters=1024
size=3
stride=1
pad=1
activation=leaky

###########

[convolutional]
batch_normalize=1
filters=256
size=1
stride=1
pad=1
activation=leaky

[convolutional]
batch_normalize=1
filters=512
size=3
stride=1
pad=1
activation=leaky

[convolutional]
size=1
stride=1
pad=1
filters=255
activation=linear

[yolo]
mask = 3,4,5
anchors = 10,14,  23,27,  37,58,  81,82,  135,169,  344,319
classes=80
num=6
jitter=.3
ignore_thresh = .7
truth_thresh = 1
random=1

[route]
layers = -4

[convolutional]
batch_normalize=1
filters=128
size=1
stride=1
pad=1
activation=leaky

[upsample]
stride=2

[route]
layers = -1, 8

[convolutional]
batch_normalize=1
filters=256
size=3
stride=1
pad=1
activation=leaky

[convolutional]
size=1
stride=1
pad=1
filters=255
activation=linear



[yolo]
mask = 0,1,2
anchors = 10,14, 23,27, 37,58, 81,82, 135,169, 344,319
classes=80
num=6
jitter=.3
ignore_thresh = .7
truth_thresh = 1
random=1

Hope it helps

Did you try the trt-yolo-app with a Jetson? Or just with a GPU?

With my Nvidia 1060 I could use the examples… but then with the jetson it brokes…