HOYIN
HOYIN

Reputation: 21

Any method to transform 'DGL.heterograph' to 'torch_geometric' graph?

I'm using dgl library since it was easy to understand.. But I need several modules in torch_geometric, but they don't support dgl graph.

Is there any way to change dgl graph to torch_geometric graph? My datasets are built in dgl graph, and I'm gonna change them into torch_geometric graph when I load the dataset.

Upvotes: 1

Views: 2756

Answers (1)

Sparky05
Sparky05

Reputation: 4892

With a homogenous networkx graph as intermediate step, you could use the following methods:

  1. dgl.to_homogenous to create a homogenous dgl graph instance
  2. dgl.to_networkx to export the homogenous graph to a networkx graph
  3. torch_geometric.utils.from_networkx to read the homogenous networkx graph into pytorch geometric
  4. torch_geometric.data.to_heterogenous to transform the homogenous graph into a heterogenous graph

As far as I saw neither of the packages has separate reader/writer for the heterogenous graphs. Hence, these extra steps are needed. Another alternative is the manual export of the tensor and the direct creation of the heterogenous pytorch geometric graph.

Upvotes: 0

Related Questions