0

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

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

我需要对图层进行上采样(12, 12, ...),以(25, 25, ...)使其conv7_1具有与图层相同的形状conv4_3。有“问题”的层是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, ...)进入(14, 14, ...)zero1

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)

4

1 回答 1

0

我使用填充作为 2 个整数的 2 个元组的元组来做到这一点:解释为((top_pad,bottom_pad),(left_pad,right_pad))。并ZeroPadding2D在卷积 7 层结束时设置:

#################################
# 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)
于 2020-06-01T10:26:59.853 回答