Hi, all. I am working on a project converting a keras based yolov3 model into tensorrt format using python api.
As it is already known that the uff parser does not support tensorflow’s operation ResizeNearestNeighbor, so i tried to re-implement the upsampling by conv2d_transpose operation with plain kernel manually.
i wrote the following testing code to get familiar with tensorrt:
x = tf.placeholder(shape=(None, 13, 13, 256), dtype=tf.float32)
# assuming input tensor in NHWC format
# upsample by height/weight factor of 2
output_shape = tf.shape(x)*tf.constant([1,2,2,0], dtype=tf.int32) + tf.constant([0,0,0,1], dtype=tf.int32)
channels = x.get_shape().as_list()[3]
strides = [1, 2, 2, 1]
kernel = tf.constant(np.ones(shape=(4, )), shape=[2,2,1,1], dtype=tf.float32)
sliced_ten_li = [x[:, :, :, i:i+1] for i in range(channels)]
deconv_ten_li = [tf.nn.conv2d_transpose(in_tensor, kernel, output_shape, strides, padding="VALID") for in_tensor in sliced_ten_li]
y = tf.concat(deconv_ten_li, axis=3)
frozen_graph = convert_variables_to_constants(sess, sess.graph.as_graph_def(), [y.op.name])
#...write pb file, convert to uff....
parser = trt.UffParser()
parser.register_input('Placeholder', (13, 13, 256), order=trt.UffInputOrder.NHWC)
parser.register_output('concat')
It works perfectly in tensorrt inference engine.
However, after i replaced the placeholder tensor with the input tensor of upsampling as follows:
up_sample_out = sess.graph.get_tensor_by_name('import/up_sampling2d_1/ResizeNearestNeighbor:0')
up_sample_in = up_sample_out.op.inputs[0] # 2nd input for resize factor, here ignored
x = up_sample_in
# ...some lines as same as above one...
parser = trt.UffParser()
parser.register_input('import/input_1', (416, 416, 3), order=trt.UffInputOrder.NHWC)
parser.register_output('concat')
the parser yields multiple errors as
...
strided_slice_133: slice is out of input range
conv2d_tranpose_133: at least three non-batch dimensions are required for input
...
it seems like this is something related to input dimension
however, i’m pretty sure that the up_sample_in tensor has the same dimension with the input tensor of the first one.
Any suggestions?