Load a modified value of data in the dataloader

Hello,

I am trying to do the following:

Load the values x and y using the data loader.
Do a forward pass, and update the parameters.
I need to change some values of y based on some criterion, and I need to be able to sample from the new updated y from next iteration onwards.

How can this be done?

1 Like

You can do this when you get it from the DataLoader itself. Assume you have a training loop like this:

my_data_loader = torch.utils.data.DataLoader(dataset=dataset, batch_size=batch_size, shuffle=shuffle)`
for i, itr in enumerate(my_data_loader):
   	X, Y = itr
  	Y = my_function(Y)
   	# Do something

I think this should work

Yes. But so in the next epoch, will I be able to load the modified Y ?

No. I don’t think my snippet saves the changes. But there is probably very little overhead in doing something like this, you might as well do this.