我正在 Keras 中迈出第一步,并为我的图层尺寸而苦苦挣扎。我目前正在构建一个卷积自动编码器,我想使用 MNIST 数据集进行训练。不幸的是,我似乎无法获得正确的尺寸,而且我很难理解我的错误在哪里。
我的模型是通过以下方式构建的:
def build_model(nb_filters=32, nb_pool=2, nb_conv=3):
input_img = Input(shape=(1, 28, 28))
x = Convolution2D(16, 3, 3, activation='relu', border_mode='same')(input_img)
x = MaxPooling2D((2, 2), border_mode='same')(x)
x = Convolution2D(8, 3, 3, activation='relu', border_mode='same')(x)
x = MaxPooling2D((2, 2), border_mode='same')(x)
x = Convolution2D(8, 3, 3, activation='relu', border_mode='same')(x)
encoded = MaxPooling2D((2, 2), border_mode='same')(x)
x = Convolution2D(8, 3, 3, activation='relu', border_mode='same')(encoded)
x = UpSampling2D((2, 2))(x)
x = Convolution2D(8, 3, 3, activation='relu', border_mode='same')(x)
x = UpSampling2D((2, 2))(x)
x = Convolution2D(16, 3, 3, activation='relu', border_mode='same')(x)
x = UpSampling2D((2, 2))(x)
decoded = Convolution2D(1, 3, 3, activation='sigmoid', border_mode='same')(x)
return Model(input_img, decoded)
并使用以下方法检索数据:
def load_data():
(x_train, _), (x_test, _) = mnist.load_data()
x_train = x_train.astype('float32') / 255.
x_test = x_test.astype('float32') / 255.
x_train = np.reshape(x_train, (len(x_train), 1, 28, 28))
x_test = np.reshape(x_test, (len(x_test), 1, 28, 28))
return x_train, x_test
如您所见,我正在尝试对图像进行规范化以以黑白显示它们,并且只是为了训练自动编码器以能够恢复它们。
您可以在下面看到我收到的错误:
Traceback(最近一次调用最后一次):文件“C:/Users//Documents/GitHub/main/research/research_framework/experiment.py”,第 46 行,回调 = [EarlyStopping(patience=3)])文件“C: \Users\AppData\Local\Continuum\Anaconda2\lib\site-packages\keras\engine\training.py”,第 1047 行,适合 batch_size=batch_size) 文件“C:\Users\AppData\Local\Continuum\Anaconda2\ lib\site-packages\keras\engine\training.py",第 978 行,在 _standardize_user_data exception_prefix='model target') 文件“C:\Users\AppData\Local\Continuum\Anaconda2\lib\site-packages\keras\ engine\training.py",第 111 行,在 standardize_input_data str(array.shape)) 异常:检查模型目标时出错:预期的 convolution2d_7 具有形状 (None, 8, 32, 1) 但得到的数组具有形状 (60000L, 1L , 28L,28L) 总参数:8273
进程以退出代码 1 结束
你能帮我解密这个错误吗?除了 Keras 网站之外,是否有任何关于构建模型和处理此类问题的材料?
干杯