def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.gcn0 = GCN(16, activation=tf.nn.relu, kernel_regularizer=L1L2(l2=l2_coef)) self.gcn1 = GCN(num_classes, kernel_regularizer=L1L2(l2=l2_coef)) self.dropout = tf.keras.layers.Dropout(drop_rate)
def __init__(self, num_clusters_list, num_features_list, num_classes, *args, **kwargs): super().__init__(*args, **kwargs) self.diff_pools = [] for num_features, num_clusters in zip(num_features_list, num_clusters_list): diff_pool = DiffPool(feature_gnn=GCN(num_features), assign_gnn=GCN(num_clusters), units=num_features, num_clusters=num_clusters, activation=tf.nn.relu) self.diff_pools.append(diff_pool) self.mlp = tf.keras.Sequential( [tf.keras.layers.Dropout(0.5), tf.keras.layers.Dense(num_classes)])
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.gcns = [] self.sag_pools = [] for _ in range(3): self.gcns.append(GCN(128, activation=tf.nn.relu)) self.sag_pools.append( SAGPool(score_gnn=GCN(1), ratio=0.5, score_activation=tf.nn.tanh)) self.mlp = tf.keras.Sequential([ tf.keras.layers.Dense(128, activation=tf.nn.relu), tf.keras.layers.Dropout(0.5), tf.keras.layers.Dense(64, activation=tf.nn.relu), tf.keras.layers.Dense(num_classes) ])
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) activations = [ tf.nn.relu if i < len(units_list) - 1 else None for i in range(len(units_list)) ] self.gcns = [ GCN(units=units, activation=activation) for units, activation in zip(units_list, activations) ] self.dropout = Dropout(drop_rate)
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.gcns = [] self.asaps = [] for _ in range(3): self.gcns.append(GCN(64, activation=tf.nn.relu)) self.asaps.append(ASAP(ratio=0.5, drop_rate=0.1)) self.mlp = tf.keras.Sequential([ tf.keras.layers.Dense(64, activation=tf.nn.relu), tf.keras.layers.Dropout(0.5), tf.keras.layers.Dense(num_classes) ])
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.gcns = [GCN(128, activation=tf.nn.relu) for _ in range(3)] self.k = 30 self.sort_pool = SortPool(k=self.k) self.conv1d = tf.keras.layers.Conv1D(128, 5, activation=tf.nn.relu) self.flatten = tf.keras.layers.Flatten() self.mlp = tf.keras.Sequential([ tf.keras.layers.Dense(128, activation=tf.nn.relu), tf.keras.layers.Dropout(0.5), # tf.keras.layers.Dense(64, activation=tf.nn.relu), tf.keras.layers.Dense(num_classes) ])
# coding=utf-8 import os os.environ["CUDA_VISIBLE_DEVICES"] = "0" import tensorflow as tf from tensorflow import keras from tf_geometric.datasets.cora import CoraDataset from tf_geometric.layers import GCN graph, (train_index, valid_index, test_index) = CoraDataset().load_data() num_classes = graph.y.shape[-1] gcn0 = GCN(32, activation=tf.nn.relu) gcn1 = GCN(num_classes) def forward(graph): h = gcn0([graph.x, graph.edge_index, graph.edge_weight], cache=graph.cache) h = gcn1([h, graph.edge_index, graph.edge_weight], cache=graph.cache) return h def compute_losses(logits, mask_index): masked_logits = tf.gather(logits, mask_index) masked_labels = tf.gather(graph.y, mask_index) losses = tf.nn.softmax_cross_entropy_with_logits(logits=masked_logits, labels=masked_labels) return losses def evaluate():