SOLVED: Iterating over a batch

@muellerzr I would like to iterate through each batch myself. Does anyone know the code to get one batch, increment a count, get the next batch, etc until no more images?

I’ve used one_batch() but it keeps getting the same batch over and over. I don’t know how to push the iterator to the next batch.

1 Like

You can iterate over the DataLoaders batches the following way:

for i in dls.train: print(i)

where i is each batch. You can do the same for dls.valid. You could also use enumerate and use the index if you need to add to a count

Without more information on your specific problem, its hard to suggest something more complex.

2 Likes

Thanks Craig. That is perfect. It works to iterate through the batches.

I really appreciate it.

1 Like