首页 > 解决方案 > 在 Keras Python 中调整输出层的大小

问题描述

我的目标是将输出图像的大小从[32,32,1]调整为[8,8,1]

我尝试使用 reshape 进行此操作,但出现错误:

Output_model = Reshape((8,8,-1))(out_1)
Error when checking target: expected reshape_1 to have shape (8, 8, 32) but got array with shape (32, 32, 1)

我怎么解决这个问题??

非常感谢

标签: pythonkerasresizereshape

解决方案


您不能直接重塑数组,因为 32*32*1 不等于 8*8*1,因此您必须进行子采样:

import keras
x=keras.layers.Input((32,32,1))
x=keras.layers.MaxPooling2D((4,4))(x)

然后您的图像将下采样到(8,8,1)。


推荐阅读