How to print y_pred value for multiclass image classification in Keras?

Viewed 28

How to print y_pred value for multiclass image classification in Keras?I also want to print Confusion Matrix for Multiclass classification. My code is as below:


train, val = train_test_split(index, test_size=0.2,random_state=42,stratify=index["level"])

train_datagen = ImageDataGenerator(rescale            = 1/255,
                                   shear_range        = 0.2,
                                   zoom_range         = 0.2,
                                   horizontal_flip    = True,
                                   rotation_range     = 40,
                                   width_shift_range  = 0.2,
                                   height_shift_range = 0.2)

val_datagen = ImageDataGenerator(rescale = 1/255)

train_set = train_datagen.flow_from_dataframe(
    train,
    path,
    x_col="image_name",
    y_col="level",
    class_mode="raw",
    color_mode="rgb",
    batch_size=32,
    target_size=(64, 64))

val_set = val_datagen.flow_from_dataframe(
    val,
    path,
    x_col="image_name",
    y_col="level",
    class_mode="raw",
    color_mode="rgb",
    batch_size=32,
    target_size=(64, 64))

model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy'])
1 Answers

after you defined the model and train it on train data, to return the predicted class based on model predictions with the high proba use this method np.argmax(model_predictions, axis = -1) and even to define its label could use train_set.class_indices

Related