One problem in the approach I think is that it doesn’t modify the dimensions of ITensor* input.
So, I was developing on full defined network and the desired output from maxpool was coming after the stride was applied. Now what I want is that if stride for the layer is 1: then the output size from maxpool should be same.
Right now when the input goes like -
15x15x3 → (2x2,1) → 14x14x3
What is needed (Using padding on one side only)-
15x15x3 → (2x2,1) → 15x15x3
Padding layer + Elementwise layer will not change the output ITensor according to above problem.
Is there any way to access the values of ITensor* so that even while making the new ITensor* the values can be adjusted. If no values are accessible, then what else solution can be thought of ?
The IPaddingLayer supports asymmetric padding. You need something like:
// add zero padding to most right column and bottom row
IPaddingLayer* pad = network->addPadding(*input, DimsHW{0, 0}, DimsHW{1, 1});
ASSERT(pad);
Weights const_weights;
// code to fill const_weights with zeros and to put -FM values at the padding areas
// make sure the tensor dimensions match the dimensions of the output tensor of the 'pad' layer
// ...
IConstantLayer* constant = network->addConstant(pad->getOutput(0)->getDimensions(), const_weights);
ASSERT(constant);
IElementWiseLayer* add = network->addElementWise(*constant->getOutput(0), *pad->getOutput(0), ElementWiseOperation::kSUM);
ASSERT(add);
This will add zero padding to the end of the two most inner dimensions (what TRT calls post padding) of the input tensor, then it will sum the zero padded tensor with a constant tensor filled with zeros and -FM values on the padding areas.