Deconvolution

Time:2020-2-2

Specific calculation steps of deconvolution

Make the image as

 

Convolution kernel is

 

 

 

case 1

If you want the output size to be 5×5 and the step number to be stripe = 2, the command in tensorflow is:

transpose_conv = tf.nn.conv2d_transpose(value=input, 
                                        filter=kernel, 
                                        output_shape=[1,5,5,1], 
                                        strides=2, 
                                        padding='SAME')

When you execute the transfer_conv command, tensorflow will first calculate whether the relationship among convolution type, input size, step number and output size is valid. If it is not, it will directly prompt an error. If it is, perform the following operations:

1. Now, the internal part of the input is filled according to the steps of strings. Here, strings can be understood as the multiple of input amplification, that is, the relationship between the number n of 0 and strings is: n = Strings-1

For example, the strings = 2 in the example here, that is, fill in 1 0 between each element of input:

[公式]

2. Next, use convolution kernel to input the filled inputpadCarry out forward convolution with step size of stride = 1, according to the output size formula of forward convolution:[公式]The output size is 5 x 5, and the output size parameter output U shape given in the deconvolution formula is also 5, which is the same, so it can be calculated. The results are as follows:

[公式]

The result is the same as that of tensorflow.

case 2

We change the output size output_shape in case 1 to 6, and the other parameters remain the same. The command in tensorflow is:

transpose_conv = tf.nn.conv2d_transpose(value=input, 
                                        filter=kernel, 
                                        output_shape=[1,6,6,1], 
                                        strides=2, 
                                        padding='SAME')

The convolution type is same, we first fill a circle of 0 in the periphery:

[公式]

At this time, it is found that the input size after filling and the output size after convolution of the convolution kernel of 3 x 3 are 5 x 5, which does not reach 6 x 6 of the output shape, so it needs to continue to fill 0. The calculation rule of tensorflow is to fill a row of 0 on the left and upper side first, and the input after filling becomes:

[公式]

Next, the filled input is convoluted with the convolution kernel of 3 x 3. The result is as follows:

[公式]

The result is the same as that of tensorflow.

 

reference material:

https://zhuanlan.zhihu.com/p/48501100

Recommended Today

[Redis5 source code learning] analysis of the randomkey part of redis command

baiyan Command syntax Command meaning: randomly return a key from the currently selected databaseCommand format: RANDOMKEY Command actual combat: 127.0.0.1:6379> keys * 1) “kkk” 2) “key1” 127.0.0.1:6379> randomkey “key1” 127.0.0.1:6379> randomkey “kkk” Return value: random key; nil if database is empty Source code analysis Main process The processing function corresponding to the keys command is […]