-
Notifications
You must be signed in to change notification settings - Fork 7.5k
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
DataBlock.dataloaders does not support the advertised "shuffle" argument #3133
Comments
Actually, I see the same issue appears on lines 215-216 as well, if |
Was able to reproduce this and taking a look at it now. |
just to understand, what are you trying to shuffle? |
I was trying to shuffle the validation set (I had a good reason to), but realised that even if the |
@juliangilbey Just to help with writing this, why are you trying to shuffle the validation set? I wouldn't think we would want to drop the last batch on the validation set so making sure. |
@jph00 For this one I think it might be good to assume keyword arguments apply to train, and can be overridden for the validation set by starting with 'val_'. The key idea below:
Here is a more complete gist for my idea: https://gist.github.com/marii-moe/7374ee9d59400f85b17dc54b7a2c4af0 Here is the original: Line 207 in dded785
This would mean removing 'shuffle_train' which has been part of the api as far back as I could track in fastai_dev/fastai2. It is important to put all in a |
Hi @marii-moe I wanted to run |
I like it. Let's leave |
Please confirm you have the latest versions of fastai, fastcore, and nbdev prior to reporting a bug (delete one): YES
fastai 2.2.2, fastcore 1.3.16, nbdev 1.1.6
Describe the bug
The DataBlock documentation describes the https://docs.fast.ai/data.block.html#DataBlock.dataloaders function and explicitly says that there is an optional kwarg
shuffle
. However, using this results in the error:To Reproduce
Take the notebook for Chapter 2 of the fastai book, and change the cell which reads
dls = bears.dataloaders(path)
to readdls = bears.dataloaders(path, shuffle=True)
instead.Expected behavior
It should perform shuffling as requested.
Error with full stack trace
Additional context
The cause of the error is clear, though the best way to solve it is not as obvious. The
DataBlock.dataloaders()
method:fastai/fastai/data/block.py
Lines 112 to 115 in 373050b
just passes most of the keyword arguments through to its
Datasets
object, which in turn is a subclass ofFilteredBase
, so inherits thedataloaders()
method from there. This method is as follows:fastai/fastai/data/core.py
Lines 207 to 217 in d1cf81c
This has the keyword argument
shuffle_train
(but not shuffle), but on lines 213-214, calls thedl_type
function with an explicitshuffle
keyword and then thekwargs
passed through (merged withdl_kwargs[0]
). So ifkwargs
includesshuffle
, there will be a repeated keyword argument.I haven't checked whether the same would apply to the other keyword arguments listed on line 213.
One simple way would be to rewrite lines 213-214 as:
The text was updated successfully, but these errors were encountered: