在可变大小的图像上训练keras模型

时间:2018-09-22 16:52:04

标签: keras keras-layer

我尝试建立一个接受灰度图像并输出3通道图像的模型。这是模型:

def get_model():
m_model = Sequential()
m_model.add(InputLayer((None, None)))
m_model.add(Lambda(lambda x: x / 255.0))
m_model.add(Convolution2D(26, (3, 3), activation='relu', padding='same'))
m_model.add(Convolution2D(26, (3, 3), activation='relu', padding='same'))
m_model.add(AvgPool2D((2, 2), padding='same'))
m_model.add(Convolution2D(26, (3, 3), activation='relu', padding='same'))
m_model.add(Convolution2D(26, (3, 3), activation='relu', padding='same'))
m_model.add(AvgPool2D((2, 2), padding='same'))
m_model.add(Convolution2D(26, (3, 3), activation='relu', padding='same'))
m_model.add(Convolution2D(26, (3, 3), activation='relu', padding='same'))
m_model.add(AvgPool2D((2, 2), padding='same'))
m_model.add(GaussianNoise(0.05))
m_model.add(Convolution2D(26, (3, 3), activation='relu', padding='same'))
m_model.add(Convolution2D(26, (3, 3), activation='relu', padding='same'))
m_model.add(Convolution2D(26, (3, 3), activation='relu', padding='same', name='encoder_output'))
m_model.add(UpSampling2D((2, 2)))
m_model.add(Convolution2D(26, (3, 3), activation='relu', padding='same'))
m_model.add(Convolution2D(26, (3, 3), activation='relu', padding='same'))
m_model.add(UpSampling2D((2, 2)))
m_model.add(Convolution2D(26, (3, 3), activation='relu', padding="same"))
m_model.add(Convolution2D(26, (3, 3), activation='relu'))
m_model.add(UpSampling2D((2, 2)))
m_model.add(Convolution2D(3, (3, 3), activation="sigmoid", padding='same'))
m_model.add(Lambda(lambda x: x * 255.0))
m_model.compile(optimizer="adadelta", loss=keras.losses.MSE, metrics=["accuracy"])
return m_model

但是,出现以下错误:

ValueError: The channel dimension of the inputs should be defined. Found `None`.

我尝试了几种方法,但无法解决。我想念什么?

0 个答案:

没有答案