Hello, I am testing some tensorflow rnn code to be used with TensorRT, but it doesn’t seem to work.
import random
import tensorflow as tf
import numpy as np
with tf.name_scope("Operation"):
batch_size = 10
rnn_cell = tf.nn.rnn_cell.BasicRNNCell(1)
initial_state = rnn_cell.zero_state(batch_size, dtype=tf.float32)
inputs = [tf.placeholder(tf.float32, shape=[batch_size, 1])]
outputs, state = tf.nn.static_rnn(rnn_cell, inputs,
initial_state=initial_state,
dtype=tf.float32)
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
tf.train.write_graph(sess.graph, "", "output.pb", as_text=False)
for i in range(1000):
feed_dict = {inputs[0]: np.repeat([[1]], 10, axis=0)}
sess.run([outputs, state], feed_dict=feed_dict)
print("Done")
So this is my sample code, and I used convert-to-uff to convert output.pb to output.uff, but it generates following error.
Traceback (most recent call last):
File "/home/skyser2003/.local/bin/convert-to-uff", line 11, in <module>
sys.exit(main())
File "/home/skyser2003/.local/lib/python3.4/site-packages/uff/bin/convert_to_uff.py", line 79, in main
output_filename=args.output
File "/home/skyser2003/.local/lib/python3.4/site-packages/uff/converters/tensorflow/conversion_helpers.py", line 159, in from_tensorflow_frozen_model
return from_tensorflow(graphdef, output_nodes, preprocessor, **kwargs)
File "/home/skyser2003/.local/lib/python3.4/site-packages/uff/converters/tensorflow/conversion_helpers.py", line 132, in from_tensorflow
name="main")
File "/home/skyser2003/.local/lib/python3.4/site-packages/uff/converters/tensorflow/converter.py", line 77, in convert_tf2uff_graph
uff_graph, input_replacements)
File "/home/skyser2003/.local/lib/python3.4/site-packages/uff/converters/tensorflow/converter.py", line 64, in convert_tf2uff_node
op, name, tf_node, inputs, uff_graph, tf_nodes=tf_nodes)
File "/home/skyser2003/.local/lib/python3.4/site-packages/uff/converters/tensorflow/converter.py", line 43, in convert_layer
return cls.registry_[op](name, tf_node, inputs, uff_graph, **kwargs)
File "/home/skyser2003/.local/lib/python3.4/site-packages/uff/converters/tensorflow/converter_functions.py", line 375, in convert_bias_add
kwargs["tf_nodes"][biases_name])
File "/home/skyser2003/.local/lib/python3.4/site-packages/uff/converters/tensorflow/converter.py", line 136, in convert_tf2numpy_const_node
return array.reshape(shape)
ValueError: cannot reshape array of size 0 into shape ()
I looked into convert_bias_add method, and it seemed that bias tensor used in BasicRNNCell is basically empty, so that’s why it gives out array of size 0 error. And this means that TensorRT does not support BasicRNNCell, contrary to what is written in official document.
So my questions are
- tf.nn.static_rnn is currently supported, but am I doing something wrong?
- If it isn’t supported, is there any plan to support it in near future?
Tested with both TensorRT4 and TensorRT5 RC version.
Thanks.