PyTorch Geometric TopKPooling with ValueError: too many values to unpack (expected 5)

When I run this Notebook https://github.com/khuangaf/PyTorch-Geometric-YooChoose/blob/master/YooChooseBuy.ipynb to learn Graph Neural Networks, I get the error ValueError: too many values to unpack (expected 5). I am new to PyTorch and graph neural networks. It seems this code worked before. I navigated the code and found the output is not right. It’s not a tuple or list with five elements. Can anyone tell me how to fix this?

torch.Size([2093, 256])
torch.Size([2093, 128])
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-49-fb44712a6f41> in <module>
      1 for epoch in range(1, 2):
----> 2     loss = train()
      3     train_acc = evaluate(train_loader)
      4     val_acc = evaluate(val_loader)
      5     test_acc = evaluate(test_loader)

<ipython-input-47-d6d407b09375> in train()
      6         data = data.to(device)
      7         optimizer.zero_grad()
----> 8         output = model(data)
      9 
     10         label = data.y.to(device)

C:\ProgramData\Miniconda3\envs\ptg\lib\site-packages\torch\nn\modules\module.py in _call_impl(self, *input, **kwargs)
    720             result = self._slow_forward(*input, **kwargs)
    721         else:
--> 722             result = self.forward(*input, **kwargs)
    723         for hook in itertools.chain(
    724                 _global_forward_hooks.values(),

<ipython-input-45-312d18271bec> in forward(self, data)
     38         x = F.relu(self.conv1(x, edge_index))
     39         print(x.shape)
---> 40         x, edge_index, _, batch, _ = self.pool1(x, edge_index, None, batch)
     41         # x = self.pool1(x, edge_index, None, batch)
     42         x1 = torch.cat([gmp(x, batch), gap(x, batch)], dim=1)

ValueError: too many values to unpack (expected 5)

I found the answer in issues by Diego Koz.

It is probably a change in TopKPooling, now the function returns

return x, edge_index, edge_attr, batch, perm, score[perm]

So it needs to be added another _ in the forward function. e.g.

x, edge_index, _, batch, _, _ = self.pool1(x, edge_index, None, batch)
instead of

x, edge_index, _, batch, _ = self.pool1(x, edge_index, None, batch)

1 Like