divelab / DIG

A library for graph deep learning research
https://diveintographs.readthedocs.io/
GNU General Public License v3.0
1.86k stars 281 forks source link

GraphCL graph-level task with GIN and GCN #178

Closed davidfstein closed 1 year ago

davidfstein commented 1 year ago

When trying to run GraphCL with GIN or GCN rather than ResGCN an error is produced.

For example

device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
print(device)
feat_dim = dataset[0].x.shape[1]
embed_dim = 128
epochs = 100
encoder = encoders.Encoder(feat_dim, embed_dim, n_layers=3, gnn='gin', node_level=False, graph_level=True)
encoder.double()
encoder.to(device)
graphcl = GraphCL(embed_dim, aug_1='dropN', aug_2='dropN', device=0)
evaluator = GraphSemisupervised(test_dataset, dataset, batch_size=4096)
evaluator.evaluate(learning_model=graphcl, encoder=encoder)

RuntimeError: mat1 and mat2 shapes cannot be multiplied (4096x384 and 128x128)

The GIN and GCN produce embed dim * n_layer sized output. But the projection head appears to expect embed dim sized input. Is it possible to use the GIN and GCN fro the graph-level tasks?

ycremar commented 1 year ago

Hi @davidfstein ,

GIN and GCN apply jumping knowledge by default. You can replace the embed_dim with embed_dim*n_layer in GraphCL() to make them work together. You can also refer to Cell [8] in this example .

Please let us know if you have any further questions! Thank you!

davidfstein commented 1 year ago

Thanks! Just to check my understanding, in the jumping knowledge paradigm, rather than combining each nodes representation with the aggregated representations from its neighbors after each layer, the aggregated representations are concatenated at the end, thus we get n_layers * embed_dim output? And this would also rely on self-loops being added right?