【发布时间】:2020-05-23 01:29:18
【问题描述】:
我写了一个包含三个卷积层的 ResNet 块:
def res_net_block(input_data, filters, kernel_size):
kernel_middle = kernel_size + 2
filters_last_layer = filters * 2
x = Conv2D(filters, kernel_size, activation = 'relu', padding = 'same')(input_data) #64, 1x1
x = BatchNormalization()(x)
x = Conv2D(filters, kernel_middle, activation = 'relu', padding = 'same')(x) #64, 3x3
x = BatchNormalization()(x)
x = Conv2D(filters_last_layer, kernel_size, activation = None, padding = 'same')(x) #128, 1x1
x = BatchNormalization()(x)
x = Add()([x, input_data])
x = Activation('relu')(x)
return x
当我将它添加到我的模型时,我收到此错误:ValueError: Operands could not be broadcast together with shapes (54, 54, 128) (54, 54, 64)
到目前为止,这是我的模型:
inputs = Input(shape = (224, 224, 3))
model = Conv2D(filters = 64, kernel_size = 7, strides = 2, activation = 'relu')(inputs)
model = BatchNormalization()(model)
model = MaxPool2D(pool_size = 3, strides = 2)(model)
for i in range(num_res_net_blocks):
model = res_net_block(model, 64, 1)
我相信问题出在 ResNet 块中的这一行:
x = Add()([x, input_data])
输入数据的维度与 x 不同。但我不知道如何解决这个问题。 我真的很感谢这里的一些帮助。
【问题讨论】:
标签: neural-network conv-neural-network tensorflow2.0 tf.keras resnet