Search code examples
tensorflowtensorrt

Upsampling Tensor for TensorRT


The tensorflow model is converted to TensorRT and Tensorflow's ResizeArea(upsample in the picture) need to implement plugin. enter image description here

So ResizeArea is implemented in CUDA. My TensorRT input is NCHW format.

uff_path = model_to_uff(model_path)
parser.register_input(ModelData.INPUT_NAME, (3, height, width), trt.UffInputOrder.NCHW)
parser.register_output(ModelData.OUTPUT_NAME)
parser.parse(uff_path, network)

So my CUDA code is implemented NCHW resampling. I like to make sure my resampling format is correct.

Method_1

NCHW resizearea(4 times upsampling) sample.

channel_1      channel_2        channel_3
3,1,2,0,       0,4,3,1,         2,0,2,3,
3,0,1,2,       0,1,2,1,         2,0,4,2,
4,1,2,2,       1,3,2,4,         2,3,4,2,

channel_1                         channel_2                         channel_3  
3,3,3,3,1,1,1,1,2,2,2,2,0,0,0,0,  0,0,0,0,4,4,4,4,3,3,3,3,1,1,1,1,  2,2,2,2,0,0,0,0,2,2,2,2,3,3,3,3,
3,3,3,3,1,1,1,1,2,2,2,2,0,0,0,0,  0,0,0,0,4,4,4,4,3,3,3,3,1,1,1,1,  2,2,2,2,0,0,0,0,2,2,2,2,3,3,3,3,
3,3,3,3,1,1,1,1,2,2,2,2,0,0,0,0,  0,0,0,0,4,4,4,4,3,3,3,3,1,1,1,1,  2,2,2,2,0,0,0,0,2,2,2,2,3,3,3,3,
3,3,3,3,1,1,1,1,2,2,2,2,0,0,0,0,  0,0,0,0,4,4,4,4,3,3,3,3,1,1,1,1,  2,2,2,2,0,0,0,0,2,2,2,2,3,3,3,3,
3,3,3,3,0,0,0,0,1,1,1,1,2,2,2,2,  0,0,0,0,1,1,1,1,2,2,2,2,1,1,1,1,  2,2,2,2,0,0,0,0,4,4,4,4,2,2,2,2,
3,3,3,3,0,0,0,0,1,1,1,1,2,2,2,2,  0,0,0,0,1,1,1,1,2,2,2,2,1,1,1,1,  2,2,2,2,0,0,0,0,4,4,4,4,2,2,2,2,
3,3,3,3,0,0,0,0,1,1,1,1,2,2,2,2,  0,0,0,0,1,1,1,1,2,2,2,2,1,1,1,1,  2,2,2,2,0,0,0,0,4,4,4,4,2,2,2,2,
3,3,3,3,0,0,0,0,1,1,1,1,2,2,2,2,  0,0,0,0,1,1,1,1,2,2,2,2,1,1,1,1,  2,2,2,2,0,0,0,0,4,4,4,4,2,2,2,2,
4,4,4,4,1,1,1,1,2,2,2,2,2,2,2,2,  1,1,1,1,3,3,3,3,2,2,2,2,4,4,4,4,  2,2,2,2,3,3,3,3,4,4,4,4,2,2,2,2,
4,4,4,4,1,1,1,1,2,2,2,2,2,2,2,2,  1,1,1,1,3,3,3,3,2,2,2,2,4,4,4,4,  2,2,2,2,3,3,3,3,4,4,4,4,2,2,2,2,
4,4,4,4,1,1,1,1,2,2,2,2,2,2,2,2,  1,1,1,1,3,3,3,3,2,2,2,2,4,4,4,4,  2,2,2,2,3,3,3,3,4,4,4,4,2,2,2,2,
4,4,4,4,1,1,1,1,2,2,2,2,2,2,2,2,  1,1,1,1,3,3,3,3,2,2,2,2,4,4,4,4,  2,2,2,2,3,3,3,3,4,4,4,4,2,2,2,2,

Each pixel is 4 times upsampled(for example, first pixel 3 is upsample 4 times horizontally and vertically). That is considered as NCHW format upsampling.

Method_2

Another way implemented is considered upsampling in NHWC format. enter image description here

enter image description here

3-channel data (83,86,77) is upsampled horizontally and vertically.

Is Method_1 is correct way of NCHW upsampling?


Solution

  • After taking some time. The issue was solved. TensorRT works in NCHW format. Tensorflow model is in NHWC format. So in my plugin, need to work upsampling in NCHW format but output needs to change as NHWC format so that it can interface to next Tensorflow operations.