Skip to content

Instantly share code, notes, and snippets.

@rohithteja
Last active August 21, 2021 14:33
Show Gist options
  • Select an option

  • Save rohithteja/989dcea59a705f7b56d20e3e3e703d90 to your computer and use it in GitHub Desktop.

Select an option

Save rohithteja/989dcea59a705f7b56d20e3e3e703d90 to your computer and use it in GitHub Desktop.
Spektral GCN Model
import tensorflow as tf
from tensorflow.keras.losses import BinaryCrossentropy
from tensorflow.keras.optimizers import Adam
from spektral.models.gcn import GCN
seed = 42
tf.random.set_seed(seed=seed)
# We convert the binary masks to sample weights so that we can compute the
# average loss over the nodes (following original implementation by
# Kipf & Welling)
def mask_to_weights(mask):
return mask.type(torch.float32) / np.count_nonzero(mask)
weights_tr, weights_te = (mask_to_weights(mask) for mask in (train_mask, test_mask))
# instantiate the model
model = GCN(n_labels=dataset.n_labels,
n_input_channels=dataset.n_node_features)
model.compile(optimizer=Adam(learning_rate),
loss=BinaryCrossentropy(reduction="sum"),
weighted_metrics=["acc"])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment