danielegrattarola / spektral

Graph Neural Networks with Keras and Tensorflow 2.
https://graphneural.network
MIT License
2.36k stars 334 forks source link

Pooling examples #9

Closed abiricz closed 4 years ago

abiricz commented 5 years ago

Hi!

I would be really grateful if you could show me an example how to use pooling in graph neural networks, for example the topKpool or the MinCutPool. I have just made a good network with spektral, but to make steps forward I would need to do some pooling.

After some experiment I found that the MinCutPool does not provide better score (it is working really bad) and the topKpool is not working for me due to rank problems.

Thank you for your help in advance!

András

danielegrattarola commented 5 years ago

Hi András,

I've been sitting on these examples for a while now, thanks for pushing me to finally putting them online. Have a look at:

MinCutPool's implementation is still limited to single and batch mode, but it should work fine. If you get a worse performance using pooling, then it's likely that your problem is not suitable for pooling. Can you post the error that you get with TopKPool?

Cheers, Daniele

thegodone commented 5 years ago

Do you also have an example for regression ?

abiricz commented 5 years ago

Hi!

Thanks for the quick reply. I am using the networks in batch mode with quite large batch size (512-1024-2048). I have a very large number of samples, so in order to learn much faster, I need this batch size. Therefore, the MinCutPool is maybe not an option for me.

For the TopKPool, I use this line of code for example:

gc = APPNP(128, 64, H=2, activation='relu' )([gc, norm_adj_in]) gc_new, adjnew, = TopKPool(0.7)([gc, adj_in])

where the (norm_)adj_in is the (normalized) adjacency matrix input and the gc is the node feature map after few layers. The error I get is the following:

ValueError: Shapes must be equal rank, but are 2 and 1 for 'top_k_pool_3/ScatterUpdate' (op: 'ScatterUpdate') with input shapes: [?], [?], [?,1].

Thank you for the help in advance!

Regards, András

danielegrattarola commented 5 years ago

@abiricz I have already encountered that error, and it should be fixed in the latest version. Try to pull from Github or run pip install -U spektral to update the code.

danielegrattarola commented 5 years ago

@thegodone you should be able to re-purpose the same network by changing the last Dense layer's activation from sigmoid to linear. Have a look at the examples

FilippoMB commented 5 years ago

@abiricz can I ask what kind of task are you working on? I am asking because APPNP is originally conceived for node classification (or regression), as it averages the logits computed for each node within the graph neighborhood. However, if you are trying to inference a single value for each node, I can't see the advantage of using a pooling layer. An exception is if you are making a sort of autoencoder structure and you also perform un-pooling afterwards to go back in the original node space.

abiricz commented 5 years ago

I made some experiments in graph regression, one or more outputs for a graph.