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

**URL:** <https://discuss.pytorch.org/t/pytorch-geometric-topkpooling-with-valueerror-too-many-values-to-unpack-expected-5/96035>\
**Category:** Uncategorized\
**Created:** [September 12, 2020, 3:29pm UTC](https://discuss.pytorch.org/t/pytorch-geometric-topkpooling-with-valueerror-too-many-values-to-unpack-expected-5/96035 "2020-09-12T15:29:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Papertiger\_Hunter](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/papertiger_hunter/32/28714_2.png) [@Papertiger\_Hunter](https://discuss.pytorch.org/u/Papertiger_Hunter)\
**Post date:** [September 12, 2020, 3:29pm UTC](https://discuss.pytorch.org/t/pytorch-geometric-topkpooling-with-valueerror-too-many-values-to-unpack-expected-5/96035/1 "2020-09-12T15:29:12Z")

</div>

When I run this Notebook [https://github.com/khuangaf/PyTorch-Geometric-YooChoose/blob/master/YooChooseBuy.ipynb](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?

```auto
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)

```

---

<div class="post-metadata">

**Author:** ![Papertiger\_Hunter](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/papertiger_hunter/32/28714_2.png) [@Papertiger\_Hunter](https://discuss.pytorch.org/u/Papertiger_Hunter)\
**Post date:** [September 12, 2020, 3:36pm UTC](https://discuss.pytorch.org/t/pytorch-geometric-topkpooling-with-valueerror-too-many-values-to-unpack-expected-5/96035/2 "2020-09-12T15:36:22Z")

</div>

I found the answer in issues by Diego Koz.

It is probably a change in [TopKPooling](https://pytorch-geometric.readthedocs.io/en/latest/_modules/torch_geometric/nn/pool/topk_pool.html#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)`
