How to modify values inside input dataset

Hello I have a dataset object using as input. I can access to the input dataset object using index and see they are all tensors.

I want to update some of the values in my input after each iteration based on my algorithm, how do I do that?

I tried the way of modify a tensor as documentation said but the values do not change:

in raw data, I have data[‘img’] and data[‘prob’]
and I use datasets and dataloader function with data tranform.

for i in range(0, len(dataset):
dataset[i][0][‘prob’][0] = calculated_value[i].item(0)

the value won’t change.

Please help! Really appreciated!

Do you want to change the values after an epoch (after a call of enumarate dataset) or during an epoch as well???

To be more accurate, after several full run, not in each epoch. So basically I run a net fit several times with cross validation and then update the input data and re-run the whole process.

why not create a function inside the Dataset object, something like update which might take arguments required and updates the data[‘prob’]. You will have have freedom to call the function when you want (after how many cross validations you want…)
I believe this should work, have done something similar myself once

Thank you for the suggestion I will try to implement that.
Still I wonder why the simple modification directly towards tensors inside the dataset object is not working.

Any luck? I am interested in doing the same thing.

1 Like