Shape mismatch in GCN for graph regression

I want to train a GCN for graph regression, but keep running into shape errors. This is the google colab MWE script. There are two nodal features (both scalars), and a label (also scalar).

I’m focused on the ‘in features’ and ‘h features’ parameters of the GCN, and the batch size. The only combination that avoids errors is both GCN parameters being equal to the number of nodes (which is constant), and batch size = 1.

If either batch size isn’t 1, or ‘in features’ isn’t the number of nodes, some mat1 and mat2 shapes cannot be multiplied [...] error happens in one of the convolutions on the forward method. And when the ‘h features’ isn’t the number of nodes, some Expect number of features to match number of nodes (len(u)). Got [x] and [y] instead error happens.

I’m confused. What is the right combination of parameters for my case and why?

1 Like

I think this issue arises because you may not have understood the requirements of the DGL model for data input. For the data input, you must ensure that each node in the graph corresponds to a feature. Also, you can only perform training when the batch size is set to 1, which I believe is due to DGL’s training being performed on the DGLGraph data structure. Therefore, if you want to change your batch size, one possible solution is to perform additional operations in the collate_fn function(This is just my immature idea). You can refer to this link for more details about data input.

1 Like

At first, I disagreed with the interpretation the each node is a feature. But I guess in the case of graph regression this makes sense. The detail regarding DGL, however, is that when the conv errors with ‘Expect number of features to match number of nodes (len(u)). Got [x] and [y] instead.’, it’s actually referring to the batched graph, so the correct number of features should be [number of nodes in graph] * [batch size]. In my opinion, this is a bit misleading. From my point of view as a user, whenever I read ‘graph’ I imagine the ones in my dataset, not the internal batched representation with a different node count.

Either way, I solved the problem. Both GCN parameters must be [number of nodes] * [batch size]. And the GraphDataLoader ‘drop_last = True’ kwarg needs to be used to avoid the feature count error in the last batch, since it ends up having a different node count from the rest because of the different number of graphs that are included in this last batch.

2 Likes

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