Keras:KeyError:‘Failed to format this callback filepath:{val_loss:.4f}.h5. Reason: \‘val_loss\‘‘

If you use keras’s imagedatagenerator for image enhancement, it is as follows:

validataion_generator = validation_datagen.flow_from_directory(validation_dir,
                                                               target_size=target_size,
                                                               batch_size=batch_size,
                                                               class_mode='categorical',
                                                               subset="validation")

In addition, your training set and verification set are two different folders, and the file name of the saved model is required to include the loss of the model above the verification set, then the error described in the title is likely to occur:

Keras:KeyError:'Failed to format this callback filepath:{val_loss:.4f}.h5. Reason: \'val_loss\''

At this time, you only need to delete the subset parameter. The subset parameter is generally used for training and verification. It is a batch of data and has been passed into validation_ Subset needs to be defined only when split is used for data division. The specific modifications are as follows:

validataion_generator = validation_datagen.flow_from_directory(validation_dir,
                                                               target_size=target_size,
                                                               batch_size=batch_size,
                                                               class_mode='categorical')

Re run the program, there will be no error, normal training!

Read More: