Unable to configure ISlice Layer for padding

Description

Unable to use ISlice layer for padding a tensor

I am trying to use the ISlice Layer with Tensorrt v8.2.1, since IPaddingLayer is going to be deprecated. I am trying to convert a tensor of shape 1,3,10,10(N,C,H,W) to 1,3,14,14(N,C,H,W) with padding done to top, bottom ,left and right of the tensor. I am trying to use the below code snippet but unsuccesful

ISliceLayer* slice = network->addSlice(*InputLayerITensor,
Dims4{0,0,0,0},
Dims4{1,3,14,14},
Dims4{1,1,-2,-2});
I see error

Error occured when invoking TensorRT API

4: (Unnamed Layer* 0) [Slice]: out of bounds slice, input dimensions = [1,3,10,10], start = [0,0,0,0], size = [1,3,14,14], stride = [1,1,-2,-2].

Error occured when invoking TensorRT API

4: [network.cpp::validate::2871] Error Code 4: Internal Error (Layer (Unnamed Layer* 0) [Slice] failed validation)

Any help in usage of this API for my requirements is highly appreciated.

Environment

TensorRT Version: Tensorrt v 8.2.1
GPU Type: Titan xp
Nvidia Driver Version: cuda 11.2
CUDA Version: cuda 11.2
CUDNN Version: 8.2.1
Operating System + Version: Linux
Python Version (if applicable):
TensorFlow Version (if applicable):
PyTorch Version (if applicable):
Baremetal or Container (if container which image + tag):

Relevant Files

Steps To Reproduce

Build Makefile using the executable. attached in the zip and run the exe.

Please include:
Build Makefile using the executable. attached in the zip and run the exe.

Hi,
Please check the below link, as they might answer your concerns

Thanks!

Hi,

Thanks for pointing me to the documentation.
By going through API documentation for addPadding I came to know that it will be removed and I need to use addSlice.

I found the below example in API documentation(TensorRT: nvinfer1::ISliceLayer Class Reference), it is not clear and does not mention how to use it for padding.

For example using slice on a tensor: input = {{0, 2, 4}, {1, 3, 5}} start = {1, 0} size = {1, 2} stride = {1, 2} output = {{1, 5}}

When the sliceMode is kCLAMP or kREFLECT, for each input dimension, if its size is 0 then the corresponding output dimension must be 0 too.

A slice layer can produce a shape tensor if the following conditions are met:

** start, size, and stride are build time constants, either as static Dims, or computable by constant folding.*
** The number of elements in the output tensor does not exceed 2Dims::MAX_DIMS.

The input tensor is a shape tensor if the output is a shape tensor.

It will be very helpful for us, if there are shipped examples on how to use each layer for specific purposes.

Thanks,
Praveen.

Hi,

We support onnx pad using iSliceLayer in parser as following.

Thank you.