For our 32-32-3 image, use the 5-5-3 convolution kernel to slide over the image. The
calculation is as shown in the figure (please make up for the calculation of the multi-channel image by yourself ):
The size calculation formula after convolution is:
Among them: input picture size W×W
Filter size F×F
strides S
padding pixel number P
output size NxN
In actual operation, we will also encounter two ways of padding "SAME" and "VALID", padding = "SAME", "0" will be filled around the image, padding = "VALID" is not needed, that is, P=0. Generally, "SAME" is selected to slow down the speed of the image becoming smaller, and secondly, to prevent the loss of boundary information (that is, the information on the boundary of some images plays less role).
padding = "VALID": (do not fill in 0)
P=0
padding = "SAME": (fill in 0)
- Convolution kernel is odd
When Filter=1x1, P=0; When
Filter=3x3, P=1; When
Filter=05x5, P=2, and so on.
P=(F-1)/2
- When the size of the convolution kernel is an even number: When
Filter=6x6, P1=【6-1/2】round up, P2=【6-1/2】round down;
(Here it becomes subtract P1 and then subtract P2)
ps: When the step size is greater than 1, the formula for calculating N is always rounded down, so that the size of N can be calculated correctly.
The tensorflow official website gives another calculation method, which is also correct: When
padding = "SAME":
N is a W / rear S as the rounding
example:
the input image size W × W = 5x5; Filter size F × F = 3x3; step strides = 2 output size of an NxN,
. 5/2 = 3, then N is equal to 3
same According to the formula at the beginning: N=(5-3+2*1)/2+1=3
When padding = "VALID":
also round up, N=(5-3+1)/2=2
also use the original formula: N=(5-3)/2+1=2