Last active
May 17, 2021 20:48
-
-
Save sidneyarcidiacono/56615b0d6ae6ba7ac5de6c54917a94c2 to your computer and use it in GitHub Desktop.
Building our GCN model with subclassing using Spektral/Keras
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Now, we can use model subclassing to define our model: | |
class ProteinsGNN(Model): | |
def __init__(self, n_hidden, n_labels): | |
super().__init__() | |
# Define our GCN layer with our n_hidden layers | |
self.graph_conv = GCNConv(n_hidden) | |
# Define our global pooling layer | |
self.pool = GlobalSumPool() | |
# Define our dropout layer, initialize dropout freq. to .5 (50%) | |
self.dropout = Dropout(0.5) | |
# Define our Dense layer, with softmax activation function | |
self.dense = Dense(n_labels, 'softmax') | |
# Define class method to call model on input | |
def call(self, inputs): | |
out = self.graph_conv(inputs) | |
out = self.dropout(out) | |
out = self.pool(out) | |
out = self.dense(out) | |
return out |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment