Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

index_select() received an invalid combination of arguments #2

Closed
elissaross opened this issue Feb 21, 2020 · 2 comments
Closed

index_select() received an invalid combination of arguments #2

elissaross opened this issue Feb 21, 2020 · 2 comments

Comments

@elissaross
Copy link

Hello!

I'm trying to run the MNIST example, but running into the following error. Any insights?

`---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
in
82
83 for epoch in range(1, 20):
---> 84 loss = train(epoch)
85 train_acc = test(train_loader)
86 test_acc = test(test_loader)

in train(epoch)
59 # data = rotation_2(data)
60 print(data.edge_index)
---> 61 output = model(data)
62 loss = F.nll_loss(output, data.y)
63 loss.backward()

/opt/tljh/user/lib/python3.6/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)

in forward(self, data)
24 def forward(self, data):
25 for i in range(self.layers_num):
---> 26 data.x = self.conv_layers[i](data.x, data.pos, data.edge_index)
27
28 if self.use_cluster_pooling:

/opt/tljh/user/lib/python3.6/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)

in forward(self, x, pos, edge_index)
22 edge_index = add_self_loops(edge_index, num_nodes=x.size(0)) # num_edges = num_edges + num_nodes
23
---> 24 return self.propagate(edge_index=edge_index, x=x, pos=pos, aggr='add') # [N, out_channels, label_dim]
25
26 def message(self, pos_i, pos_j, x_j):

~/.local/lib/python3.6/site-packages/torch_geometric/nn/conv/message_passing.py in propagate(self, edge_index, size, **kwargs)
165 assert len(size) == 2
166
--> 167 kwargs = self.collect(edge_index, size, kwargs)
168
169 msg_kwargs = self.distribute(self.msg_params, kwargs)

~/.local/lib/python3.6/site-packages/torch_geometric/nn/conv/message_passing.py in collect(self, edge_index, size, kwargs)
113
114 self.set_size(size, idx, data)
--> 115 out[arg] = data.index_select(self.node_dim, edge_index[idx])
116
117 size[0] = size[1] if size[0] is None else size[0]

TypeError: index_select() received an invalid combination of arguments - got (int, NoneType), but expected one of:

  • (name dim, Tensor index)
    didn't match because some of the arguments have invalid types: (!int!, !NoneType!)
  • (int dim, Tensor index)
    didn't match because some of the arguments have invalid types: (int, !NoneType!)`
@viduzz84
Copy link

viduzz84 commented Feb 26, 2020

Hi
I ran into the same problem these days and finally discover that the function add_self_loops in graph_conv.py, line 28, returns two arguments and you need the first one, so modify the call with:
edge_index, _ = add_self_loops(edge_index, num_nodes=x.size(0))

@elissaross
Copy link
Author

Yes! I discovered the same fix -- thanks for your comment!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants