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 warning about saving best model only when val_acc is available means your checkpoint monitor name does not match the metrics emitted during training. In modern TensorFlow, metric names changed over time, so many older examples still reference outdated keys. The fix is to align ModelCheckpoint.monitor with the actual history keys and ensure validation metrics are being computed.
Why the Warning Appears
ModelCheckpoint saves based on the metric named in monitor. If the metric never appears in logs, callback logic cannot decide what is "best" and skips saving.
Common reasons:
- using
val_accwhile model reportsval_accuracy - no validation data passed to
fit - custom training step not logging the monitored name
- typo in monitor string
You can always inspect available metric names after a short run.
This printout tells you exactly which monitor names are valid in your environment.
Correct ModelCheckpoint Configuration
In current TensorFlow, use val_accuracy for binary and categorical classification unless you explicitly rename metrics.
If you monitor loss instead, use mode="min" and monitor="val_loss".
Pick one objective and keep it consistent with model goals.
Ensure Validation Metrics Exist
No validation metrics means no val_ keys, even with correct monitor spelling. You need either validation_split or explicit validation_data.
For sequence and custom dataset pipelines, verify validation dataset is non-empty and batched correctly.
Debugging With Callback Logs
If checkpointing still skips, add a small callback to print epoch log keys.
This removes guesswork and immediately shows whether your monitor key exists.
Notes on save_weights_only and File Formats
Choose whether you want full model serialization or only weights. Full model saves optimizer state and architecture, which is usually easier for deployment reproducibility.
When using save_weights_only=True, remember to rebuild model architecture before loading weights.
Verify Saved Artifacts During Training
Do not assume checkpoints are being written just because training logs continue. Confirm files appear and update as epochs progress.
For team workflows, store checkpoint path, monitored metric, and best value in run metadata. This makes experiment audits much easier when comparing runs across branches and environments.
Common Pitfalls
- Monitoring
val_accin environments that emitval_accuracy. - Forgetting to pass validation data and expecting
val_metrics. - Using
mode="max"while monitoring a metric that should decrease. - Typo in monitor string such as
val_acuracy. - Mixing full model and weights-only workflows without clear restore logic.
Summary
- The warning means the monitored metric was not found in epoch logs.
- Use history keys to choose the exact monitor name.
- Prefer
val_accuracyon modern TensorFlow unless custom names are defined. - Always provide validation data if monitoring
val_metrics. - Add callback log inspection to debug checkpoint behavior quickly.
Related reading
- 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
- Tensorflow.js pretrained Google AutoML model not working
- TensorflowJS Failed to parse model.json
- TensorflowJS It is possible to convert a graph model to a layers model?
- Tensorflow.js save model using node
- Tensorflow.js tokenizer
.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.