How to resolve KeyError: 'val_mean_absolute_error' Keras 2.3.1 and TensorFlow 2.0 From Chollet Deep Learning with Python

The problem in your code is that, when you compile your model, you do not add the specific 'mae' metric.

If you wanted to add the 'mae' metric in your code, you would need to do like this:

  1. model.compile('sgd', metrics=[tf.keras.metrics.MeanAbsoluteError()])
  2. model.compile('sgd', metrics=['mean_absolute_error'])

After this step, you can try to see if the correct name is val_mean_absolute_error or val_mae. Most likely, if you compile your model like I demonstrated in option 2, your code will work with "val_mean_absolute_error".

Also, you should also put the code snippet where you compile your model, it is missing in the question text from above(i.e. the build_model() function)


I replaced 'val_mean_absolute_error' with 'val_mae' and it worked for me