Does DataBunch.one_batch return the same batch everytime?

The DataBunch.one_batch return the same batch or different batches every time? The docs aren’t very clear on this.

The source code shows:

        dl = self.dl(ds_type)
        w = self.num_workers
        self.num_workers = 0
        try:     x,y = next(iter(dl))

So yes, it will always return the first batch of data and then subsequent should return the next

(https://github.com/fastai/fastai/blob/master/fastai/basic_data.py#L163)

I just checked it out using a small dataset. It returns different batches. I can understand it now. I’ll make sure to check the source code next time before I ask.

1 Like

You’re right :slight_smile: next(iter()) grabs the next one afterwards. Nice catch

1 Like