I have two datasets each of 142.000 images, one for training and one for validation. What I have implemented is that it goes through the train data set (batchsize 11) and trains.
But what I now want to do is the following:

train on the first images 11 images of the train set
validate the model on the first 11 images from the validation set
then train on the second 11 images of the train set
then validate the model on the second 11 images from the validation set
etc.

training_data_loader = DataLoader(dataset=train_set, num_workers=4, batch_size=11)
val_data_loader = DataLoader(dataset=val_set, num_workers=4, batch_size=11)

Here is my trainings code. Here I enumerate over the training_data_loader. Is there an efficient way to get the corresponding batch from the val_data_loader?
I tried a for loop that iterates through the val_data_loader and gets me the correct batch, but that’s too time consuming. I have to directly access the correct batch from the val_data_loader. I tried it with the function getitem, but I didn’t found a solution that worked.
for iteration, batch in enumerate(training_data_loader, 0):
		input_train, target_train = Variable(batch[0]), Variable(batch[1])

		if cuda:
			input_train = input_train.cuda()
			target_train = target_train.cuda()
            
		optimizer.zero_grad()
        
		output_model_train = model(input_train)

		loss = criterion(output_model_train, target_train)
        
		loss.backward()
		optimizer.step()