This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

AM5749: TIDL - How to use SAME padding in convolution with non-square kernels?

Part Number: AM5749

Hi,

I'm trying to quantize a model from caffe to TIDL using the tools from the TI Processor SDK.

I have the following convolution:

layer {
name: "conv1"
type: "Convolution"
bottom: "data/bias"
top: "conv1"
param {
lr_mult: 1.0
decay_mult: 1.0
}
param {
lr_mult: 2.0
decay_mult: 0.0
}
convolution_param {
num_output: 3
bias_term: true
group: 1
weight_filler {
type: "msra"
}
bias_filler {
type: "constant"
value: 0.0
}
pad_h: 3
pad_w: 0
kernel_h: 7
kernel_w: 1
stride_h: 1
stride_w: 1
dilation: 1
}
}

Basically I'm trying to apply a convolution with kernel 7x1 and SAME padding 3x0 so that the output shape is the same as the input (1x3x32x32)

During training on the host, the model behaves correctly, but when I try to optimize it with tidl_model_import.out it looks like the padding fall backs to 0x0 leading to an output shape of 1x3x26x32

Here's the output of tidl_model_import.out

Caffe Network File : models/cj/deploy.prototxt
Caffe Model File : models/cj/snapshot.caffemodel
TIDL Network File : models/cj/tidl_net.bin
TIDL Model File : models/cj/tidl_params.bin
Name of the Network : graph_deploy
Num Inputs : 1
Num of Layer Detected : 5
0, TIDL_DataLayer , data 0, -1 , 1 , x , x , x , x , x , x , x , x , 0 , 0 , 0 , 0 , 0 , 1 , 3 , 32 , 32 , 0 ,
1, TIDL_BatchNormLayer , data/bias 1, 1 , 1 , 0 , x , x , x , x , x , x , x , 1 , 1 , 3 , 32 , 32 , 1 , 3 , 32 , 32 , 3072 ,
2, TIDL_ConvolutionLayer , conv1 1, 1 , 1 , 1 , x , x , x , x , x , x , x , 2 , 1 , 3 , 32 , 32 , 1 , 3 , 26 , 32 , 52416 ,
3, TIDL_FlattenLayer , flatten1 1, 1 , 1 , 2 , x , x , x , x , x , x , x , 3 , 1 , 3 , 26 , 32 , 1 , 1 , 1 , 2496 , 1 ,
4, TIDL_InnerProductLayer , fc10 1, 1 , 1 , 3 , x , x , x , x , x , x , x , 4 , 1 , 1 , 1 , 2496 , 1 , 1 , 1 , 10 , 24960 ,
Total Giga Macs : 0.0001

Processing config file ./tempDir/qunat_stats_config.txt !
0, TIDL_DataLayer , 0, -1 , 1 , x , x , x , x , x , x , x , x , 0 , 0 , 0 , 0 , 0 , 1 , 3 , 32 , 32 ,
1, TIDL_BatchNormLayer , 1, 1 , 1 , 0 , x , x , x , x , x , x , x , 1 , 1 , 3 , 32 , 32 , 1 , 3 , 32 , 32 ,
2, TIDL_ConvolutionLayer , 1, 1 , 1 , 1 , x , x , x , x , x , x , x , 2 , 1 , 3 , 32 , 32 , 1 , 3 , 26 , 32 ,
3, TIDL_FlattenLayer , 1, 1 , 1 , 2 , x , x , x , x , x , x , x , 3 , 1 , 3 , 26 , 32 , 1 , 1 , 1 , 2496 ,
4, TIDL_InnerProductLayer , 1, 1 , 1 , 3 , x , x , x , x , x , x , x , 4 , 1 , 1 , 1 , 2496 , 1 , 1 , 1 , 10 ,
5, TIDL_DataLayer , 0, 1 , -1 , 4 , x , x , x , x , x , x , x , 0 , 1 , 1 , 1 , 10 , 0 , 0 , 0 , 0 ,
Layer ID ,inBlkWidth ,inBlkHeight ,inBlkPitch ,outBlkWidth ,outBlkHeight,outBlkPitch ,numInChs ,numOutChs ,numProcInChs,numLclInChs ,numLclOutChs,numProcItrs ,numAccItrs ,numHorBlock ,numVerBlock ,inBlkChPitch,outBlkChPitc,alignOrNot
2 32 32 32 32 26 32 3 3 3 1 3 1 3 1 1 1024 832 1

Processing Frame Number : 0

Image reading is Not Supported. OpenCV not Enabled
Layer 1 : Out Q : 1 , TIDL_BatchNormLayer , PASSED #MMACs = 0.00, 0.00, Sparsity : 0.00
Layer 2 : Out Q : 1 , TIDL_ConvolutionLayer, PASSED #MMACs = 0.05, 0.06, Sparsity : -14.29
Layer 3 :TIDL_FlattenLayer, PASSED #MMACs = 0.00, 0.00, Sparsity : 0.00
Layer 4 : Out Q : 1 , TIDL_InnerProductLayer, PASSED #MMACs = 0.00, 0.00, Sparsity : 0.00
End of config list found !

Process finished with exit code 0

--------------------------------------------------

If I instead use a square kernel 7x7, with square padding 3x3, I get the expected output shape 1x3x32x32:

deploy.prototxt:

layer {
name: "conv1"
type: "Convolution"
bottom: "data/bias"
top: "conv1"
param {
lr_mult: 1.0
decay_mult: 1.0
}
param {
lr_mult: 2.0
decay_mult: 0.0
}
convolution_param {
num_output: 3
bias_term: true
pad: 3
kernel_size: 7
group: 1
stride: 1
weight_filler {
type: "msra"
}
bias_filler {
type: "constant"
value: 0.0
}
dilation: 1
}
}

Output of tidl_model_import.out:

Caffe Network File : models/cj/deploy.prototxt
Caffe Model File : models/cj/snapshot.caffemodel
TIDL Network File : models/cj/tidl_net.bin
TIDL Model File : models/cj/tidl_params.bin
Name of the Network : graph_deploy
Num Inputs : 1
Num of Layer Detected : 5
0, TIDL_DataLayer , data 0, -1 , 1 , x , x , x , x , x , x , x , x , 0 , 0 , 0 , 0 , 0 , 1 , 3 , 32 , 32 , 0 ,
1, TIDL_BatchNormLayer , data/bias 1, 1 , 1 , 0 , x , x , x , x , x , x , x , 1 , 1 , 3 , 32 , 32 , 1 , 3 , 32 , 32 , 3072 ,
2, TIDL_ConvolutionLayer , conv1 1, 1 , 1 , 1 , x , x , x , x , x , x , x , 2 , 1 , 3 , 32 , 32 , 1 , 3 , 32 , 32 , 451584 ,
3, TIDL_FlattenLayer , flatten1 1, 1 , 1 , 2 , x , x , x , x , x , x , x , 3 , 1 , 3 , 32 , 32 , 1 , 1 , 1 , 3072 , 1 ,
4, TIDL_InnerProductLayer , fc10 1, 1 , 1 , 3 , x , x , x , x , x , x , x , 4 , 1 , 1 , 1 , 3072 , 1 , 1 , 1 , 10 , 30720 ,
Total Giga Macs : 0.0005

Processing config file ./tempDir/qunat_stats_config.txt !
0, TIDL_DataLayer , 0, -1 , 1 , x , x , x , x , x , x , x , x , 0 , 0 , 0 , 0 , 0 , 1 , 3 , 32 , 32 ,
1, TIDL_BatchNormLayer , 1, 1 , 1 , 0 , x , x , x , x , x , x , x , 1 , 1 , 3 , 32 , 32 , 1 , 3 , 32 , 32 ,
2, TIDL_ConvolutionLayer , 1, 1 , 1 , 1 , x , x , x , x , x , x , x , 2 , 1 , 3 , 32 , 32 , 1 , 3 , 32 , 32 ,
3, TIDL_FlattenLayer , 1, 1 , 1 , 2 , x , x , x , x , x , x , x , 3 , 1 , 3 , 32 , 32 , 1 , 1 , 1 , 3072 ,
4, TIDL_InnerProductLayer , 1, 1 , 1 , 3 , x , x , x , x , x , x , x , 4 , 1 , 1 , 1 , 3072 , 1 , 1 , 1 , 10 ,
5, TIDL_DataLayer , 0, 1 , -1 , 4 , x , x , x , x , x , x , x , 0 , 1 , 1 , 1 , 10 , 0 , 0 , 0 , 0 ,
Layer ID ,inBlkWidth ,inBlkHeight ,inBlkPitch ,outBlkWidth ,outBlkHeight,outBlkPitch ,numInChs ,numOutChs ,numProcInChs,numLclInChs ,numLclOutChs,numProcItrs ,numAccItrs ,numHorBlock ,numVerBlock ,inBlkChPitch,outBlkChPitc,alignOrNot
2 40 38 40 32 32 32 3 3 3 1 3 1 3 1 1 1520 1024 1

Processing Frame Number : 0

Image reading is Not Supported. OpenCV not Enabled
Layer 1 : Out Q : 1 , TIDL_BatchNormLayer , PASSED #MMACs = 0.00, 0.00, Sparsity : 0.00
Layer 2 : Out Q : 1 , TIDL_ConvolutionLayer, PASSED #MMACs = 0.45, 0.48, Sparsity : -6.12
Layer 3 :TIDL_FlattenLayer, PASSED #MMACs = 0.00, 0.00, Sparsity : 0.00
Layer 4 : Out Q : 1 , TIDL_InnerProductLayer, PASSED #MMACs = 0.00, 0.00, Sparsity : 0.00
End of config list found !

Process finished with exit code 0

What should I do to make this work?

Thanks in advance.

Gabriele