# Cannot convert a tensorflow model to UFF

**URL:** <https://forums.developer.nvidia.com/t/cannot-convert-a-tensorflow-model-to-uff/58162>\
**Category:** Jetson TX2\
**Created:** [February 13, 2018, 9:03am UTC](https://forums.developer.nvidia.com/t/cannot-convert-a-tensorflow-model-to-uff/58162 "2018-02-13T09:03:25Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![chenyiyibupt](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@chenyiyibupt](https://forums.developer.nvidia.com/u/chenyiyibupt)\
**Post date:** [February 13, 2018, 9:03am UTC](https://forums.developer.nvidia.com/t/cannot-convert-a-tensorflow-model-to-uff/58162/1 "2018-02-13T09:03:25Z")

</div>

Hello,

When I’m following the guide to convert a tensorflow model to UFF

```auto
res_graph = train_net(train_x, train_y, test_x, test_y, num_class, MAX_LEN, LEARNING_RATE)

# Convert a model to UFF
uff_model = uff.from_tensorflow(graphdef=res_graph,
                                    output_filename=UFF_OUTPUT_FILENAME,
                                    output_nodes=OUTPUT_NAMES,
                                    text=True)

G_LOGGER = trt.infer.ConsoleLogger(trt.infer.LogSeverity.ERROR)

parser = uffparser.create_uff_parser()
parser.register_input("input", (1, 1, 800), 0) # [channels, height, width]
parser.register_output("layer_fc/tf_output/BiasAdd")

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

```

```auto
[TensorRT] ERROR: Failed to parse UFF model stream
  File "/usr/local/lib/python2.7/dist-packages/tensorrt/utils/_utils.py", line 186, in uff_to_trt_engine
    assert(parser_result)
Traceback (most recent call last):
  File "/home/yizong/PycharmProjects/OfflineModelTensorflow-20180209/tensorflow_model.py", line 270, in <module>
    engine = trt.utils.uff_to_trt_engine(G_LOGGER, uff_model, parser, 1, 1 << 20)
  File "/usr/local/lib/python2.7/dist-packages/tensorrt/utils/_utils.py", line 194, in uff_to_trt_engine
    raise AssertionError('UFF parsing failed on line {} in statement {}'.format(line, text))
AssertionError: UFF parsing failed on line 186 in statement assert(parser_result)

```

Then I modify my code like this, save the .uff file and read the .uff file:

```auto
# Read UFF model
uff_model = open(UFF_OUTPUT_FILENAME, 'rb').read()

# generate a TensorRT engine by creating a logger for TensorRT
G_LOGGER = trt.infer.ConsoleLogger(trt.infer.LogSeverity.ERROR)

# Create a UFF parser and identify the desired input and output nodes
parser = uffparser.create_uff_parser()
parser.register_input("input", (1, 1, 800), 0) # [channels, height, width]
parser.register_output("layer_fc/tf_output/BiasAdd")

# Pass the logger, parser, the UFF model stream, and some settings (max batch size and
# max workspace size) to a utility function that will create the engine
engine = trt.utils.uff_to_trt_engine(G_LOGGER, uff_model, parser, 1, 1 << 20)

```

It shows the error 134 like the below:

```auto
Process finished with exit code 134 (interrupted by signal 6: SIGABRT)

```

I don’t know why… Thanks for help.

---

<div class="post-metadata">

**Author:** ![dusty\_nv](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/dusty_nv/32/14043_2.png) [@dusty\_nv](https://forums.developer.nvidia.com/u/dusty_nv)\
**Post date:** [February 14, 2018, 4:05pm UTC](https://forums.developer.nvidia.com/t/cannot-convert-a-tensorflow-model-to-uff/58162/2 "2018-02-14T16:05:55Z")

</div>

Hi chenyiyibupt, which network are you trying to convert?

Are you able to successfully run any of the simple examples from the documentation through the converter?

---

<div class="post-metadata">

**Author:** ![p146103](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@p146103](https://forums.developer.nvidia.com/u/p146103)\
**Post date:** [September 28, 2018, 1:51pm UTC](https://forums.developer.nvidia.com/t/cannot-convert-a-tensorflow-model-to-uff/58162/3 "2018-09-28T13:51:44Z")

</div>

Hi @chenyiyibupt have you solved this error?  
if you have resolved it please share the solution.  
Error

File “/home/wang/PycharmProjects/Test\_VGG\_Tensorrt/create\_engine.py”, line 44, in   
create\_and\_save\_inference\_engine()  
File “/home/wang/PycharmProjects/Test\_VGG\_Tensorrt/create\_engine.py”, line 29, in create\_and\_save\_inference\_engine  
trt.infer.DataType.FLOAT)  
File “/usr/local/lib/python3.5/dist-packages/tensorrt/utils/\_utils.py”, line 263, in uff\_to\_trt\_engine  
raise AssertionError(‘UFF parsing failed on line {} in statement {}’.format(line, text))  
AssertionError: UFF parsing failed on line 255 in statement assert(parser.parse(stream, network, model\_datatype))

Thanks

---

<div class="post-metadata">

**Author:** ![AastaLLL](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/aastalll/32/14043_2.png) [@AastaLLL](https://forums.developer.nvidia.com/u/AastaLLL)\
**Post date:** [October 5, 2018, 7:13am UTC](https://forums.developer.nvidia.com/t/cannot-convert-a-tensorflow-model-to-uff/58162/4 "2018-10-05T07:13:26Z")

</div>

Hi,

Could you share the model you used and the converting python script with us?  
Thanks.

---

<div class="post-metadata">

**Author:** ![p146103](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@p146103](https://forums.developer.nvidia.com/u/p146103)\
**Post date:** [October 8, 2018, 6:36am UTC](https://forums.developer.nvidia.com/t/cannot-convert-a-tensorflow-model-to-uff/58162/5 "2018-10-08T06:36:28Z")

</div>

Thanks @AastaLLL I have followed Nvidia documentation ([https://docs.nvidia.com/deeplearning/sdk/tensorrt-api/python\_api/workflows/tf\_to\_tensorrt.html](https://docs.nvidia.com/deeplearning/sdk/tensorrt-api/python_api/workflows/tf_to_tensorrt.html)) and my task is object detection

code

import tensorflow as tf  
import tensorrt as trt  
from tensorrt.parsers import uffparser  
import pycuda.driver as cuda  
import pycuda.autoinit  
import numpy as np  
from random import randint # generate a random test case  
from PIL import Image  
from matplotlib.pyplot import imshow # To show test case  
import time  
import os

import keras.backend.tensorflow\_backend as K  
import uff  
uff\_model = uff.from\_tensorflow('/home/cloud4/Akhtar\_Vir\_Env/my\_new\_app/mars-sma$  
G\_LOGGER = trt.infer.ConsoleLogger(trt.infer.LogSeverity.ERROR)  
parser = uffparser.create\_uff\_parser()  
parser.register\_input(“images”, (128, 64, 3), 0)  
parser.register\_output(“features”)  
engine = trt.utils.uff\_to\_trt\_engine(G\_LOGGER, uff\_model, parser, 1, 1 \<\< 20)#this line genrate the Error

## File “/usr/local/lib/python3.5/dist-packages/tensorrt/utils/\_utils.py”, line 255, in uff\_to\_trt\_engine assert(parser.parse(stream, network, model\_datatype))

AssertionError Traceback (most recent call last)  
/usr/local/lib/python3.5/dist-packages/tensorrt/utils/\_utils.py in uff\_to\_trt\_engine(logger, stream, parser, max\_batch\_size, max\_workspace\_size, datatype, plugin\_factory, calibrator)  
254 try:  
 → 255 assert(parser.parse(stream, network, model\_datatype))  
256 except AssertionError:

AssertionError:

During handling of the above exception, another exception occurred:

AssertionError Traceback (most recent call last)  
 in ()  
----\> 1 engine = trt.utils.uff\_to\_trt\_engine(G\_LOGGER, uff\_model, parser, 1, 1 \<\< 20)

/usr/local/lib/python3.5/dist-packages/tensorrt/utils/\_utils.py in uff\_to\_trt\_engine(logger, stream, parser, max\_batch\_size, max\_workspace\_size, datatype, plugin\_factory, calibrator)  
261 filename, line, func, text = tb\_info[-1]  
262  
 → 263 raise AssertionError(‘UFF parsing failed on line {} in statement {}’.format(line, text))  
264  
265

AssertionError: UFF parsing failed on line 255 in statement assert(parser.parse(stream, network, model\_datatype))

you can see my frozen graph

> **[graph\_large\_attrs\_key=\_too\_large\_attrs&amp;limit\_attr\_size=1024&amp;run= (8).png](https://drive.google.com/file/d/1AGBpXzXVCABoLNnkOap-Q13EaLHLAeZ3/view?usp=sharing)**
>
> Google Drive file.

And the file from which I created frozen graph

> **[freeze\_model.py](https://drive.google.com/file/d/16TpAB9XYn3PEufVlwRBAR2vjfgzBTAZf/view?usp=sharing)**
>
> Google Drive file.

system information  
Linux:16  
Cuda:9.0  
driver 390.87  
cudnn 7.1  
tensorRt:4  
Python 3.5  
Gpu:Gtx 1080  
Tensorflow:1.7.1

Thanks

---

<div class="post-metadata">

**Author:** ![jkjung13](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/jkjung13/32/10943_2.png) [@jkjung13](https://forums.developer.nvidia.com/u/jkjung13)\
**Post date:** [October 8, 2018, 2:12pm UTC](https://forums.developer.nvidia.com/t/cannot-convert-a-tensorflow-model-to-uff/58162/6 "2018-10-08T14:12:57Z")

</div>

Maybe you could try optimizing your model with TF-TRT directly (skipping the step of UFF conversion).

Reference:

1. [url][https://devtalk.nvidia.com/default/topic/1037019/jetson-tx2/tensorflow-object-detection-and-image-classification-accelerated-for-nvidia-jetson/[/url]](https://devtalk.nvidia.com/default/topic/1037019/jetson-tx2/tensorflow-object-detection-and-image-classification-accelerated-for-nvidia-jetson/%5B/url%5D)

2. [url][https://devtalk.nvidia.com/default/topic/1042106/how-to-train-a-custom-object-detector-and-deploy-it-onto-jtx2-with-tf-trt-tensorrt-optimized-/#5285864[/url]](https://devtalk.nvidia.com/default/topic/1042106/how-to-train-a-custom-object-detector-and-deploy-it-onto-jtx2-with-tf-trt-tensorrt-optimized-/#5285864%5B/url%5D)

---

<div class="post-metadata">

**Author:** ![p146103](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@p146103](https://forums.developer.nvidia.com/u/p146103)\
**Post date:** [October 9, 2018, 8:09am UTC](https://forums.developer.nvidia.com/t/cannot-convert-a-tensorflow-model-to-uff/58162/7 "2018-10-09T08:09:32Z")

</div>

Thanks @jkjung13 I am follow the ([https://docs.nvidia.com/deeplearning/sdk/tensorrt-api/python\_api/workflows/tf\_to\_tensorrt.html](https://docs.nvidia.com/deeplearning/sdk/tensorrt-api/python_api/workflows/tf_to_tensorrt.html)) and here is my code

Code  
import tensorflow as tf  
import tensorrt as trt  
from tensorrt.parsers import uffparser  
import pycuda.driver as cuda  
import pycuda.autoinit  
import numpy as np  
from random import randint # generate a random test case  
from PIL import Image  
from matplotlib.pyplot import imshow # To show test case  
import time  
import os  
#import keras as K  
import keras.backend.tensorflow\_backend as K  
uff\_model = uff.from\_tensorflow(‘/home/cloud4/Akhtar\_Vir\_Env/my\_new\_app/mars-small128.pb’, [“images”])  
G\_LOGGER = trt.infer.ConsoleLogger(trt.infer.LogSeverity.ERROR)

parser = uffparser.create\_uff\_parser()  
parser.register\_input(“images”, (128, 64, 3), 0)  
parser.register\_output(“features”)  
#these above there lines return true

engine = trt.utils.uff\_to\_trt\_engine(G\_LOGGER, uff\_model, parser, 1, 1 \<\< 20)  
#This last line genrate this error

## File “/usr/local/lib/python3.5/dist-packages/tensorrt/utils/\_utils.py”, line 255, in uff\_to\_trt\_engine assert(parser.parse(stream, network, model\_datatype))

AssertionError Traceback (most recent call last)  
/usr/local/lib/python3.5/dist-packages/tensorrt/utils/\_utils.py in uff\_to\_trt\_engine(logger, stream, parser, max\_batch\_size, max\_workspace\_size, datatype, plugin\_factory, calibrator)  
254 try:  
 → 255 assert(parser.parse(stream, network, model\_datatype))  
256 except AssertionError:

AssertionError:

During handling of the above exception, another exception occurred:

AssertionError Traceback (most recent call last)  
 in ()  
----\> 1 engine = trt.utils.uff\_to\_trt\_engine(G\_LOGGER, uff\_model, parser, 1, 1 \<\< 20)

/usr/local/lib/python3.5/dist-packages/tensorrt/utils/\_utils.py in uff\_to\_trt\_engine(logger, stream, parser, max\_batch\_size, max\_workspace\_size, datatype, plugin\_factory, calibrator)  
261 filename, line, func, text = tb\_info[-1]  
262  
 → 263 raise AssertionError(‘UFF parsing failed on line {} in statement {}’.format(line, text))  
264  
265

AssertionError: UFF parsing failed on line 255 in statement assert(parser.parse(stream, network, model\_datatype))

Thanks

---

<div class="post-metadata">

**Author:** ![AastaLLL](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/aastalll/32/14043_2.png) [@AastaLLL](https://forums.developer.nvidia.com/u/AastaLLL)\
**Post date:** [October 11, 2018, 7:47am UTC](https://forums.developer.nvidia.com/t/cannot-convert-a-tensorflow-model-to-uff/58162/8 "2018-10-11T07:47:16Z")

</div>

Hi,

Please use the output op name(‘_features_’ ?) to convert an UFF file.

For example:

```auto
uff_model = uff.from_tensorflow('/home/cloud4/Akhtar_Vir_Env/my_new_app/mars-small128.pb', <b>["features"]</b>)

```

Thanks.

---

<div class="post-metadata">

**Author:** ![p146103](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@p146103](https://forums.developer.nvidia.com/u/p146103)\
**Post date:** [October 18, 2018, 6:08am UTC](https://forums.developer.nvidia.com/t/cannot-convert-a-tensorflow-model-to-uff/58162/9 "2018-10-18T06:08:13Z")

</div>

Thanks @AastaLLL  
When I change my code like this then it generate this error  
uff\_model = uff.from\_tensorflow(‘/home/cloud4/Akhtar\_Vir\_Env/my\_new\_app/mars-small128.pb’, [“features”])

Error

## Using output node features Converting to UFF graph

UffException Traceback (most recent call last)  
 in ()  
----\> 1 uff\_model = uff.from\_tensorflow(‘/home/cloud4/Akhtar\_Vir\_Env/my\_new\_app/mars-small128.pb’, [“features”])

/usr/local/lib/python3.5/dist-packages/uff/converters/tensorflow/conversion\_helpers.py in from\_tensorflow(graphdef, output\_nodes, preprocessor, \*\*kwargs)  
121 output\_nodes=output\_nodes,  
122 input\_replacements=input\_replacements,  
 → 123 name=“main”)  
124  
125 uff\_metagraph\_proto = uff\_metagraph.to\_uff()

/usr/local/lib/python3.5/dist-packages/uff/converters/tensorflow/converter.py in convert\_tf2uff\_graph(cls, tf\_graphdef, uff\_metagraph, output\_nodes, input\_replacements, name)  
77 while len(nodes\_to\_convert):  
78 nodes\_to\_convert += cls.convert\_tf2uff\_node(nodes\_to\_convert.pop(), tf\_nodes,  
—\> 79 uff\_graph, input\_replacements)  
80 for output in output\_nodes:  
81 uff\_graph.mark\_output(output)

/usr/local/lib/python3.5/dist-packages/uff/converters/tensorflow/converter.py in convert\_tf2uff\_node(cls, name, tf\_nodes, uff\_graph, input\_replacements)  
54 return   
55 if name not in tf\_nodes:  
—\> 56 raise UffException(str(name) + " was not found in the graph. Please use the -l option to list nodes in the graph.")  
57 tf\_node = tf\_nodes[name]  
58 inputs = list(tf\_node.input)

UffException: features was not found in the graph. Please use the -l option to list nodes in the graph.

---

<div class="post-metadata">

**Author:** ![AastaLLL](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/aastalll/32/14043_2.png) [@AastaLLL](https://forums.developer.nvidia.com/u/AastaLLL)\
**Post date:** [October 26, 2018, 6:31am UTC](https://forums.developer.nvidia.com/t/cannot-convert-a-tensorflow-model-to-uff/58162/10 "2018-10-26T06:31:05Z")

</div>

Hi,

It looks like the node you required is NOT in the .pb file.

```auto
UffException: features was not found in the graph. Please use the -l option to list nodes in the graph.

```

Could you check if each node in the _output\_nodes_ is well-included in your model?  
If we don’t miss something, the error should come from the ‘_mars-small128.pb_’ model doesn’t have a layer named as ‘_features_’.

Thanks.

---

<div class="post-metadata">

**Author:** ![edding](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@edding](https://forums.developer.nvidia.com/u/edding)\
**Post date:** [January 4, 2019, 3:47pm UTC](https://forums.developer.nvidia.com/t/cannot-convert-a-tensorflow-model-to-uff/58162/11 "2019-01-04T15:47:07Z")

</div>

Hi,

I have the same problem. I’m trying to convert the ssd\_mobilenet\_v1\_coco\_2018\_01\_28.

The outputs selected need to change because the _uff.from\_tensorflow_ function remove the Identity layers (and the outputs layers are of that type). This function also return a lot of warning because there are not implementation of layers. Maybe if you use anyway that uff\_model when you try to do the _trt.utils.uff\_to\_trt\_engine_ you get that error:

```auto
AssertionError: UFF parsing failed on line 255 in statement assert(parser.parse(stream, network, model_datatype))

```

Do you know if someone could convert the ssd\_mobilenet\_v1 to uff\_model?

---

<div class="post-metadata">

**Author:** ![AastaLLL](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/aastalll/32/14043_2.png) [@AastaLLL](https://forums.developer.nvidia.com/u/AastaLLL)\
**Post date:** [January 11, 2019, 7:00am UTC](https://forums.developer.nvidia.com/t/cannot-convert-a-tensorflow-model-to-uff/58162/12 "2019-01-11T07:00:34Z")

</div>

Hi,

Do you follow the steps shared in this tutorial:  
[url][https://github.com/NVIDIA-AI-IOT/tf\_to\_trt\_image\_classification[/url]](https://github.com/NVIDIA-AI-IOT/tf_to_trt_image_classification%5B/url%5D)

You may need to update the output configure but should be similar.  
Thanks.

---

<div class="post-metadata">

**Author:** ![edding](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@edding](https://forums.developer.nvidia.com/u/edding)\
**Post date:** [January 11, 2019, 12:59pm UTC](https://forums.developer.nvidia.com/t/cannot-convert-a-tensorflow-model-to-uff/58162/13 "2019-01-11T12:59:28Z")

</div>

Hi,

I follow the next repo that it is forked from that:

> **[GitHub - jkjung-avt/tf\_trt\_models: TensorFlow object detection models accelerated...](https://github.com/jkjung-avt/tf_trt_models)**
>
> TensorFlow object detection models accelerated with NVIDIA TensorRT (TF-TRT)

I test that and everything runs ok, and the times improve in the jetson TX2 compared to the original TensorFlow model, but in a Tesla K80 the times get worse.

That code not convert the model to an UFF model and then build the engine. Only optimize the TensorFlow model with TensorRT and then continue using the TensorFlow model. For do that possible, it need to change a few layers.

However when I try to convert the original model to UFF, there are a lot of layers that are not implemented..

---

<div class="post-metadata">

**Author:** ![nadeemm](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/nadeemm/32/367020_2.png) [@nadeemm](https://forums.developer.nvidia.com/u/nadeemm)\
**Post date:** [October 18, 2021, 6:31pm UTC](https://forums.developer.nvidia.com/t/cannot-convert-a-tensorflow-model-to-uff/58162/14 "2021-10-18T18:31:17Z")

</div>

Closed on October 18, 2021, 6:31pm UTC


