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

KeyError: 'graph' in Tutorials :Property Prediction #16

Closed
Yongrui-Wang opened this issue Aug 26, 2021 · 4 comments
Closed

KeyError: 'graph' in Tutorials :Property Prediction #16

Yongrui-Wang opened this issue Aug 26, 2021 · 4 comments
Labels
bug Something isn't working

Comments

@Yongrui-Wang
Copy link

Yongrui-Wang commented Aug 26, 2021

When running the following code

from torchdrug import utils
from torch.nn import functional as F
samples = []
categories = set()
for sample in valid_set:
    sample.pop("graph")
    category = tuple(sample.values())
    if category not in categories:
        categories.add(category)
        samples.append(sample)
samples = data.graph_collate(samples)
samples = utils.cuda(samples)

preds = F.sigmoid(task.predict(samples))
targets = task.target(samples)

titles = []
for pred, target in zip(preds, targets):
    pred = ", ".join(["%.2f" % p for p in pred])
    target = ", ".join(["%d" % t for t in target])
    titles.append("predict: %s\ntarget: %s" % (pred, target))
graph = samples["graph"]
graph.visualize(titles, figure_size=(3, 3.5), num_row=1)

The following error occurred:

Traceback (most recent call last):
  File "/home/ibmc-2/Projects/MNIST/mnist_data/5-2.py", line 46, in <module>
    preds = F.sigmoid(task.predict(samples))
  File "/home/ibmc-2/anaconda3/envs/td/lib/python3.8/site-packages/torchdrug-0.1.0-py3.8.egg/torchdrug/tasks/property_prediction.py", line 104, in predict
    graph = batch["graph"]
KeyError: 'graph'

Since I'm just getting started, the question may be absurd. Thank you

@KiddoZhu
Copy link
Member

Hi! I think the reason is due to the line sample.pop("graph"). You may try to remove this line and run it again.

We will also check this and update the tutorial accordingly.

@KiddoZhu KiddoZhu added the bug Something isn't working label Aug 26, 2021
@Yongrui-Wang
Copy link
Author

Thank you, we can copy the 'sample' dictionary 'sample_1', and using sample_1.pop("graph") to filter, but the dict "samples" which will be predicted add a complete "sample" with graph information

for sample in valid_set:
    sample_1 = sample.copy()
    sample_1.pop("graph")
    category = tuple(sample_1.values())
    if category not in categories:
        categories.add(category)
        samples.append(sample)

@KiddoZhu
Copy link
Member

Yes. That's a good idea. We will update this part in the tutorial.

@KiddoZhu
Copy link
Member

Fixed in a12bbd3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants