【发布时间】:2018-07-10 21:06:20
【问题描述】:
我正在尝试使用 Keras 中的自动编码器,使用 Indian Pines 数据集对高光谱图像进行无监督分类。我在这里开始了一个项目https://github.com/KonstantinosF/Classification-of-Hyperspectral-Image 并修改了TrainTheModel.ipynb 中的部分,将 "Train the model" 部分(以及以下两个代码块)替换为以下代码,这只是自编码器的编码端:
input_img = Input(shape=input_shape) # input_shape is (30, 5, 5)
x = Conv2D(16, (3, 3), activation='relu', padding='same')(input_img) # x1
x = MaxPooling2D((2, 2), padding='same')(x) # x2
x = Conv2D(8, (3, 3), activation='relu', padding='same')(x) # x3
x = MaxPooling2D((2, 2), padding='same')(x) # x4
x = Conv2D(8, (3, 3), activation='relu', padding='same')(x) #x5
encoded = MaxPooling2D((2, 2), padding='same')(x)
model = Model(input_img, encoded)
model.compile(optimizer='adadelta', loss='binary_crossentropy')
model.fit(X_train, y_train, batch_size=32, epochs=15)
我改编自 https://blog.keras.io/building-autoencoders-in-keras.html 的 “卷积自动编码器” 部分。当我尝试运行命令时:
model.fit(X_train, y_train, batch_size=32, epochs=15)
命令,我收到错误消息:
ValueError: Error when checking target: expected max_pooling2d_25 to have 4 dimensions, but got array with shape (29685, 16)
由于我是 CNN 的新手,我不确定为什么我的尺寸不正确。如果我在这里打印出每个步骤的形状,我会得到:
(?, 16, 5, 5) # x1
(?, 16, 3, 3) # x2
(?, 8, 3, 3) # x3
(?, 8, 2, 2) # x4
(?, 8, 2, 2) # x5
(?, 8, 1, 1) # encoded
有什么想法吗?
【问题讨论】:
标签: keras conv-neural-network autoencoder unsupervised-learning