DS4.0 TX2: How to add same padding based on yolov3

Hello,
I want to add same padding based on yolov3,

for example:
[maxpool]
stride=1
size=5

The tiny_yolo have same padding ,but the kernel size is 2, I want to add same padding with ketnel 5, I want to follow tiny_yolo to add same padding,but I cna’t sure if it’s correct ,can you tell me how to modify it?

thanks

The stride and size are read directly from the config file and used while creating the maxpool layers. You do not have to change anything. You can have a look at this function in trt_utils.cpp file -

nvinfer1::ILayer* netAddMaxpool(int layerIdx, std::map<std::string, std::string>& block,
                                nvinfer1::ITensor* input, nvinfer1::INetworkDefinition* network)
{
    assert(block.at("type") == "maxpool");
    assert(block.find("size") != block.end());
    assert(block.find("stride") != block.end());

    int size = std::stoi(block.at("size"));
    int stride = std::stoi(block.at("stride"));

    nvinfer1::IPoolingLayer* pool
        = network->addPooling(*input, nvinfer1::PoolingType::kMAX, nvinfer1::DimsHW{size, size});
    assert(pool);
    std::string maxpoolLayerName = "maxpool_" + std::to_string(layerIdx);
    pool->setStride(nvinfer1::DimsHW{stride, stride});
    pool->setName(maxpoolLayerName.c_str());

    return pool;
}

Hi NvCJR,
If I didn’t change anything ,the code will treat it as valid padding when stride set to 1,but I want it as same padding.

for example:
1.[maxpool]
stride=1
size=5

2.input–>12 x 19 x 19

3.output–>12 x 15 x 15 ,expect 12 x 19 x 19,detail please see layer (79)

1.(76)  conv-bn-leaky   864 x  19 x  19      11 x  19 x  19    10909193

2.(77)  conv-bn-leaky    11 x  19 x  19      33 x  19 x  19    10912592

3.(78)  conv-bn-leaky    33 x  19 x  19      12 x  19 x  19    10913036

4.(79)  maxpool          12 x  19 x  19      12 x  15 x  15    10913036

5.(80)  route                  -             12 x  19 x  19    10913036

6.(81)  maxpool          12 x  19 x  19      12 x  11 x  11    10913036

7.(82)  route                  -             12 x  19 x  19    10913036

8.(83)  maxpool          12 x  19 x  19      12 x   7 x   7    10913036

,
I try to update createYoloNetwork function source code as bellow,is it right?
I’m not very clearly for the function of “m_TinyMaxpoolPaddingFormula->addSamePaddingLayer(“maxpool_” + std::to_string(i))”,what’t the function for it?

else if (m_configBlocks.at(i).at("type") == "maxpool")

2.        {

3.            // Add same padding layers

4.            if (m_configBlocks.at(i).at("size") == "2" && m_configBlocks.at(i).at("stride") == "1")

5.            {

6.                m_TinyMaxpoolPaddingFormula->addSamePaddingLayer("maxpool_" + std::to_string(i));

7.            }

8.            if (m_configBlocks.at(i).at("size") == "5" && m_configBlocks.at(i).at("stride") == "1")

9.            {

10.                m_TinyMaxpoolPaddingFormula->addSamePaddingLayer("maxpool_" + std::to_string(i));

11.            }

12.            if (m_configBlocks.at(i).at("size") == "9" && m_configBlocks.at(i).at("stride") == "1")

13.            {

14.                m_TinyMaxpoolPaddingFormula->addSamePaddingLayer("maxpool_" + std::to_string(i));

15.            }

16.            if (m_configBlocks.at(i).at("size") == "13" && m_configBlocks.at(i).at("stride") == "1")

17.            {

18.                m_TinyMaxpoolPaddingFormula->addSamePaddingLayer("maxpool_" + std::to_string(i));

19.            }

20.            std::string inputVol = dimsToString(previous->getDimensions());

21.            nvinfer1::ILayer* out = netAddMaxpool(i, m_configBlocks.at(i), previous, network);

22.            previous = out->getOutput(0);

23.            assert(previous != nullptr);

24.            std::string outputVol = dimsToString(previous->getDimensions());

25.            tensorOutputs.push_back(out->getOutput(0));

26.            printLayerInfo(layerIndex, "maxpool", inputVol, outputVol, std::to_string(weightPtr));

27.        }

thread continued here - https://devtalk.nvidia.com/default/topic/1063207/deepstream-sdk/ds4-0-tx2-precision-detection-decreased-a-lot/