Training and validation data loader


#1

Trying to understand different behaviors of validation and training loader in pascal and pascal-multi notebook.

Every time, I execute

x,y=next(iter(md.trn_dl)) ; show_img(md.trn_ds.denorm(to_np(x))[0]);

I could see different “x” and “y” . If I am not wrong then that how iterator should give us next “x” and “y”. But this is not true for “md.val_dl”.

It does not matter how many times i executed

x,y=next(iter(md.val_dl)) ; show_img(md.val_ds.denorm(to_np(x))[0]);

value of “x” and “y” does not change. It does not iterate through all validation dataset.

Can someone explain me this behavior?


(Marcin Kardas) #2

Every time you call iter(), a new iterator is created. In order to iterate over whole dataset using next() you have to store the iterator somewhere.

it = iter(md.trn_dl)
x,y=next(it) ; show_img(md.trn_ds.denorm(to_np(x))[0]);
x,y=next(it) ; show_img(md.trn_ds.denorm(to_np(x))[0]);
...

The difference between training and validation data loader is that the former shuffle the data.


#3

Thank you Marcin!!