首页 > 解决方案 > 重塑层存在但不重塑

问题描述

嗨,同时添加一个简单而琐碎的Keras Reshape层来从卷积重塑我的图像

    decoder = BatchNormalization()(decoder)
    decoder = Reshape((224 * 512, n_classes), input_shape=(224, 512, 3))(decoder)

    predictions = Activation('softmax')(decoder)

运行时出现此错误

ValueError: Error when checking target: expected activation_13 to have 3 dimensions, but got array with shape (8, 224, 512, 3)

奇怪的是它出现在图中:

batch_normalization_13 (Batc (None, 224, 512, 3)       12
_________________________________________________________________
reshape_1 (Reshape)          (None, 114688, 3)         0
_________________________________________________________________
activation_13 (Activation)   (None, 114688, 3)         0
______________________________________________________________

标签: pythontensorflowkeras

解决方案


这是预期的行为,错误与批量大小有关,因此您的最终输出是 3 维的,如摘要所示。问题是你的目标,你的火车没有重塑。您需要重塑您的目标数组,即您传递的目标数组以适合 shape 的 3D 张量(samples, 114688, 3)


推荐阅读