Thx for your answers!! But I have some puzzles!
I have done below:
mycnn = CNN()
print (mycnn.state_dict().keys())
it shows：
[‘conv1.0.weight’, ‘conv1.0.bias’, ‘conv2.0.weight’, ‘conv2.0.bias’, ‘conv3.0.weight’, ‘conv3.0.bias’, ‘fc1.weight’, ‘fc1.bias’, ‘out.weight’, ‘out.bias’]
Then I try to do below:
print (mycnn.conv1[0].bias.data)
print (mycnn.state_dict()[‘conv1.0.bias’].data)
The outputs are different.
And I check the gradient:
It shows
mycnn.conv1[0].bias.grad = None
mycnn.state_dict()[‘conv1.0.bias’].grad is an ERROR
AttributeError: ‘torch.FloatTensor’ object has no attribute ‘grad’
Can you tell the difference between “mycnn.conv1[0].bias” and “mycnn.state_dict()[‘conv1.0.bias’]” in my Pytorch model?