While training a neural network I would like to periodically evaluate the loss values on a mini-batch from the validation set. To this end, I create a train_loader and a val_loader as follows:
train_loader = torch.utils.data.DataLoader(
train_dataset, batch_size = BATCH_SIZE, shuffle = True, num_workers = 4
)
val_loader = torch.utils.data.DataLoader(
val_dataset, batch_size = BATCH_SIZE, shuffle = False, num_workers = 4
)
While training, for every 100 iterations, I do:
batch = iter(val_loader).next()
However I get BATCH_SIZE of identical images, e.g.,
<type ‘list’>: [‘COCO_val2014_000000000042’, ‘COCO_val2014_000000000042’, ‘COCO_val2014_000000000042’, ‘COCO_val2014_000000000042’, ‘COCO_val2014_000000000042’, ‘COCO_val2014_000000000042’, ‘COCO_val2014_000000000042’, ‘COCO_val2014_000000000042’, ‘COCO_val2014_000000000042’, ‘COCO_val2014_000000000042’, ‘COCO_val2014_000000000042’, ‘COCO_val2014_000000000042’, ‘COCO_val2014_000000000042’, ‘COCO_val2014_000000000042’, ‘COCO_val2014_000000000042’, ‘COCO_val2014_000000000042’, ‘COCO_val2014_000000000042’, ‘COCO_val2014_000000000042’, ‘COCO_val2014_000000000042’, ‘COCO_val2014_000000000042’, ‘COCO_val2014_000000000042’, ‘COCO_val2014_000000000042’, ‘COCO_val2014_000000000042’, ‘COCO_val2014_000000000042’, ‘COCO_val2014_000000000042’]
If I set shuffle to True then I can get BATCH_SIZE of random images, e.g.,
<type ‘list’>: [‘COCO_val2014_000000212761’, ‘COCO_val2014_000000478009’, ‘COCO_val2014_000000534428’, ‘COCO_val2014_000000272430’, ‘COCO_val2014_000000173434’, ‘COCO_val2014_000000577212’, ‘COCO_val2014_000000418700’, ‘COCO_val2014_000000494154’, ‘COCO_val2014_000000244581’, ‘COCO_val2014_000000054092’, ‘COCO_val2014_000000581450’, ‘COCO_val2014_000000581183’, ‘COCO_val2014_000000093686’, ‘COCO_val2014_000000242362’, ‘COCO_val2014_000000195542’, ‘COCO_val2014_000000303024’, ‘COCO_val2014_000000465430’, ‘COCO_val2014_000000194310’, ‘COCO_val2014_000000305404’, ‘COCO_val2014_000000581781’, ‘COCO_val2014_000000034471’, ‘COCO_val2014_000000027662’, ‘COCO_val2014_000000311041’, ‘COCO_val2014_000000579362’, ‘COCO_val2014_000000081061’]
I am wondering how am I able to get BATCH_SIZE of different images without having to set shuffle to True (i.e., get images from the validation set in its original order)?
Thanks!