Keras: Get true labels (y_test) from ImageDataGenerator or predict_generator

I am using ImageDataGenerator().flow_from_directory(...)

to create data packages from catalogs.

After successfully assembling the model, I would like to get a two-column array of True and Predicted class labels. With help model.predict_generator(validation_generator, steps=NUM_STEPS)

I can get many arrays of predicted classes. Is it possible to predict_generator

output the appropriate class labels True?

To add: validation_generator.classes does print the labels True, but in the order in which they are fetched from the directory, it does not account for batch expansion or fetch growth.

+4


source to share


1 answer


You can get the forecast labels:

 y_pred = numpy.rint(predictions)

      

and you can get true shortcuts by:

y_true = validation_generator.classes

      



Before doing this, you must install shuffle=False

in the validation generator.

Finally, you can print the confusion matrix

print confusion_matrix(y_true, y_pred)

+1


source







All Articles