I’m stuck with this error and not able to rectify.
RuntimeError Traceback (most recent call last)
Cell In[40], line 38
35 edge_index = edge_index.to(device) # Move edge indices to device
36 batch_labels = batch_labels.to(device) # Move labels to device
—> 38 output = mil_model(batch_data, edge_index)
39 edl_outputs = edl_model(output)
40 test_loss += criterion(edl_outputs, batch_labels).item()
File ~\AppData\Local\anaconda3\lib\site-packages\torch\nn\modules\module.py:1130, in Module._call_impl(self, *input, **kwargs)
1126 # If we don’t have any hooks, we want to skip the rest of the logic in
1127 # this function, and just call forward.
1128 if not (self._backward_hooks or self._forward_hooks or self._forward_pre_hooks or _global_backward_hooks
1129 or _global_forward_hooks or _global_forward_pre_hooks):
→ 1130 return forward_call(*input, **kwargs)
1131 # Do not call functions when jit is used
1132 full_backward_hooks, non_full_backward_hooks = [], []
Cell In[28], line 81, in MILModel.forward(self, x, edge_index)
80 def forward(self, x, edge_index):
—> 81 x = self.gcn_fe_extractor(x, edge_index)
82 x = self.edl_model(x)
83 return x
File ~\AppData\Local\anaconda3\lib\site-packages\torch\nn\modules\module.py:1130, in Module._call_impl(self, *input, **kwargs)
1126 # If we don’t have any hooks, we want to skip the rest of the logic in
1127 # this function, and just call forward.
1128 if not (self._backward_hooks or self._forward_hooks or self._forward_pre_hooks or _global_backward_hooks
1129 or _global_forward_hooks or _global_forward_pre_hooks):
→ 1130 return forward_call(*input, **kwargs)
1131 # Do not call functions when jit is used
1132 full_backward_hooks, non_full_backward_hooks = [], []
Cell In[28], line 33, in GCNFeatureExtractor.forward(self, x, edge_index)
31 def forward(self, x, edge_index):
32 # Implement the forward pass of the GCN feature extractor
—> 33 x = self.conv1(x, edge_index)
34 x = torch.relu(x)
35 x = self.conv2(x, edge_index)
File ~\AppData\Local\anaconda3\lib\site-packages\torch\nn\modules\module.py:1130, in Module._call_impl(self, *input, **kwargs)
1126 # If we don’t have any hooks, we want to skip the rest of the logic in
1127 # this function, and just call forward.
1128 if not (self._backward_hooks or self._forward_hooks or self._forward_pre_hooks or _global_backward_hooks
1129 or _global_forward_hooks or _global_forward_pre_hooks):
→ 1130 return forward_call(*input, **kwargs)
1131 # Do not call functions when jit is used
1132 full_backward_hooks, non_full_backward_hooks = [], []
File ~\AppData\Local\anaconda3\lib\site-packages\torch_geometric\nn\conv\gcn_conv.py:210, in GCNConv.forward(self, x, edge_index, edge_weight)
208 cache = self._cached_edge_index
209 if cache is None:
→ 210 edge_index, edge_weight = gcn_norm( # yapf: disable
211 edge_index, edge_weight, x.size(self.node_dim),
212 self.improved, self.add_self_loops, self.flow, x.dtype)
213 if self.cached:
214 self._cached_edge_index = (edge_index, edge_weight)
File ~\AppData\Local\anaconda3\lib\site-packages\torch_geometric\nn\conv\gcn_conv.py:100, in gcn_norm(edge_index, edge_weight, num_nodes, improved, add_self_loops, flow, dtype)
98 row, col = edge_index[0], edge_index[1]
99 idx = col if flow == ‘source_to_target’ else row
→ 100 deg = scatter(edge_weight, idx, dim=0, dim_size=num_nodes, reduce=‘sum’)
101 deg_inv_sqrt = deg.pow_(-0.5)
102 deg_inv_sqrt.masked_fill_(deg_inv_sqrt == float(‘inf’), 0)
File ~\AppData\Local\anaconda3\lib\site-packages\torch_geometric\utils\scatter.py:74, in scatter(src, index, dim, dim_size, reduce)
72 if reduce == ‘sum’ or reduce == ‘add’:
73 index = broadcast(index, src, dim)
—> 74 return src.new_zeros(size).scatter_add_(dim, index, src)
76 if reduce == ‘mean’:
77 count = src.new_zeros(dim_size)
RuntimeError: index 5 is out of bounds for dimension 0 with size 5