Converting networkx graph to PyG Data issue.
See original GitHub issue🐛 Bug
Converting nx.DiGraph to Data raises ValueError: only one element tensors can be converted to Python scalars
98 for key, item in data.items():
---> 99 data[key] = torch.tensor(item)
100
101 data['edge_index'] = edge_index
To Reproduce
Steps to reproduce the behavior:
- Convert PyG Data to a networkx Graph using
pytorch_geometric.utils.to_networkx
providing edge attributes as a parameter. - Try to convert it back to PyG Data.
from_networkx(to_networkx(pyg_graph, node_attrs=['pos', 'x'], edge_attrs=['edge_attr']))
Expected behavior
I would expect it to work properly. Also there is no possibility now to convert graph features to nx.Graph
and back.
Environment
- OS: Ubuntu 18.04.1 LTS
- Python version: 3.6.9
- PyTorch version: 1.1.0
- CUDA/cuDNN version: 10.0.130
- GCC version: 7.4.0
- Any other relevant information: N/A
Additional context
N/A
Issue Analytics
- State:
- Created 4 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Converting networkx graph to PyG Data issue. #685 - GitHub
Convert PyG Data to a networkx Graph using pytorch_geometric.utils.to_networkx providing edge attributes as a parameter. · Try to convert it back ...
Read more >Converting to and from other data formats - NetworkX
Functions to convert NetworkX graphs to and from other formats. The preferred way of converting data to a NetworkX graph is through the...
Read more >How to load in graph from networkx into PyTorch geometric ...
The easiest way is to add all information to the networkx graph and directly create it in the way you need it. I...
Read more >torch_geometric.utils — pytorch_geometric documentation
Converts a graph given by edge indices and edge attributes to a scipy sparse matrix. ... Graph if to_undirected is set to True...
Read more >How to retain node ordering when converting graph from ...
... to retain the node ordering/labels when converting a graph from networkx ... -f https://data.pyg.org/whl/torch-1.10.0+cpu.html from torch_geometric.nn ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Fixed in master! Sorry 😃
Edit: Steps to reproduce:
I have converted it into a homogenous Networkx graph and now all nodes/edges are in integers. However, I can’t find any documentation on the Networkx homogenous -> heterogenous conversion. Do we have to implement this on our own with the Networkx modules from scratch?