Graph convolutional network: please can someone help me with this error

IndexError Traceback (most recent call last)
in ()
22 for batch in train_loader:
23 optimizer.zero_grad()
ā€”> 24 y_train_prediction = model(batch)
25 loss = MSE(denormalize_output(y_train_prediction, y_val_mean, y_val_std), denormalize_output(batch.y, y_val_mean, y_val_std))
26 loss.backward()

3 frames
/usr/local/lib/python3.7/dist-packages/torch/nn/modules/module.py in _call_impl(self, *input, **kwargs)
1100 if not (self._backward_hooks or self._forward_hooks or self._forward_pre_hooks or _global_backward_hooks
1101 or _global_forward_hooks or _global_forward_pre_hooks):
ā†’ 1102 return forward_call(*input, **kwargs)
1103 # Do not call functions when jit is used
1104 full_backward_hooks, non_full_backward_hooks = [], []

in forward(self, data)
15 # x: Node feature matrix of shape [num_nodes, in_channels]
16 # edge_index: Graph connectivity matrix of shape [2, num_edges]
ā€”> 17 x = self.conv1(x, edge_index).relu()
18 x = self.conv2(x, edge_index)
19 return x

/usr/local/lib/python3.7/dist-packages/torch/nn/modules/module.py in _call_impl(self, *input, **kwargs)
1100 if not (self._backward_hooks or self._forward_hooks or self._forward_pre_hooks or _global_backward_hooks
1101 or _global_forward_hooks or _global_forward_pre_hooks):
ā†’ 1102 return forward_call(*input, **kwargs)
1103 # Do not call functions when jit is used
1104 full_backward_hooks, non_full_backward_hooks = [], []

/usr/local/lib/python3.7/dist-packages/torch_geometric/nn/conv/gcn_conv.py in forward(self, x, edge_index, edge_weight)
162 if cache is None:
163 edge_index, edge_weight = gcn_norm( # yapf: disable
ā†’ 164 edge_index, edge_weight, x.size(self.node_dim),
165 self.improved, self.add_self_loops)
166 if self.cached:

IndexError: Dimension out of range (expected to be in range of [-1, 0], but got -2)

I guess the x.size operation fails and raises the error as seen here:

x = torch.randn(10)
node_dim = -2
x.size(node_dim)
# > IndexError: Dimension out of range (expected to be in range of [-1, 0], but got -2)

If so, check the dimensions of x as well as the value of self.node_dim and make sure the latter can be used to get the size of x.

1 Like