In Keras
, what are the layers(functions) corresponding to tf.nn.conv2d_transpose
in Tensorflow
? I once saw the comment that we can Just use combinations of UpSampling2D and Convolution2D as appropriate
. Is that right?
In the following two examples, they all use this kind of combination.
1) In Building Autoencoders in Keras , author builds decoder as follows.
2) In an u-uet implementation , author builds deconvolution as follows
up6 = merge([UpSampling2D(size=(2, 2))(conv5), conv4], mode='concat', concat_axis=1)
conv6 = Convolution2D(256, 3, 3, activation='relu', border_mode='same')(up6)
conv6 = Convolution2D(256, 3, 3, activation='relu', border_mode='same')(conv6)
The corresponding layers in Keras
are Deconvolution2D layers.
It's worth to mention that you should be really careful with them because they sometimes might behave in unexpected way. I strongly advise you to read this Stack Overflow question (and its answer) before you start to use this layer.
UPDATE:
Convolution2D * UpSampling2D
. Convolution2D
and UpSampling2D
- so maybe this is the reason why it was mentioned in texts you provided. UPDATE 2:
Ok. I think I found an easy explaination why Deconvolution2D
might be presented in a form of a composition of Convolution2D
and UpSampling2D
. We would use a definition that Deconvolution2D
is a gradient of some convolution layer. Let's consider three most common cases:
Convolutional2D
without any pooling. In this case - as it's the linear operation - its gradient is a function itself - so Convolution2D
. Convolution2D
with AveragePooling
. So: (AveragePooling2D * Convolution2D)' = AveragePooling2D' * Convolution2D'
. But a gradient of AveragePooling2D = UpSample2D * constant
- so it's also in this case when the preposition is true. MaxPooling2D
. In this case still (MaxPooling2D * Convolution2D)' = MaxPooling2D' * Convolution2D'
But MaxPooling2D' != UpSample2D
. But in this case one can easily find an easy Convolution2D
which makes MaxPooling2D' = Convolution2D * UpSample2D
(intuitively - a gradient of MaxPooling2D
is a zero matrix with only one 1 on its diagonal. As Convolution2D
might express a matrix operation - it may also represent the injection from a identity matrix to a MaxPooling2D
gradient). So: (MaxPooling2D * Convolution2D)' = UpSampling2D * Convolution2D * Convolution2D = UpSampling2D * Convolution2D'
. The final remark is that all parts of the proof have shown that Deconvolution2D
is a composition of UpSampling2D
and Convolution2D
instead of opposite. One can easily proof that every function of a form a composition of UpSampling2D
and Convolution2D
might be easily presented in a form of a composition of UpSampling2D
and Convolution2D
. So basically - the proof is done :)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.