Running a basic graph classification algorithm with my own data, most of the code being from here. I get the below issue in the training loop, and I don’t understand why.
One problem could be, my node features are not normalized, some can be 99999 and some 0.12 . Does Pytorch Geometric have a normalization method?
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
<ipython-input-9-1ad15c16fb39> in <module>
2
3 for epoch in range(1, 25):
----> 4 loss = train(epoch)
5 train_acc = test(train_loader)
6 test_acc = test(test_loader)
<ipython-input-8-6e9d94325104> in train(epoch)
6 data = data.to(device)
7 optimizer.zero_grad()
----> 8 output = model(data)
9 loss = F.nll_loss(output, data.y.long())
10 loss.backward()
~/anaconda3/envs/py38/lib/python3.8/site-packages/torch/nn/modules/module.py in __call__(self, *input, **kwargs)
530 result = self._slow_forward(*input, **kwargs)
531 else:
--> 532 result = self.forward(*input, **kwargs)
533 for hook in self._forward_hooks.values():
534 hook_result = hook(self, input, result)
<ipython-input-6-8fcd8f65419a> in forward(self, data)
15
16 # 1. Obtain node embeddings
---> 17 x = self.conv1(x, edge_index)
18 x = x.relu()
19 x = self.conv2(x, edge_index)
~/anaconda3/envs/py38/lib/python3.8/site-packages/torch/nn/modules/module.py in __call__(self, *input, **kwargs)
530 result = self._slow_forward(*input, **kwargs)
531 else:
--> 532 result = self.forward(*input, **kwargs)
533 for hook in self._forward_hooks.values():
534 hook_result = hook(self, input, result)
~/anaconda3/envs/py38/lib/python3.8/site-packages/torch_geometric/nn/conv/gcn_conv.py in forward(self, x, edge_index, edge_weight)
98 self.cached_num_edges = edge_index.size(1)
99 if self.normalize:
--> 100 edge_index, norm = self.norm(edge_index, x.size(self.node_dim),
101 edge_weight, self.improved,
102 x.dtype)
~/anaconda3/envs/py38/lib/python3.8/site-packages/torch_geometric/nn/conv/gcn_conv.py in norm(edge_index, num_nodes, edge_weight, improved, dtype)
77
78 row, col = edge_index
---> 79 deg = scatter_add(edge_weight, row, dim=0, dim_size=num_nodes)
80 deg_inv_sqrt = deg.pow(-0.5)
81 deg_inv_sqrt[deg_inv_sqrt == float('inf')] = 0
RuntimeError: Invalid index in scatterAdd at /opt/conda/conda-bld/pytorch_1579022027550/work/aten/src/TH/generic/THTensorEvenMoreMath.cpp:721
The above operation failed in interpreter.
Traceback (most recent call last):
File "/home/user/anaconda3/envs/py38/lib/python3.8/site-packages/torch_scatter/scatter.py", line 22
size[dim] = int(index.max()) + 1
out = torch.zeros(size, dtype=src.dtype, device=src.device)
return out.scatter_add_(dim, index, src)
~~~~~~~~~~~~~~~~ <--- HERE
else:
return out.scatter_add_(dim, index, src)