tensorflowYour input ran out of data
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 saying input ran out of data means training expected more batches than the dataset could produce. This is usually a mismatch between dataset cardinality, epoch configuration, and steps_per_epoch. The fix is to size steps from real batch counts or make dataset repetition explicit.
Core Sections
Understand the Failure Condition
Keras fit consumes batches until epoch target is reached. Failure occurs when:
- dataset is finite
- configured steps require more batches than available
- dataset is not repeated
A common trigger is setting large steps_per_epoch by sample count guess instead of actual batch count.
Baseline Working Setup Without Explicit Steps
If dataset is finite and you do not need strict step count, omit steps_per_epoch.
Keras infers available batches from dataset cardinality.
When You Need steps_per_epoch
Use explicit steps only when required, for example infinite datasets or strict experiment comparability.
Here repeat ensures enough data for configured steps.
Compute Step Count Correctly
If you want deterministic step count for finite data, compute from sample count and batch size.
Choose floor or ceil intentionally based on whether you want partial final batch.
Check Dataset Cardinality in Debugging
Cardinality is a quick signal for finite versus infinite datasets.
Special values can indicate unknown or infinite cardinality, which changes how you configure fit.
drop_remainder Interaction
When batching with drop_remainder=True, final partial batch is discarded. This reduces available batches and can cause unexpected shortfall.
Recalculate steps whenever batching options change.
Multi-Worker and Distributed Training
In distributed settings, effective per-worker batch behavior can differ because of sharding and drop rules. Verify cardinality and steps on the actual distributed input pipeline, not only on local prototype.
Validation Data Can Also Run Out
This error is not limited to training dataset. If validation dataset is finite and validation_steps is set too high, the same failure can occur during evaluation phase.
Keep validation step sizing aligned with validation cardinality, especially after changing batch size.
Practical Prevention Checklist
Before long runs:
- print one batch shape
- inspect cardinality
- verify batch size and drop remainder
- verify steps against expected available batches
- run one short epoch smoke test
This prevents wasting time on avoidable configuration errors.
Keep Step Math with Dataset Code
Store step-count calculations near dataset construction code rather than scattered in training configs. This reduces mismatch risk when batch size or sharding logic changes.
Common Pitfalls
- Setting
steps_per_epochlarger than available finite dataset batches. - Forgetting
.repeat()when using explicit steps on finite input. - Changing batch settings and not updating step calculations.
- Confusing sample count with batch count.
- Ignoring cardinality checks before long training jobs.
Summary
- Input-ran-out-of-data errors come from step and dataset mismatch.
- Omit explicit steps for simple finite dataset training.
- Use
.repeat()when fixed steps are required. - Recompute step counts after batch or drop settings change.
- Add a short smoke run to catch configuration mistakes early.
Related reading
- tensorflowYour input ran out of data
- Testing GPU with tensorflow matrix multiplication
- Tf-Idf Vectorizer with LSTM in Keras Error Expected LSTM to have 3 dimensions
- TF2 / Keras slice tensor using , , 0
- tensor.numpy not working in tensorflow.data.Dataset. Throws the error AttributeError 'Tensor' object has no attribute 'numpy
- TensorRT - TensorFlow deserialization fails with Serialization Error in verifyHeader
- Test error lower than training error
- Test have poor results when using BatchNorm
.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.