ValueError:检查目标时出错:预期的预测具有4维,但数组的形状为(256,1,1)

时间:2019-05-29 00:37:05

标签: python-3.x keras

我正在尝试训练模型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)

0 个答案:

没有答案