Add configurable batch_size to CNN to fix GPU OOM on large directories#241
Open
umerkhan95 wants to merge 1 commit intoidealo:devfrom
Open
Add configurable batch_size to CNN to fix GPU OOM on large directories#241umerkhan95 wants to merge 1 commit intoidealo:devfrom
umerkhan95 wants to merge 1 commit intoidealo:devfrom
Conversation
…directories The batch size was hardcoded at 64 with no way to lower it, which caused OOM on GPUs with limited memory. This adds a batch_size parameter to CNN() so users can reduce it when needed. Also fixes a few related problems found along the way: - features are now moved to cpu per batch instead of accumulating on gpu - collate_fn no longer crashes when all images in a batch are unreadable - bad_im_count now counts actual bad images instead of batches - pool in parallelise uses a context manager to avoid leaked workers - single image encoding uses explicit shape check instead of squeeze()
d063c2f to
34176b3
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #232
The batch size was hardcoded at 64 with no way to lower it, which caused OOM on GPUs with limited memory when processing large image directories.
Changes:
CNN()now accepts abatch_sizeparameter (default 64, fully backwards compatible)_collate_fnhandles the case where all images in a batch fail to loadbad_im_countnow counts individual bad images, not just batchesparalleliseuses pool as a context manager to clean up workers properlyshape[0] == 1check instead ofsqueeze()Usage:
Tests:
All 251 existing + new tests pass across the suite. Added tests for custom batch sizes, batch size edge cases (1, larger than dataset), and all bad images directory.