I am using for loop to modify the parameters in the model. I use named_parameters to check the names of the attributes and using for loop to record them.
weight_data = []
bias_data=[]
weight_key =[]
bias_key = []
for key,value in net.named_parameters():
if (torch.tensor(value.size()).size()==torch.Size([3])):
weight_key.append(key)
weight_data.append(value)
elif …:
bias_data.append(value)
bias_key.append(key)
What I want to do is modify the parameters in weight_data, I now I can use:
net.fc1.conv.data = [] to do that, but I need to use for loop.
So how can I use keys in weight_key to do that? for example:
net.‘weight_key[0]’.data = […] (which is not right, just need too use the value in ‘weight_key’)
I would appreciate your help!