Hello,
what is the default initial weights for pytorch-geometric SAGEconv layer and other convolution layers? and how to initialize them using Xavier?
I need guidance in how to apply Xavier initialization in graph neural network, I am using pytorch geometry
I tried this, but it didn’t work,
def initialize_weights(self):
for m in self.modules():
if isinstance(m,SAGEConv):
nn.init.xavier_normal_(m.weight)
if m.bias is not None:
nn.init.constant_(m.bias, 0)
it neither goes to the first if statement, and gives error “AttributeError(f”‘{type(self).name}’ object has no attribute ‘{name}’“) AttributeError: ‘MeanAggregation’ object has no attribute ‘bias’”
I’m not sure for SAGEConv, but for regular PyTorch layers, you can just define a custom conv class, and reference the parent accordingly, then redefine the reset_parameters() function. Or just modify your code to something like this:
def initialize_weights(self):
for m in self.modules():
if isinstance(m,SAGEConv):
nn.init.xavier_normal_(m.weight.data)
So calling on the SAGEConv class won’t target the weights. Instead, you may need to change SAGEConv to Linear. But given it’s not a torch.nn.Linear, that might not work, too.
They also have a specific reset_parameters method:
I tried to print out the weights and I found that it is initialised by default with uniform Kaiming, and the weights are in conv1.lin_l.weight and conv1.lin_r.weight. for each SAGEconv layer. Reaching both of these weights, I could initialise them using Xavier.
thanks.