Error convert tensorflow frozen model (pb) to TRT Inference model (uff)

I made tensorflow frozen model using google colab based on following nodebook.

And, I tried to convert pb file to uff file using uff.from_tensorflow_frozen_model.

uff.from_tensorflow_frozen_model(‘frozen_inference_graph.pb’, output_filename=‘model.uff’, debug_mode=False)

But, the following errors occurred. How can I make uff file?
Thank you for your help.

Converting FeatureExtractor/MobilenetV1/MobilenetV1/Conv2d_13_depthwise/act_quant/FakeQuantWithMinMaxVars as custom op: FakeQuantWithMinMaxVars
Traceback (most recent call last):
  File "convert.py", line 4, in <module>
    uff.from_tensorflow_frozen_model('frozen_inference_graph.pb', output_filename='model.uff', debug_mode=False)
  File "/usr/lib/python3.6/dist-packages/uff/converters/tensorflow/conversion_helpers.py", line 276, in from_tensorflow_frozen_model
    return from_tensorflow(graphdef, output_nodes, preprocessor, **kwargs)
  File "/usr/lib/python3.6/dist-packages/uff/converters/tensorflow/conversion_helpers.py", line 225, in from_tensorflow
    debug_mode=debug_mode)
  File "/usr/lib/python3.6/dist-packages/uff/converters/tensorflow/converter.py", line 141, in convert_tf2uff_graph
    uff_graph, input_replacements, debug_mode=debug_mode)
  File "/usr/lib/python3.6/dist-packages/uff/converters/tensorflow/converter.py", line 126, in convert_tf2uff_node
    op, name, tf_node, inputs, uff_graph, tf_nodes=tf_nodes, debug_mode=debug_mode)
  File "/usr/lib/python3.6/dist-packages/uff/converters/tensorflow/converter.py", line 94, in convert_layer
    return cls.registry_[op](name, tf_node, inputs, uff_graph, **kwargs)
  File "/usr/lib/python3.6/dist-packages/uff/converters/tensorflow/converter_functions.py", line 455, in convert_depthwise_conv2d_native
    return _conv2d_helper(name, tf_node, inputs, uff_graph, func="depthwise", **kwargs)
  File "/usr/lib/python3.6/dist-packages/uff/converters/tensorflow/converter_functions.py", line 480, in _conv2d_helper
    number_groups = int(wt.attr['value'].tensor.tensor_shape.dim[2].size)
  File "/usr/local/lib/python3.6/dist-packages/google/protobuf/internal/containers.py", line 209, in __getitem__
    return self._values[key]
IndexError: list index out of range

Hi,

uff.from_tensorflow_frozen_model(‘frozen_inference_graph.pb’, output_filename=‘model.uff’, debug_mode=False)

Could you set up the output_nodes and try it again?
https://docs.nvidia.com/deeplearning/tensorrt/api/python_api/uff/uff.html#uff.from_tensorflow

Parameters

  • graphdef ( tensorflow.GraphDef ) – The TensorFlow graph to convert.
  • output_nodes ( list ( str ) ) – The names of the outputs of the graph. If not provided, graphsurgeon is used to automatically deduce output nodes.

Thanks.

Thank you for your help.

I wanted to find node_names from my pb file. But, I could not get node_names.

My environment is:

tensorboard                   1.15.0
tensorflow                    1.15.4+nv20.10
tensorflow-estimator          1.15.1
tensorrt                      7.1.3.0

My program is:

import tensorflow as tf

def load_graph(model_file):
  graph = tf.Graph()
  graph_def = tf.GraphDef()

  with open(model_file, "rb") as f:
    graph_def.ParseFromString(f.read())
  with graph.as_default():
    tf.import_graph_def(graph_def)

  for node in graph_def.node:
       print(node.name)

  return graph

graph = load_graph('frozen_inference_graph.pb')
ops = graph.get_operations()

Error is:

2020-11-14 21:15:27.528828: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcudart.so.10.2
WARNING:tensorflow:Deprecation warnings have been disabled. Set TF_ENABLE_DEPRECATION_WARNINGS=1 to re-enable them.
Traceback (most recent call last):
  File "printNodes2.py", line 1, in <module>
    import tensorflow as tf
  File "/usr/local/lib/python3.6/dist-packages/tensorflow/__init__.py", line 101, in <module>
    from tensorflow_core import *
  File "/usr/local/lib/python3.6/dist-packages/tensorflow_core/__init__.py", line 36, in <module>
    from tensorflow._api.v1 import compat
  File "/usr/local/lib/python3.6/dist-packages/tensorflow_core/_api/v1/compat/__init__.py", line 24, in <module>
    from tensorflow._api.v1.compat import v2
  File "/usr/local/lib/python3.6/dist-packages/tensorflow_core/_api/v1/compat/v2/__init__.py", line 323, in <module>
    from tensorboard.summary._tf import summary
  File "/home/totti/09.DeepStreamTotti/model/tensorboard.py", line 3, in <module>
    with tf.Session() as sess:
AttributeError: module 'tensorflow' has no attribute 'Session'

I think, I can use “Session” on Tensor flow 1.x. What is my mistake?

Thank you for your help. I deleted tensorboard.py. I can get node_names using my program!