New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unexpected steps_per_epoch behavior in model.fit #64076
Comments
@varshad18 Could you please double-check your calculation for steps_per_epoch. Kindly ensure it considers the total number of samples in your dataset and the batch size. |
epochs = 300 Calculate steps per epoch and validation stepssteps_per_epoch = train_size // BATCH_SIZE Optionally, you can adjust steps_per_epoch and validation_steps based on whether your dataset is shuffledIf your dataset is shuffled during training, you might want to set steps_per_epoch to Noneand let it automatically determine the number of steps based on the dataset size and batch sizehist = model.fit(x=[trainNumericData, trainImagesSBData, trainImagesCBData, trainImagesWBData, trainImagesHBData,trainImagesLLData,trainImagesLBData, trainImagesUpLeftABData,trainImagesUpRightABData, trainImagesALeftLData, trainImagesARightLData],y=trainAllRegressionData,epochs=epochs,validation_data=([validationNumericData, validationImagesSBData, validationImagesCBData, validationImagesWBData, validationImagesHBData, validationImagesLLData,validationImagesLBData, validationImagesUpLeftABData, validationImagesUpRightABData, validationImagesALeftLData, validationImagesARightLData], validationAllRegressionData),steps_per_epoch=steps_per_epoch, # Set steps_per_epochvalidation_steps=validation_steps, # Set validation_stepscallbacks=[mc, tensorboard_callback]).historyInstead of manually setting steps_per_epoch and validation_steps, you can let it automatically determine based on the dataset size and batch sizehist = model.fit( |
@varshad18 Could you please share the complete code in a notebook or gist to replicate the issue reported here? |
@sushreebarsa I double-checked my calculation for steps_per_epoch and tried using the following formula:
This worked for me and is training for all 179 steps with no errors. But the most common approach is to simply exclude the last incomplete batch from training during an epoch and here if I try to exclude the last batch by
Is it okay to train 179 steps according to my train size? Or am I doing something wrong? |
@varshad18 Could you please confirm if you are still using Keras 2 ? If so then please migrate to Keras 3 and follow this documentation here. Thank you! |
This issue is stale because it has been open for 7 days with no activity. It will be closed if no further activity occurs. Thank you. |
This issue was closed because it has been inactive for 7 days since being marked as stale. Please reopen if you'd like to work on this further. |
Issue type
Bug
Have you reproduced the bug with TensorFlow Nightly?
Yes
Source
source
TensorFlow version
2.15.0
Custom code
Yes
OS platform and distribution
Windows 11 x64
Mobile device
No response
Python version
3.10.12
Bazel version
No response
GCC/compiler version
No response
CUDA/cuDNN version
No response
GPU model and memory
No response
Current behavior?
According to documentation, under the Args of fit method:
So when I run the model.fit function without the steps_per_epoch assigned, and without the validation_steps, the model trains all epochs without error. But uses a very small number for steps_per_epoch.
In my case:
But it trains only for 23 steps each epoch.
Questions
Standalone code to reproduce the issue
Relevant log output
The text was updated successfully, but these errors were encountered: