Skip to content

Instantly share code, notes, and snippets.

@sidneyarcidiacono
Last active May 17, 2021 20:48
Show Gist options
  • Save sidneyarcidiacono/56615b0d6ae6ba7ac5de6c54917a94c2 to your computer and use it in GitHub Desktop.
Save sidneyarcidiacono/56615b0d6ae6ba7ac5de6c54917a94c2 to your computer and use it in GitHub Desktop.
Building our GCN model with subclassing using Spektral/Keras
# 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