Help - GraphDataset creation for model trainning

I’m trying to create a GraphDataset to be trained at the graph-level, similar to what was done in the tutorial (Training a GNN for Graph Classification — DGL 1.2 documentation).

I have two adjacency matrices that contain the values of bidirectional edges for 2 graphs. The edges and edge values will be the same for all graphs, while the general ‘label’ of the graph (not the nodes) and the values placed on each node will differ.

I’m trying to create two sets of graphs to perform the training. However, I’m having trouble making my dataset have the necessary attributes for training because it is a list (for example, dataset.dim_nfeats, dataset.gclasses, etc., don’t work).

Below is the very simple function I’m using to try to accomplish this. The values for each node are extracted from each column of a row in the dataframe, as shown below.

Could someone please help me?

> #Transforming them into a torch tensor adjucancy matrix
> 
> adj_od = torch.tensor(matod)
> 
> adj_oe = torch.tensor(matoe)
> 
> #Separating initial and ending point for each node to create graphs with edges
> 
> src_od, dst_od = torch.where(adj_od !=0)
> 
> src_oe, dst_oe = torch.where(adj_oe !=0)
> 
> #Creating graph with points
> 
> graphOD = dgl.graph((src_od, dst_od))
> 
> graphOE = dgl.graph((src_oe, dst_oe))
> 
> dod and doe are the dataframes for OD and for OE
> 
> def graphs_classif(df, G):
> 
>     graphs = []
> 
>     for row in range(len(df)):
> 
>         values = df.iloc[row, 3:].values.tolist()
> 
>         label = df.iloc[row, 0]
> 
>         graph_copy = G.clone()
> 
>        
> 
>         if label == 0:
> 
>             graph_copy.ndata['label'] = torch.zeros(54)
> 
>         else:
> 
>             graph_copy.ndata['label'] = torch.ones(54)
> 
>   
>         node_weights = torch.tensor(values)
> 
>         graph_copy.ndata['node_weight'] = node_weights
> 
>         graphs.append(graph_copy)
> 
>     return graphs

Thanks!

Hi @douglascosta100, you can follow https://docs.dgl.ai/en/latest/tutorials/blitz/6_load_data.html to create a dataset for graph classification tasks.

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