tensorflowCan save best model only with val_acc available, skipping
ML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.
Introduction
The message Can save best model only with val_acc available, skipping comes from Keras ModelCheckpoint when the callback is told to watch a metric that never appears in the training logs. In practice, that usually means the monitor name is outdated, validation data was not provided, or the metric was never compiled into the model in the first place.
Why the Callback Skips Saving
ModelCheckpoint(save_best_only=True) works by comparing the current epoch value of one metric against the best value seen so far. If the callback looks for val_acc and the logs only contain val_accuracy, it has nothing to compare and prints the skipping message instead of saving.
That behavior is important because it means the callback is not broken. It is protecting you from saving based on a metric that does not exist.
A minimal example of the correct modern pattern looks like this:
With this configuration, val_accuracy exists, so the checkpoint callback can compare epochs and save the best model.
Old Metric Names Versus New Metric Names
A large share of these errors comes from copying code written for older Keras versions. Older tutorials often used:
- '
acc' - '
val_acc'
Modern tf.keras usually logs:
- '
accuracy' - '
val_accuracy'
That small naming change is enough to trigger the warning. If the code says monitor="val_acc" but your history contains val_accuracy, the callback will skip every epoch.
The fastest way to stop guessing is to print the actual history keys:
Typical output looks like this:
Use one of those exact strings for monitor.
Validation Data Must Exist
The prefix val_ means Keras computed the metric on validation data. If you do not pass validation_data or validation_split, there is no validation metric at all.
In that case, the logs will usually contain only training metrics such as loss and accuracy. Monitoring val_accuracy is impossible because it was never produced.
If you intentionally do not have validation data, monitor a training metric instead:
That is valid, but it changes the meaning of “best” from best validation result to best training result.
The Metric Must Be Compiled
The metric also needs to be part of compile. If you monitor val_accuracy but compile only a loss, Keras will not log accuracy at all.
The same rule applies to custom metrics. If you define tf.keras.metrics.AUC(name="auc"), then the validation metric will typically be named val_auc, not val_accuracy or val_acc.
Again, the key point is exact name matching.
Match the mode to the Metric
The mode argument matters too. Accuracy-like metrics should usually use mode="max", because bigger is better. Loss metrics should usually use mode="min", because smaller is better.
A wrong mode does not cause the “available, skipping” message, but it can still make checkpoint selection incorrect.
A Reliable Debugging Routine
When ModelCheckpoint behaves strangely, use this checklist:
- print
history.history.keys() - confirm validation data exists if the monitor starts with
val_ - confirm the metric appears in
compile(metrics=...) - confirm
modematches the direction of improvement
This is much faster than changing the callback arguments at random.
Common Pitfalls
- Monitoring
val_accin moderntf.keraswhere the real key isval_accuracy. - Expecting validation metrics without passing
validation_dataorvalidation_split. - Compiling the model without the metric you want to monitor.
- Using
mode="max"forval_lossormode="min"for accuracy. - Debugging the callback before inspecting
history.history.keys().
Summary
- The skipping message means the monitored metric is missing from the logs.
- In modern
tf.keras,val_accuracyis usually the right replacement forval_acc. - Validation metrics exist only when validation data is actually provided.
- The monitored metric must also be present in
compile(metrics=...). - Print the history keys first and make the callback match them exactly.
Related reading
- tensorflowCan save best model only with val_acc available, skipping
- tensorflow.contrib.graph_editor in TF 2 API?
- TensorFlow.js How to avoid Your CPU supports instructions ... AVX AVX2?
- tensorflow.js loss goes to infinity
- TensorflowJS Failed to parse model.json
- TensorflowJS It is possible to convert a graph model to a layers model?
- Tensorflow.js pretrained Google AutoML model not working
- Tensorflow.js save model using node
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
ML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.