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

How to convert pyTorch-Geometric custom datasets into DeepSnap datasets? #44

Open
ajith01 opened this issue Feb 25, 2022 · 1 comment
Open

Comments

@ajith01
Copy link

ajith01 commented Feb 25, 2022

Hello,

I am trying to use a custom dataset for link prediction,
What i tried was

pyg_dataset = My_Own_Dataset()
graphs1 = GraphDataset.pyg_to_graphs(pyg_dataset) #error here

but i am getting an error: TypeError: zip argument #2 must support iteration

The full error is

/usr/local/lib/python3.7/dist-packages/deepsnap/dataset.py in pyg_to_graphs(dataset, verbose, fixed_split, tensor_backend, netlib)
   1280                     netlib=netlib
   1281                 )
-> 1282                 for data in dataset
   1283             ]
   1284 

/usr/local/lib/python3.7/dist-packages/deepsnap/dataset.py in <listcomp>(.0)
   1280                     netlib=netlib
   1281                 )
-> 1282                 for data in dataset
   1283             ]
   1284 

/usr/local/lib/python3.7/dist-packages/deepsnap/graph.py in pyg_to_graph(data, verbose, fixed_split, tensor_backend, netlib)
   2025             if Graph._is_node_attribute(key):
   2026                 if not tensor_backend:
-> 2027                     Graph.add_node_attr(G, key, value)
   2028                 else:
   2029                     attributes[key] = value

/usr/local/lib/python3.7/dist-packages/deepsnap/graph.py in add_node_attr(G, attr_name, node_attr)
   1909         # TODO: Better method here?
   1910         node_list = list(G.nodes)
-> 1911         attr_dict = dict(zip(node_list, node_attr))
   1912         deepsnap._netlib.set_node_attributes(G, attr_dict, name=attr_name)
   1913 

TypeError: zip argument #2 must support iteration

I have also tried to do this using networkx and converting it to a pyg graph and converting from there, in that case I get a different error .

This error doesn't happen when I am using a graph in Planetoid as in the Link prediction with DeepSnap example colab notebook.

What could be causing this problem? Is there a guide on how I can use custom data on DeepSnap?

Thank you for your help!

@Syzseisus
Copy link

This is not only for custom data, but also PyG data which has not node features: IMDB-b.

What I tried was:

pyg_dataset = torch_geometric.datasets.TUDataset('./imdb-b', 'IMDB-BINARY')
graphs = deepsnap.dataset.pyg_to_graphs(pyg_dataset)

And the full error is:

Traceback (most recent call last):
  File "cw224.py", line 39, in <module>
    graphs = GraphDataset.pyg_to_graphs(pyg_dataset)
  File "/opt/conda/envs/PR/lib/python3.8/site-packages/deepsnap/dataset.py", line 1276, in pyg_to_graphs
    return [
  File "/opt/conda/envs/PR/lib/python3.8/site-packages/deepsnap/dataset.py", line 1277, in <listcomp>
    Graph.pyg_to_graph(
  File "/opt/conda/envs/PR/lib/python3.8/site-packages/deepsnap/graph.py", line 2027, in pyg_to_graph
    Graph.add_node_attr(G, key, value)
  File "/opt/conda/envs/PR/lib/python3.8/site-packages/deepsnap/graph.py", line 1911, in add_node_attr
    attr_dict = dict(zip(node_list, node_attr))
TypeError: 'int' object is not iterable

I thought 'int' object is maybe 'node_attr', so I transformed dataset like:

transform = torch_geometric.transforms.Compose([T.Constant(value=-1), T.Constant(value=-2)])
pyg_dataset = torch_geometric.datasets.TUDataset('./imdb-b', 'IMDB-BINARY', transform=transform)
graphs = deepsnap.dataset.pyg_to_graphs(pyg_dataset)

but I got the same error.

Thank you for your help!

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