Does DataBunch.one_batch return the same batch everytime?

(Vishal R) #1

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

0 Likes

(Zachary Mueller) #2

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)

0 Likes

(Vishal R) #3

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

(Zachary Mueller) #4

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

1 Like