Fail to convert an Inception-V3 model to uff.

Hi there,

I met a problem when I tried to convert an Inception-V3 model to uff. Here is part of my code:

Convert a tensorflow model to UFF
uff_model =uff.from_tensorflow_frozen_model("./inception_v3.pb",["InceptionV3/Logits/SpatialSqueeze"])
#Import a UFF Model into TensorRT and Create an Engine
G_LOGGER = trt.infer.ConsoleLogger(trt.infer.LogSeverity.ERROR)

parser = uffparser.create_uff_parser()
parser.register_input("input", (1,224,224), 0)
parser.register_output("InceptionV3/Logits/SpatialSqueeze")

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

And the error is below:

Using output node InceptionV3/Logits/SpatialSqueeze
Converting to UFF graph
No. nodes: 788
[TensorRT] ERROR: InceptionV3/InceptionV3/Conv2d_1a_3x3/Conv2D: kernel weights has count 864 but 288 was expected
[TensorRT] ERROR: UFFParser: Parser error: InceptionV3/InceptionV3/Conv2d_1a_3x3/BatchNorm/FusedBatchNorm: Invalid scale mode, nbWeights: 32
[TensorRT] ERROR: Failed to parse UFF model stream
  File "/usr/lib64/python2.7/site-packages/tensorrt/utils/_utils.py", line 191, in uff_to_trt_engine
    assert(parser.parse(stream, network, model_datatype))
Traceback (most recent call last):
  File "tensorrt_gen.py", line 28, in <module>
    engine = trt.utils.uff_to_trt_engine(G_LOGGER, uff_model, parser, 128, 1 << 10)
  File "/usr/lib64/python2.7/site-packages/tensorrt/utils/_utils.py", line 199, in uff_to_trt_engine
    raise AssertionError('UFF parsing failed on line {} in statement {}'.format(line, text))
AssertionError: UFF parsing failed on line 191 in statement assert(parser.parse(stream, network, model_datatype))

Any help would be appreciated.

Hi,

Not sure if there is any incorrect setting for the conversion.

Here is a tutorial for TensorFlow to TensorRT and inception_v3 model is also included:

It’s recommended to take a look and please let us know if this issue keeps on.
Thanks.

hello, @AastaLLL, I met similar problem, could u give me some advise,
I tried to convert my model to uff then inference in tensorrt.

pb model: https://goo.gl/zTtbMR
uff model: https://goo.gl/v4TNGh

I’m sure this pb model can worked normally in tensorflow.

pb_model='20180518-115854.pb'
G_LOGGER = trt.infer.ConsoleLogger(trt.infer.LogSeverity.ERROR)
uff_model = uff.from_tensorflow_frozen_model(pb_model, ["embeddings"])

parser = uffparser.create_uff_parser()
parser.register_input("input", (160,160,3), 0)
parser.register_output("embeddings")

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

The program produces the following error:

[TensorRT] ERROR: Parameter check failed at: Utils.cpp::reshapeWeights::71, condition: input.values != nullptr
[TensorRT] ERROR: UFFParser: Parser error: InceptionResnetV1/Conv2d_1a_3x3/BatchNorm/FusedBatchNorm: reshape weights failed!
[TensorRT] ERROR: Failed to parse UFF model stream
  File "/usr/lib/python2.7/dist-packages/tensorrt/utils/_utils.py", line 191, in uff_to_trt_engine
    assert(parser.parse(stream, network, model_datatype))
Traceback (most recent call last):
  File "inference.py", line 40, in <module>
    engine = trt.utils.uff_to_trt_engine(G_LOGGER, uff_model, parser, 1, 1 << 20, trt.infer.DataType.FLOAT)
  File "/usr/lib/python2.7/dist-packages/tensorrt/utils/_utils.py", line 199, in uff_to_trt_engine
    raise AssertionError('UFF parsing failed on line {} in statement {}'.format(line, text))
AssertionError: UFF parsing failed on line 191 in statement assert(parser.parse(stream, network, model_datatype))

Hi,

Based on the log, there is a missing input buffer.
Could you check your implementation with our sample again?
[url]https://docs.nvidia.com/deeplearning/sdk/tensorrt-api/topics/topics/workflows/tf_to_tensorrt.html[/url]

Thanks.

@AastaLLL, thank for your reply!

I have referenced this link but still encountered some problems.
And, I try to inference pb model by tensorflow like below:

import tensorflow as tf
from tensorflow.python.platform import gfile
import os, sys
import numpy as np
from scipy import misc

def main():
	with tf.Graph().as_default():
		with tf.Session() as sess:
			load_model('/home/jerry/facenet_UFF/remove_unuse_20180518-115854.pb')

			# Get input and output tensors
			images_placeholder = tf.get_default_graph().get_tensor_by_name("input:0")
			embeddings = tf.get_default_graph().get_tensor_by_name("embeddings:0")

			
			images = misc.imread('Anthony_Hopkins_0001.jpg', mode='RGB')
			images = misc.imresize(images, (160, 160), interp='bilinear')

			img_list = [None] * 1
			img_list[0] = images
			images = np.stack(img_list)

			feed_dict = { images_placeholder: images }
			emb = sess.run(embeddings, feed_dict=feed_dict)

			print(emb)

def load_model(model):
	model_exp = os.path.expanduser(model)
	if (os.path.isfile(model_exp)):
		print('Model filename: %s' % model_exp)
		with gfile.FastGFile(model_exp,'rb') as f:
			graph_def = tf.GraphDef()
			graph_def.ParseFromString(f.read())
			tf.import_graph_def(graph_def, name='')
			# print(graph_def)

if __name__ == '__main__':
	main()

It could work normally, so I think the input’s placeholder should be no error. But I’m not sure.
Is it a problem when I convert UFF?
Very Thankful

Hi @AastaLLL,

Thanks for your reply.

I met some setup problems when I followed the tutorial you recommended. Here’s error:

[root@a108752133 build]# make
[ 16%] Linking CXX executable classify_image
/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../libnvparsers.so:对‘std::invalid_argument::invalid_argument(char const*)@GLIBCXX_3.4.21’未定义的引用
/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../libnvinfer.so:对‘std::__throw_out_of_range_fmt(char const*, ...)@GLIBCXX_3.4.20’未定义的引用
/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../libnvparsers.so:对‘__cxa_throw_bad_array_new_length@CXXABI_1.3.8’未定义的引用
/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../libnvparsers.so:对‘std::runtime_error::runtime_error(char const*)@GLIBCXX_3.4.21’未定义的引用
collect2: 错误:ld 返回 1
make[2]: *** [examples/classify_image/classify_image] 错误 1
make[1]: *** [examples/classify_image/CMakeFiles/classify_image.dir/all] 错误 2
make: *** [all] 错误 2

And here’s my set up flows:

git clone --recursive https://github.com/NVIDIA-Jetson/tf_to_trt_image_classification.git
cd tf_to_trt_image_classification
mkdir build
cd build
cmake ..
make

I’m not very familiar with C/C++, could you help tell me what’s going on and what should I do?

Hi @jerryhouuu

I have solved my original problem. I just set the wrong input size of the parser. It worked when I changed

parser.register_input("input", (1,224,224), 0)

to

parser.register_input("input", (3,224,224), 0)

Based on the information you provided, it seems that your input node is not named “input”, it’s might be “images_placeholder”. Hope it works.

@627185180 hi, Thank for your request and sorry to disturb you.
sorry i had some mistake in above code, i have modified.

In my tensorflow inference, I did “images_placeholder = tf.get_default_graph().get_tensor_by_name(“input:0”)”

so i think my input placeholder name is ‘input’. right?

@jerryhouuu not a same error

when i execute python3 scripts/convert_plan.py data/frozen_graphs/inception_v3.pb data/plans/inception_v3.plan input 299 299 InceptionV3/Logits/SpatialSqueeze 1 0 float

the error
UffParser: Parser error: InceptionV3/InceptionV3/Conv2d_1a_3x3/BatchNorm/FusedBatchNorm: The input to the Scale Layer is required to have a minimum of 3 dimensions.

could someone give me some help
thanks for your time