TRT5.0: Error when creating UFF graph with DepthwiseConv2dNative

Hello,

When converting a .pb graph to .uff using convert-to-uff, I get the following error which appears to be linked to a depth-wise convolution layer:

Converting to UFF graph
Traceback (most recent call last):
  File "/opt/tools/anaconda2/bin/convert-to-uff", line 11, in <module>
    sys.exit(main())
  File "/opt/tools/anaconda2/lib/python2.7/site-packages/uff/bin/convert_to_uff.py", line 79, in main
    output_filename=args.output
  File "/opt/tools/anaconda2/lib/python2.7/site-packages/uff/converters/tensorflow/conversion_helpers.py", line 159, in from_tensorflow_frozen_model
    return from_tensorflow(graphdef, output_nodes, preprocessor, **kwargs)
  File "/opt/tools/anaconda2/lib/python2.7/site-packages/uff/converters/tensorflow/conversion_helpers.py", line 132, in from_tensorflow
    name="main")
  File "/opt/tools/anaconda2/lib/python2.7/site-packages/uff/converters/tensorflow/converter.py", line 77, in convert_tf2uff_graph
    uff_graph, input_replacements)
  File "/opt/tools/anaconda2/lib/python2.7/site-packages/uff/converters/tensorflow/converter.py", line 64, in convert_tf2uff_node
    op, name, tf_node, inputs, uff_graph, tf_nodes=tf_nodes)
  File "/opt/tools/anaconda2/lib/python2.7/site-packages/uff/converters/tensorflow/converter.py", line 43, in convert_layer
    return cls.registry_[op](name, tf_node, inputs, uff_graph, **kwargs)
  File "/opt/tools/anaconda2/lib/python2.7/site-packages/uff/converters/tensorflow/converter_functions.py", line 276, in convert_depthwise_conv2d_native
    return _conv2d_helper(name, tf_node, inputs, uff_graph, func="depthwise", **kwargs)
  File "/opt/tools/anaconda2/lib/python2.7/site-packages/uff/converters/tensorflow/converter_functions.py", line 301, in _conv2d_helper
    number_groups = int(wt.attr['value'].tensor.tensor_shape.dim[2].size)
IndexError: list index out of range

Note that I am using python 2.7, tensorflow 1.11 (to create the .pb file) and TensorRT 5.0.0.10 (which comes with uff 0.5.1) on a p100 GPU.

I can provide the .pb file if needed, it is quite small (900kb)

Any help would be very much appreciated.
Thanks

hello,

It’d help us debug if you can please provide a small repro package that contains the source, model/pb/uff that exhibit this symptom.

you can DM me if you don’t want to post on the forum.

regards,
NVIDIA Enterprise Support

Hello,

Thanks for your interest.

After some digging, I think I found (part of) the problem.

When using tf.nn.depthwise_conv2d, it appears that tensorflow authorizes using a filter argument of shape [filter_height, filter_width, in_channels] if the channel_multiplier is 1. (see [url]https://www.tensorflow.org/api_docs/python/tf/nn/depthwise_conv2d[/url])

But this is incompatible with uff, which expects weights of dimension 4, hence the crash.

HOWEVER, even after correcting this, retraining a model… and successfully building an uff graph and then an engine, I am NOT able to get the same results using TRT and tensorflow. Still digging…

Got it working by provding input in NCHW format and converting output back to NHWC format.

It’s a bit confusing though, I thought specifying the format in the parser.register_input was enough.

@blancpaques can you explain more how did you change input in NCHW format and converting output back to NHWC format? In which file and where? Do you also use the following config file:
https://devtalk.nvidia.com/default/topic/1050465/jetson-nano/how-to-write-config-py-for-converting-ssd-mobilenetv2-to-uff-format/post/5331289/#5331289