-
Notifications
You must be signed in to change notification settings - Fork 323
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
Fix max_depth recursion crash in AsynchronousLoader #191
Conversation
Some people use dict samples with strings, numpy array etc. They are returned from dataloader and are passed to model. Later those are parsed/replaced/removed inside of step/forward function. Example of such dict (I use it): `{'image': tensor([WHATEVER]), 'path': [WHATEVER_STRING], 'target': tensor([WHATEVER_NUMPY]), 'meta': {'PatientAge': tensor([WHATEVER]), 'PatientSex': tensor([WHATEVER]), 'StudyDate': tensor([WHATEVER])}, 'mask': tensor([WHATEVER]), 'bboxes': [[tensor([WHATEVER]), tensor([WHATEVER]), tensor([WHATEVER])]]}` Sadly, async loader was crashing as max depth of recursion was reached (e.g. when it meets string, it just infinitely goes to else in original AsyncLoader). I went to torch.utils.data.default_collate (as it's said that code is based on it), took few lines from there and it works now. So it will no longer crash at named_tuples, dict-like objects and strings. Those will all be processed.
Codecov Report
@@ Coverage Diff @@
## master #191 +/- ##
==========================================
- Coverage 87.81% 87.57% -0.25%
==========================================
Files 89 89
Lines 4236 4250 +14
==========================================
+ Hits 3720 3722 +2
- Misses 516 528 +12
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
Hello @DaGuT! Thanks for updating this PR.
Comment last updated at 2020-09-08 11:38:16 UTC |
Small note: |
Some people use dict samples with strings, numpy array etc. They are returned from dataloader and are passed to model. Later those are parsed/replaced/removed inside of step/forward function.
Example of such dict (I use it):
{'image': tensor([WHATEVER]), 'path': [WHATEVER_STRING], 'target': tensor([WHATEVER_NUMPY]), 'meta': {'PatientAge': tensor([WHATEVER]), 'PatientSex': tensor([WHATEVER]), 'StudyDate': tensor([WHATEVER])}, 'mask': tensor([WHATEVER]), 'bboxes': [[tensor([WHATEVER]), tensor([WHATEVER]), tensor([WHATEVER])]]}
Sadly, async loader was crashing as max depth of recursion was reached (e.g. when it meets string, it just infinitely goes to else in original AsyncLoader).
I went to torch.utils.data.default_collate (as it's said that code is based on it), took few lines from there and it works now. :)
So it will no longer crash at named_tuples, dict-like objects and strings. Those will all be processed.
Before submitting
What does this PR do?
Fixes issue when anything other than torch.tensor containing thing is passed to AsynchronousLoader (more details above)
PR review
Anyone in the community is free to review the PR once the tests have passed.
If we didn't discuss your PR in Github issues there's a high chance it will not be merged.
Did you have fun?
Make sure you had fun coding 🙃