python-3.x - ValueError:检查目标时出错:预期的预测有 4 个维度,但得到了形状为 (256, 1, 1) 的数组
问题描述
我正在尝试训练模型 Keras,但我遇到了问题:
g = ImageDataGenerator(featurewise_center=True,
featurewise_std_normalization=True,
rotation_range=45,
width_shift_range=0.2,
height_shift_range=0.2,
horizontal_flip=True,
validation_split=validation_split,
preprocessing_function=lambda x: x / 127 - 1)
g_train = g.flow(x_train, y_train,
batch_size=batch_size,
subset='training')
g_valid = g.flow(x_train, y_train,
batch_size=batch_size,
shuffle=False,
subset='validation')
history = network.fit_generator(g_train,
steps_per_epoch=len(x_train) / 32,
epochs=epochs)
ValueError: Error when checking target: expected predictions to have 4 dimensions, but got array with shape (256, 1)
有人知道为什么吗?在我看来,这很像文档中的示例。
x_train.shape
(50000, 32, 32, 1)
y_train.shape
(50000, 1, 1)
解决方案
推荐阅读
- angular - aws-sdk bucket.getObject:没有“访问控制允许来源”错误
- webrtc - WebRTC:我需要 TURN 服务器吗?(这会有帮助吗?)
- python - 如何修复使用python请求库时出现的转义字符?
- jquery - 两个 div 中的活动类冲突
- data-structures - 这个数据结构的名称是什么,在哪里使用?
- azure - 使用 Key Vault 管理其密钥的 Azure 存储帐户
- sql - 如何按顺序检查组联合的可能性
- python - 在 QWizardPage 上获取 QTreeView 以正确更新
- python - 如何在 Python 中捕获对列表项的直接引用以提高速度?
- javascript - 使用 React 单击按钮时在 div 上显示返回的对象