I use the code in the forum to transfer the networkx graph to DGL heterogeneous graph, but I get some problems here,
nxg = nx.DiGraph(...)
g = dgl.graph(nxg)
g.ndata[dgl.NTYPE] = ... # assign node types from nxg
g.edata[dgl.ETYPE] = ... # assign edge types from nxg
ntypes = [...] # name of each node type ID
etypes = [...] # name of each edge type ID
hg = dgl.to_hetero(g, ntypes, types)
edge_features = nx.get_edge_attributes(nxg, 'weight')
print(edge_features)
for etype in hg.canonical_etypes:
nxg_edge_ids = hg.edges[etype].data[dgl.EID]
hg.edges[etype].data['edge_weight'] = [edge_features[i.item()] for i in nxg_edge_ids]
It won’t work, because the edge_features return by networkx is index with two nodes, like (node1, node2): feature
, can DGL accept this format instead of the edge id?