microsoft / CNTK

Microsoft Cognitive Toolkit (CNTK), an open source deep-learning toolkit
https://docs.microsoft.com/cognitive-toolkit/
Other
17.49k stars 4.3k forks source link

Where is the implement of 'Padding' operation in CNTK source code ? #3808

Open shiningrain opened 4 years ago

shiningrain commented 4 years ago

I have encountered some difficulties when I investigating the implementation of MaxPool and AveragePool operation in CNTK the source code: I can see the functions of MaxPoolingForward and AveragePoolingForward near /CNTK-2.7/Source/Math/CPUMatrixImpl.h --- line4713. These two functions complete the pooling operation, but I find that the input of these two functions seems to have been padded, and I have not found the place to pad the input on the relevant execution path. I would like to inquire about how CNTK exactly pads the input data and the approximate position of the padding function in the source code. Waiting for your reply.

delzac commented 4 years ago

I don't write c++ so i can't help you there. But there is something that you need to be aware of for pooling functions.

During calculations, paddings (i.e. the zeros on the edges) do not contribute to the pooling function. Imagine this:

0 - paddings 1 - image

0 0 0 0 1 1 1 0 1 1 1

For a 3x3 ave pooling, at the top-left corner of the image,

ave-pool = (1 + 1 + 1 + 1) / 4 = 1.

NOT (0 + 0 + 0 + 0 + 1 + 1 + 0 + 1 + 1) / 9 = 0.44444.....

Tensorflow, cntk, theano does the former. MxNet does the latter (without option to do the former).

shiningrain commented 4 years ago

I don't write c++ so i can't help you there. But there is something that you need to be aware of for pooling functions.

During calculations, paddings (i.e. the zeros on the edges) do not contribute to the pooling function. Imagine this:

Thank you for your reply! I just want to find out the Pad implement in source code to make sure something. I'm very curious where or what kind of operation CNTK uses to add these padding to the input