I want to call torch.nn.utils spectral_norm function on a GCNConv layer
gc1 = GCNConv(18, 16)
spectral_norm(gc1)
but I'm getting the following error:
KeyError: 'weight'
meaning gc1._parameters doesn't have weight (only bias):
gc1._parameters
OrderedDict([('bias', Parameter containing:
tensor([0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
requires_grad=True))])
However, gc1.parameters() stores two objects and one of them is a 16 by 18 matrix (weight matrix).
for p in gc1.parameters():
print('P: ', p.shape)
P: torch.Size([16])
P: torch.Size([16, 18])
How can I make spectral_norm function work on a GCNConv module?
According to the source code, the weight parameter is wrapped within a linear module contained in GCNConv objects as lin
.
I imagine that this should then work:
gc1 = GCNConv(18, 16)
spectral_norm(gc1.lin)