Creating DGLGraph for Graph Classification

Hello, I’m quite new to dgl, therefore I have a question, hope you don’t mind :slight_smile:

Imagine, having a graphs with weights implemented in networkx and also the corresponding labels for them (let’s say stored in a list).


import networkx as nx
import dgl
import torch

labels = [0,1]

G1=nx.Graph()
G1.add_edge(0,1,weight=0.1)
G1.add_edge(0,2,weight=0.2)
G1.add_edge(2,3,weight=0.3)

G2=nx.Graph()
G2.add_edge(0,2,weight=0.4)
G2.add_edge(0,1,weight=0.5)
G2.add_edge(0,3,weight=0.6)

dgl_G1 = dgl.DGLGraph()
dgl_G1.from_networkx(G1, edge_attrs=['weight']) 

dgl_G2 = dgl.DGLGraph()
dgl_G2.from_networkx(G2, edge_attrs=['weight'])

Is it somehow possible to assign labels to the dgl.DGLGraph() graph when it is already created (as in the example above)? Many thanks!

Are there any suggestions?

Hi @ds-muzalevskiy. You can assign label to the node data of a DGLGraph, i.e., dgl_G1.ndata['label'] = torch.tensor(label).

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.