python - 重塑层存在但不重塑
问题描述
嗨,同时添加一个简单而琐碎的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
______________________________________________________________
解决方案
这是预期的行为,错误与批量大小有关,因此您的最终输出是 3 维的,如摘要所示。问题是你的目标,你的火车没有重塑。您需要重塑您的目标数组,即您传递的目标数组以适合 shape 的 3D 张量(samples, 114688, 3)
。
推荐阅读
- python - Beautiful Soup - XML 解析 - 属性错误异常(处理空值)
- azure - 管理用于暂存和生产的 Azure 应用服务中的 Docker 映像
- r - R:write.table 的异常输出
- python - 无法再使用“python”在 PowerShell 或控制台中启动 Python 解释器,需要输入“py”
- python - 将列表中每个元素的长度与 Python 中的某个数字进行比较
- flutter - 警报框中的颤振导航器不起作用
- asp.net-core - 如何从控制器中提取方法?
- python - 使用python将列表中的字典转换为JSON格式
- android - Android 11 媒体恢复发出第二次通知
- java - Java 8 Stream vs For 循环 - 修改列表中的对象,使用另一个列表中对象的属性