TensorRT and UFF support for NVIDIA DRIVE PX 2 [cross-post from TensorRT forum]

Hello,

I have already posted this on the TensorRT forum, but since we are working on DRIVE PX 2 platform, I thought someone here may know something.

We are working to deploy a neural net defined in TensorFlow on NVIDIA DRIVE PX 2 using TensorRT. The details of our development environment follow.

Training Desktop: Ubuntu 16.04 LTS, Python 2.x, CUDA 8.x, cuDNN 5.x, TensorFlow 1.4
Platform Host (PC): Ubuntu 16.04 LTS, Python 2.x, CUDA 9.0, cuDNN 7.1, TensorRT 3.0.2
Platform Target (DPX2): Ubuntu 16.04, Python 2.x, CUDA 9.0, cuDNN 7.1, TensorRT 3.0.2

Since I am using TRT version 3.0.2, the UFF version is 0.2.0.

We received a frozen graph (.pb) file from our internal Applications Group. Thereafter, on the hoswe followed the steps described at https://docs.nvidia.com/deeplearning/sdk/tensorrt-archived/tensorrt_302/tensorrt-developer-guide/index.html#convert_model_tensorflow. The terminal output of this procedure is shown below.

sagar@Sagar:~$ python
    Python 2.7.12 (default, Nov 12 2018, 14:36:49) 
    [GCC 5.4.0 20160609] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import uff
    >>> uff_model = uff.from_tensorflow_frozen_model(frozen_file="/home/sagar/backups/Reshape_1_frozen_model.pb", output_nodes=["output/Reshape_1"], preprocessor=None, output_filename="/home/sagar/backups/tmp.uff")
    Using output node output/Reshape_1
    Converting to UFF graph
    Warning: No conversion function registered for layer: Merge yet.
    Converting as custom op Merge stage4_0/Gconv1x1/batch_normalization/cond/Merge
    name: "stage4_0/Gconv1x1/batch_normalization/cond/Merge"
    op: "Merge"
    input: "stage4_0/Gconv1x1/batch_normalization/cond/FusedBatchNorm_1"
    input: "stage4_0/Gconv1x1/batch_normalization/cond/FusedBatchNorm"
    attr {
      key: "N"
      value {
        i: 2
      }
    }
    attr {
      key: "T"
      value {
        type: DT_FLOAT
      }
    }

    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/home/sagar/.local/lib/python2.7/site-packages/uff/converters/tensorflow/conversion_helpers.py", line 103, in from_tensorflow_frozen_model
        return from_tensorflow(graphdef, output_nodes, **kwargs)
      File "/home/sagar/.local/lib/python2.7/site-packages/uff/converters/tensorflow/conversion_helpers.py", line 75, in from_tensorflow
        name="main")
      File "/home/sagar/.local/lib/python2.7/site-packages/uff/converters/tensorflow/converter.py", line 64, in convert_tf2uff_graph
        uff_graph, input_replacements)
      File "/home/sagar/.local/lib/python2.7/site-packages/uff/converters/tensorflow/converter.py", line 46, in convert_tf2uff_node
        inp_node = tf_nodes[inp_name]
    KeyError: u'^stage4_0/Gconv1x1/batch_normalization/cond/switch_t'
    >>>

My first question is - in what ways can I resolve this error?

Upon reading through many posts on this forum, I observed that many people have reported such issues, and they have been asked to upgrade their TensorRT/UFF version. Suppose I upgraded the UFF version on our Platform Host PC. Suppose I also succeeded in converting the .pb file to a .uff file with the new UFF. The problem is, I have to parse this UFF file on the Platform Target DPX2, and the UFF version for that platform is stuck at 0.2.0 (since it is part of the DriveInstall 5.0.5.0b package for automotive use).

This brings me to my second question - is it possible to create a UFF file with UFF v0.5.x and then parse it with UFF v0.2.0?

Thank you.

Dear sagar.kirtany,
Both the UFF parsers should be in same version to have smooth transition. Could you please check this symtom on latest PDK?

Dear SivaRamaKrishna,

Thank you for your reply. We upgraded our TensorRT to 4.x and checked again. We are now receiving the following error message.

>>> uff.from_tensorflow_frozen_model(pb_file,output_nodes=["output/Reshape_1"])
Using output node output/Reshape_1
Converting to UFF graph
Warning: No conversion function registered for layer: Merge yet.
Converting as custom op Merge stage4_0/Gconv1x1/batch_normalization/cond/Merge
name: "stage4_0/Gconv1x1/batch_normalization/cond/Merge"
op: "Merge"
input: "stage4_0/Gconv1x1/batch_normalization/cond/FusedBatchNorm_1"
input: "stage4_0/Gconv1x1/batch_normalization/cond/FusedBatchNorm"
attr {
  key: "N"
  value {
    i: 2
  }
}
attr {
  key: "T"
  value {
    type: DT_FLOAT
  }
}

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/dist-packages/uff/converters/tensorflow/conversion_helpers.py", line 113, in from_tensorflow_frozen_model
    return from_tensorflow(tf_graphdef, output_nodes, **kwargs)
  File "/usr/lib/python2.7/dist-packages/uff/converters/tensorflow/conversion_helpers.py", line 77, in from_tensorflow
    name="main")
  File "/usr/lib/python2.7/dist-packages/uff/converters/tensorflow/converter.py", line 74, in convert_tf2uff_graph
    uff_graph, input_replacements)
  File "/usr/lib/python2.7/dist-packages/uff/converters/tensorflow/converter.py", line 61, in convert_tf2uff_node
    op, name, tf_node, inputs, uff_graph, tf_nodes=tf_nodes)
  File "/usr/lib/python2.7/dist-packages/uff/converters/tensorflow/converter.py", line 31, in convert_layer
    fields = cls.parse_tf_attrs(tf_node.attr)
  File "/usr/lib/python2.7/dist-packages/uff/converters/tensorflow/converter.py", line 201, in parse_tf_attrs
    for key, val in attrs.items()}
  File "/usr/lib/python2.7/dist-packages/uff/converters/tensorflow/converter.py", line 201, in <dictcomp>
    for key, val in attrs.items()}
  File "/usr/lib/python2.7/dist-packages/uff/converters/tensorflow/converter.py", line 196, in parse_tf_attr_value
    return cls.convert_tf2uff_field(code, val)
  File "/usr/lib/python2.7/dist-packages/uff/converters/tensorflow/converter.py", line 170, in convert_tf2uff_field
    return TensorFlowToUFFConverter.convert_tf2numpy_dtype(val)
  File "/usr/lib/python2.7/dist-packages/uff/converters/tensorflow/converter.py", line 87, in convert_tf2numpy_dtype
    return np.dtype(dt[dtype])
TypeError: list indices must be integers, not AttrValue
>>>

Do you see anything that we may have missed here?

Dear sagar.kirtany,
Is it possible to attach a pb file here to reproduce it on my side. If not, Could you file a bug with relavant information and share Bud ID.

Dear Siva,
Unfortunately, we are not able to share the pb file at this time. We will consider opening a bug and get back to you. Thank you.