About tf.reshape() with TRT

When parsing a .uff file from tensorflow model , one issue confused me , about tf.reshape():
When I reshaped 2 tensors form (1,2,4,6) to (1,2,24), and add them, trt built the engine successfully

output_node_names = [“input”, “add”]
input = tf.placeholder(shape=[1,2,4,6],dtype=tf.float32, name=‘input’)
bias=tf.constant(value=1.0,shape=[1,2,4,6],dtype=tf.float32,name=‘bias’)
input=tf.reshape(input,shape=[1,2,24])
bias=tf.reshape(bias,shape=[1,2,24])

node name:add

output=input+bias

But reshaped from (1,2,4,6) to (1,2,4,3,2), it failed: Parameter check failed at: Network.cpp::addScale::175, condition: shift.count == 0 || shift.count == weightCount

output_node_names = [“input”, “add”]
input = tf.placeholder(shape=[1,2,4,6],dtype=tf.float32, name=‘input’)
bias=tf.constant(value=1.0,shape=[1,2,4,6],dtype=tf.float32,name=‘bias’)
input=tf.reshape(input,shape=[1,2,4,3,2])
bias=tf.reshape(bias,shape=[1,2,4,3,2])

node name:add

output=input+bias

It seemed not supported to add two tensors reshaped from less dimensions?

win10
trt 5.1.5.0
cuda 10.0
cudnn 7.3.1

  • I have met the similar situation, but I have found that it is not because of the tf.reshape().

    The error you got is because of the output = input + bias operation, means that the tf.add leads to the error.I have tried and found that trt doesn’t not support the add operation if input and bias are above 5 dimension. It only support add operation if they are 4 dimension or less.

    You can solve your problem by doing the add operation before tf.reshape, and the result will be the same.