Thank you @mufeili, I will check your points!
Hi @mufeili
Thanks a lot for this classification code. I have a doubt regarding the dimensions fed to the GATclassifier (1,16,8,trainset.num_classes), why are the input dimensions always 1 and gives a size mismatch error on changing it to a higher value. My data has 68 graphs with 264 nodes and 19 features per node. In this case the forward function in GATlayer, should have dimensions of βhβ as VxF (68x264*19) right?, but it gives me [264,1]. Could you please help me understand how is the code incorporating node features in the model, or am I missing something here, as I do not get the VxF feature dimensions with any variable?
Thanks a lot.
You can change in_dim
to the size of your node features. 1 is only for a demo. For 68 graphs with 264 nodes and 19 features per node, the dimension of βhβ will be (68 * 264, 19). Have you read our user guide on graph classification?
Sorry, I misplaced the * for h dimensions in the last post. I am fairly new to deep learning and GNNs and really appreciate your help on this.
On changing the in_dim to 19 and running the code as it is, I still get size mismatch error as-
RuntimeError: size mismatch, m1: [2112 x 1], m2: [19 x 48] at /pytorch/aten/src/TH/generic/THTensorMath.cpp:41
Here 2112-batch size(8)xno.ofnodes(264) and 48-hid_dim(16)xno.of head(3)
I have gone through the graph classification tutorial of dgl that you referred to, but I am not clear on this command- h = bg.in_degrees().view(-1, 1).float() in the GATClassifier class of your code, why is it required?. On replacing it with the command- h = bg.ndata[βfeatβ].float() the code does run without size mismatch error, but it gives me NaN values in the prediction tensor after a few batches in an epoch.
Is the modified h initialization correct?
-
h = bg.in_degrees().view(-1, 1).float()
is simply used for demo purposes and you can replace it with any initial node features. In that case, you need to changein_dim
accordingly. - For NaN values, itβs likely due to a gradient explosion issue. You can try replacing the GATLayer with GATConv and see if the issue still exists.
@mufeili
I am using your GAT code for Graph classification
I have some questions:
My own dataset I have for each graph
1- Adjacency matrix
2-feature matrix
3-label matrix
I directly use them in the for loop on graphs
to cope with your code I first convert adjacency matrix to Graph
G = nx.from_scipy_sparse_matrix(adj1,create_using=nx.DiGraph())
bg=dgl.DGLGraph()
bg=dgl.from_networkx(G)
for features i have feature vector of 209 features for each node
I added it to the graph
bg.ndata[βhβ]=fs
then in forward function of GAT classifier
h=bg.ndata[βhβ]
Is that right ?
the code works but it gives nan values randomly in some runs
I need to try GATconv also would you please tell me where I can find its code as i could not find it in the link above
Many thanks for your help
You are using highly outdated APIs. Take a look at:
Thanks for your response
I am working on using dgl dataloader
But is the old way i use the reason for nan values ?
@mufeili
Iβm not sure. Perhaps you can provide a minimal script for reproducing the nan issues.
Hi @mufeili
I have graph datasets, where each graph has node and edge features, and each graphs belong to a target class (total of 10 classes). I want to use GATv2 for this classification problem. What do I need to change in your code? Only GATLayer to GATv2Conv?