problem with uff.from_tensorflow


I am trying to create a TensorRT enging from a frozen graph I have from TensorFlow. I receive an error during the uff parsing part
Here is my code:

def load_graph(frozen_graph_filename):
    # We load the protobuf file from the disk and parse it to retrieve the 
    # unserialized graph_def
    with tf.gfile.GFile(frozen_graph_filename, "rb") as f:
        graph_def = tf.GraphDef()

    # Then, we import the graph_def into a new Graph and returns it 
    with tf.Graph().as_default() as graph:
        # The name var will prefix every op/nodes in your graph
        # Since we load everything in a new graph, this is not needed
        tf.import_graph_def(graph_def, name="prefix")
    return graph

if __name__ == '__main__':
        graph = load_graph(args.frozen_model_filename)
        OUTPUT_NAMES = 'prefix/prediction'
        INPUT_NAME = "prefix/imgs"
        INPUT_SHAPE = (3, 224, 448)

tf_model_graphdef = graph.as_graph_def()
        uff_model = uff.from_tensorflow(tf_model_graphdef, [OUTPUT_NAMES])

        G_LOGGER = trt.infer.ConsoleLogger(trt.infer.LogSeverity.ERROR)
        parser = uffparser.create_uff_parser()
        parser.register_input(INPUT_NAME, INPUT_SHAPE, 0)

        engine = trt.utils.uff_to_trt_engine(G_LOGGER, uff_model, parser, 1, 1 << 20)
        print "engine created"

I receive the following error

Using output node prefix/prediction
Converting to UFF graph
Warning: No conversion function registered for layer: Slice yet.
Converting as custom op Slice prefix/Slice
name: "prefix/Slice"
op: "Slice"
input: "prefix/Shape_1"
input: "prefix/Slice/begin"
input: "prefix/Slice/size"
attr {
  key: "Index"
  value {
    type: DT_INT32
attr {
  key: "T"
  value {
    type: DT_INT32

Traceback (most recent call last):
  File "", line 110, in <module>
    uff_model = uff.from_tensorflow(tf_model_graphdef, ['prefix/prediction'])
  File "/home/adm.Z625637/.conda/envs/trtp2.7/lib/python2.7/site-packages/uff/converters/tensorflow/", line 75, in from_tensorflow
  File "/home/adm.Z625637/.conda/envs/trtp2.7/lib/python2.7/site-packages/uff/converters/tensorflow/", line 64, in convert_tf2uff_graph
    uff_graph, input_replacements)
  File "/home/adm.Z625637/.conda/envs/trtp2.7/lib/python2.7/site-packages/uff/converters/tensorflow/", line 51, in convert_tf2uff_node
    op, name, tf_node, inputs, uff_graph, tf_nodes=tf_nodes)
  File "/home/adm.Z625637/.conda/envs/trtp2.7/lib/python2.7/site-packages/uff/converters/tensorflow/", line 28, in convert_layer
    fields = cls.parse_tf_attrs(tf_node.attr)
  File "/home/adm.Z625637/.conda/envs/trtp2.7/lib/python2.7/site-packages/uff/converters/tensorflow/", line 177, in parse_tf_attrs
    for key, val in attrs.items()}
  File "/home/adm.Z625637/.conda/envs/trtp2.7/lib/python2.7/site-packages/uff/converters/tensorflow/", line 177, in <dictcomp>
    for key, val in attrs.items()}
  File "/home/adm.Z625637/.conda/envs/trtp2.7/lib/python2.7/site-packages/uff/converters/tensorflow/", line 172, in parse_tf_attr_value
    return cls.convert_tf2uff_field(code, val)
  File "/home/adm.Z625637/.conda/envs/trtp2.7/lib/python2.7/site-packages/uff/converters/tensorflow/", line 146, in convert_tf2uff_field
    return TensorFlowToUFFConverter.convert_tf2numpy_dtype(val)
  File "/home/adm.Z625637/.conda/envs/trtp2.7/lib/python2.7/site-packages/uff/converters/tensorflow/", line 74, in convert_tf2numpy_dtype
    return np.dtype(dt[dtype])
TypeError: list indices must be integers, not AttrValue
TensorFlow v. 1.4.1
TensorRT v. 3.0.1
Cuda compilation tools, release 8.0, V8.0.61

Any help on this issue please ?


2 recommendations.

  1. Please update your TF, TRT, CUDA to latest versions to take advantage of the latest features/fixes
  2. the error is saying slice layer is not supported. To add custom layer support, please reference


Thanks for the advice, but actually the thing concerning the Slice layer is just a warning, the error is something else related to

uff_model = uff.from_tensorflow(tf_model_graphdef, [OUTPUT_NAMES])

the error is

TypeError: list indices must be integers, not AttrValue

I think the error is a consequence of the unsupported layer.