Thanks for clarifying the use case!
There are some minor issues in the code.
You should store the state_dict
, update it, and reload it afterwards:
def __init__(...):
...
w1 = self.conv1.weight.detach().numpy()
print(w1[1][1][1])
state = model_zoo.load_url(resnet50_url)
state_dict = self.state_dict()
for k, v in state.items():
if 'fc' in k:
continue
state_dict.update({k: v})
self.load_state_dict(state_dict)
w2 = self.conv1.weight.detach().numpy()
print(w2[1][1][1])
w3 = state['conv1.weight'][1][1][1].detach().numpy()
print(w3)