How to properly save conv2d weights?

So I have just 1 layer of conv2d defined as follows: -
self.proj = nn.Conv2d(in_chans, embed_dim, kernel_size=patch_size, stride=patch_size)

Now I want to save its state dictionary for future use. I thought that the state dictionary is a python dictionary that contains the weights of the model but when I execute
print(self.proj.state_dict)
I get
<bound method Module.state_dict of Conv2d(3, 96, kernel_size=(4, 4), stride=(4, 4))>

And if I execute
print(self.proj.state_dict.keys())
I get
AttributeError: 'function' object has no attribute 'keys'

So how do I get the weights?

You would have to call the state_dict method via:

print(self.proj.state_dict())
1 Like

Thanks a lot! This was the problem.