Skip to content
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

Set batch num to 1 for low samples cases in the dataloader #48

Conversation

louisPoulain
Copy link
Collaborator

When creating a DataLoader with a DataModule that has less samples than the provided batch size, the __getitem__ always returns an IndexError. This issues arises often when using thinning as the number of test and validation samples is already low.

The simple change consists in checking whether the number of samples is too low and in that case to set batch_num to be 1. This prevents the __getitem__ from raising an IndexError.

Copy link
Member

@dnerini dnerini left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect, thanks!

@dnerini dnerini merged commit 5c2e52f into main Jun 27, 2024
2 checks passed
@dnerini dnerini deleted the 47-allow-having-dataloaders-with-less-samples-than-the-provided-batch_size branch June 27, 2024 15:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow having dataloaders with less samples than the provided batch_size
2 participants