当我将填充设置为 1 时,ZeroPadding2D 填充两次

ZeroPadding2D pad twices when I set padding to 1

我刚刚开始学习 Tensorflow (2.1.0)、Keras (2.3.7) Python 3.7.7。

我正在尝试使用 VGG16 的编码器-解码器网络。

我需要将层从 (12, 12, ...) 上采样到 (25, 25, ...) 以使 conv7_1 具有与 conv4_3 层相同的形状。带有 'problem' 的图层是 upsp2:

conv4_3 (Conv2D)             (None, 25, 25, 512)       2359808
_________________________________________________________________
pool_4 (MaxPooling2D)        (None, 12, 12, 512)       0
_________________________________________________________________
conv5_1 (Conv2D)             (None, 12, 12, 512)       2359808
_________________________________________________________________
conv5_2 (Conv2D)             (None, 12, 12, 512)       2359808
_________________________________________________________________
conv5_3 (Conv2D)             (None, 12, 12, 512)       2359808
_________________________________________________________________
pool_5 (MaxPooling2D)        (None, 6, 6, 512)         0
_________________________________________________________________
upsp1 (UpSampling2D)         (None, 12, 12, 512)       0
_________________________________________________________________
conv6_1 (Conv2D)             (None, 12, 12, 512)       2359808
_________________________________________________________________
conv6_2 (Conv2D)             (None, 12, 12, 512)       2359808
_________________________________________________________________
conv6_3 (Conv2D)             (None, 12, 12, 512)       2359808
_________________________________________________________________    
upsp2 (UpSampling2D)         (None, 24, 24, 512)       0
_________________________________________________________________
conv7_1 (Conv2D)             (None, 24, 24, 512)       2359808

我试过这个:

#################################
# Decoder
#################################
#conv1 = Conv2DTranspose(512, (2, 2), strides = 2, name = 'conv1')(pool5)

upsp1 = UpSampling2D(size = (2,2), name = 'upsp1')(pool5)
conv6 = Conv2D(512, 3, activation = 'relu', padding = 'same', name = 'conv6_1')(upsp1)
conv6 = Conv2D(512, 3, activation = 'relu', padding = 'same', name = 'conv6_2')(conv6)
conv6 = Conv2D(512, 3, activation = 'relu', padding = 'same', name = 'conv6_3')(conv6)

zero1 = ZeroPadding2D(padding = (1,1), data_format = 'channels_last', name='zero1')(conv6)
upsp2 = UpSampling2D(size = (2,2), name = 'upsp2')(zero1)

但是我得到那个形状 (12, 12, ...)zero1 层进入 (14, 14, ...):

conv6_3 (Conv2D)             (None, 12, 12, 512)       2359808
_________________________________________________________________
zero1 (ZeroPadding2D)        (None, 14, 14, 512)       0
_________________________________________________________________
upsp2 (UpSampling2D)         (None, 28, 28, 512)       0
_________________________________________________________________

如何将 (12,12,512) 上采样到 (25,25,512)

我使用填充作为 2 个整数的 2 个元组的元组来完成它:解释为 ((top_pad, bottom_pad), (left_pad, right_pad) ).并在卷积7层的最后设置ZeroPadding2D

#################################
# Decoder
#################################
#conv1 = Conv2DTranspose(512, (2, 2), strides = 2, name = 'conv1')(pool5)

upsp1 = UpSampling2D(size = (2,2), name = 'upsp1')(pool5)
conv6 = Conv2D(512, 3, activation = 'relu', padding = 'same', name = 'conv6_1')(upsp1)
conv6 = Conv2D(512, 3, activation = 'relu', padding = 'same', name = 'conv6_2')(conv6)
conv6 = Conv2D(512, 3, activation = 'relu', padding = 'same', name = 'conv6_3')(conv6)

upsp2 = UpSampling2D(size = (2,2), name = 'upsp2')(conv6)
conv7 = Conv2D(512, 3, activation = 'relu', padding = 'same', name = 'conv7_1')(upsp2)
conv7 = Conv2D(512, 3, activation = 'relu', padding = 'same', name = 'conv7_2')(conv7)
conv7 = Conv2D(512, 3, activation = 'relu', padding = 'same', name = 'conv7_3')(conv7)
zero1 = ZeroPadding2D(padding =  ((1, 0), (1, 0)), data_format = 'channels_last', name='zero1')(conv7)