How to read the output tensor data of a previous layer channel by channel?


I want to implement torch.nn.InstanceNorm2d() with TensorRT API, but don’t know to read out the data of the output tensor of a previous layer in network channel by channel.


TensorRT Version: 7.1.3
GPU Type: Nano
Nvidia Driver Version:
CUDA Version: 10.2
CUDNN Version: 8.0.3
Operating System + Version: Ubuntu18.04
PyTorch Version: 1.8

As you know, TensorRT doesn’t provide any normalization API, but our network does have torch.nn.InstanceNorm2d layer and torch.nn.BatchNorm2d() used, it is easy to implement BatchNorm2d as I can normalize the whole tensor data output by a previous layer (not the final output layer of network) basing on ScaleLayer, but don’t know how to implement InstanceNorm2d, as this normalization should apply to each channel, I don’t know how to read the data channel by channel from the output tensor of a middle layer in a network, it looks like there is not any TensorRT API by which we can read data from an tensor output by a middle layer, not to speak of reading tensor data channel by channel. thanks.

Hi @akachen,

TensorRT has an instance norm plugin. It’s automatically used by the ONNX parser. For your reference,

Thank you.