Python 3.x 使用predict_generator时如何返回项目的真实标签?

Python 3.x 使用predict_generator时如何返回项目的真实标签?,python-3.x,machine-learning,neural-network,deep-learning,keras,Python 3.x,Machine Learning,Neural Network,Deep Learning,Keras,我正在使用predict\u generator()函数观察神经网络的输出,但我无法看到预测项目的真实标签。如何实现块以查看输入项的真实标签 test_datagen = ImageDataGenerator( rescale=1./255, rotation_range=45, width_shift_range=0.25, height_shift_range=0.25, horizontal_flip=True, ) test_generator = test_datagen.flow_f

我正在使用
predict\u generator()
函数观察神经网络的输出,但我无法看到预测项目的真实标签。如何实现块以查看输入项的真实标签

test_datagen = ImageDataGenerator(
rescale=1./255,
rotation_range=45,
width_shift_range=0.25,
height_shift_range=0.25,
horizontal_flip=True,
)
test_generator = test_datagen.flow_from_directory(
    evaluate_path,
    target_size=(width, height),
    batch_size=batch_size,
    class_mode='categorical')

model.compile(optimizer=SGD(lr=0.0001, momentum=0.9),      loss='categorical_crossentropy', metrics=['accuracy'])
x = model.predict_generator(test_generator, val_samples=1)
print(x)

尝试以下功能:

from six import next

def generator_with_true_classes(model, generator):
    while True:
        x, y = next(generator)
        yield x, model.predict(x), y
它将产生原始数据,
y\u pred
y\u true
。按以下方式使用:

nb_of_samples = 0
nb_of_samples_to_compute = 100 # set your own value
for x, y_pred, y_true in generator_with_true_classes(model, test_generator):
    # do something with data, eg. print it.
    nb_of_samples += 1
    if nb_of_samples == nb_of_samples_to_compute:
         break

predict_generator()返回包含所有预测的numpy数组。你能提供你的代码并给出你遇到问题的更多细节吗?我想看到预测和真实的标签。基本上,他们想知道如何“产生生成器的结果”。你错过了
test\u generator
的定义。是outputValueError:无法为具有形状“(?,250,250,3)”的张量“input_1:0”馈送形状()的值您确定生成器工作正常吗?找到了多少张图片?找到了326张图片,分为两类。奇怪-但现在试试。