question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to copy a `torch_geometric.data.Data` object?

See original GitHub issue

❓ Questions & Help

I like the torch_geometric.data.Data object a lot, especially in combination with all the other neat stuff and the general apply function. One thing I am missing and currently have a stupid work-around for is the copying of such a data object.

E.g. the apply function does generate new torch.Tensor objects but overwrites the attributes of the existing Data object. So when I pass a Data object into a function and want to process the data without affecting the input object, I need to make a copy of the Data object.

Currently I am doing this via data = torch_geometric.data.Data.from_dict(data.to_dict()). My question is, is there a better way of doing this or a reason why there does not exist a copy method? Thanks for your input on this 😃

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
de-gozarucommented, Dec 27, 2021

Hi @rusty1s

Thanks for your answer, so If I install now PyG using

pip3 install https://github.com/pyg-team/pytorch_geometric.git@master

It should be ok, right?

1reaction
rusty1scommented, Jan 30, 2021

There is a Data.clone() to deep-copy a data object. Alternatively, copy.copy(data) and copy.deepcopy(data) should work just fine.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to copy a torch_geometric.data.Data object? #2050
There is a Data.clone() to deep-copy a data object. Alternatively, copy.copy(data) and copy.deepcopy(data) ...
Read more >
torch_geometric.data — pytorch_geometric documentation
A data object describing a heterogeneous graph, holding multiple node and/or ... if edge indices edge_index are sorted and do not contain duplicate...
Read more >
Data handling in PyTorch Geometric (Part 1) - YouTube
How is a graph represented in Pytorch Geometric? How one can handle collections of data ? This is the first of two tutorials...
Read more >
Graphein Protein Structure Dataloaders
The data object will be transformed before every access. ) Copy to clipboard. [6]:
Read more >
How to load in graph from networkx into PyTorch geometric ...
Then you name your input features x and your labels/ground truth y . The splitting of the data into train and test is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found