A. *_*ski 6 python autoencoder keras
我的目标是构建一个卷积自动编码器,将输入图像编码为大小为 的平面向量(10,1)
。我按照 keras文档中的示例进行操作,并根据我的目的对其进行了修改。不幸的是,模型是这样的:
input_img = Input(shape=(28, 28, 1))
x = Conv2D(16, (3, 3), activation='relu', padding='same')(input_img)
x = MaxPooling2D((2, 2), padding='same')(x)
x = Conv2D(8, (3, 3), activation='relu', padding='same')(x)
x = MaxPooling2D((2, 2), padding='same')(x)
x = Flatten()(x)
encoded = Dense(units = 10, activation = 'relu')(x)
x = Conv2D(8, (3, 3), activation='relu', padding='same')(encoded)
x = UpSampling2D((2, 2))(x)
x = Conv2D(16, (3, 3), activation='relu')(x)
x = UpSampling2D((2, 2))(x)
decoded = Conv2D(1, (3, 3), activation='sigmoid', padding='same')(x)
autoencoder = Model(input_img, decoded)
Run Code Online (Sandbox Code Playgroud)
给我
ValueError: Input 0 is incompatible with layer conv2d_39: expected ndim=4, found ndim=2
Run Code Online (Sandbox Code Playgroud)
我认为我应该在解码器中添加一些层来反转 Flatten 的效果,但不确定是哪一层。你能帮我吗?
为什么你想要向量具有特定的 (10,1) 形状?然后,您尝试使用大小为 3x3 的内核对其进行卷积,这实际上没有意义。
卷积层的形状有高度、宽度和通道。密集层的输出必须被重塑,这可以通过重塑层来完成。然后,您可以将其重塑为例如 5x2 单通道。
encoded = Reshape((5, 2, 1))(encoded)
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2273 次 |
最近记录: |