我试图为灰度图像做一个模型。它看起来像是有一个问题的输出形状,我试图添加一个填充到conv2d,把它给我一个输入形状的错误在测试中。the model
实施:
model=keras.Sequential()
model.add(Conv2D(64, kernel_size=(48, 48), activation='relu', input_shape=(105,105,1)))
model.add(BatchNormalization())
model.add(MaxPooling2D(pool_size=(2, 2), padding='same'))
model.add(Conv2D(128, kernel_size=(24, 24), activation='relu'))
model.add(BatchNormalization())
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Conv2DTranspose(128, (24,24), strides = (2,2), activation = 'relu', padding='same', kernel_initializer='uniform'))
model.add(UpSampling2D(size=(2, 2)))
model.add(Conv2DTranspose(64, (12,12), strides = (2,2), activation = 'relu', padding='same', kernel_initializer='uniform'))
model.add(UpSampling2D(size=(2, 2)))
model.add(Conv2D(256, kernel_size=(12, 12), activation='relu'))
model.add(Conv2D(256, kernel_size=(12, 12), activation='relu'))
model.add(Conv2D(256, kernel_size=(12, 12), activation='relu'))
model.add(Flatten())
model.add(Dense(4096, activation='relu'))
model.add(Dropout(0.5))
model.add(
Dense(4096,activation='relu'))
model.add(Dropout(0.5))
model.add(Dense(2383,activation='relu'))
model.add(Dense(5, activation='softmax'))
错误:
ValueError: One of the dimensions in the output is <= 0 due to downsampling in conv2d_9. Consider increasing the input size. Received input shape [None, 105, 105, 1] which would produce output shape with a zero or negative value in a dimension.
2条答案
按热度按时间lnvxswe21#
我认为错误是从(1,105,105)中减去(48,48)的内核大小。尝试使用data_format将输入从(105,105,1)更改为(1,105,105):
model.add(Conv2D(64, kernel_size=(48, 48), activation='relu', input_shape=(105,105,1), data_format='channels_first')))
您可以在此处阅读相关信息:“conv2d_2/convolution”的1减去3导致的负维度大小
zte4gxcn2#
有点晚了,但是如果你使用padding = 'same',它应该也能工作:
这基本上使输出大小与输入大小保持相同。