Skip to content

Instantly share code, notes, and snippets.

@lightaime
Created September 8, 2022 17:57
Show Gist options
  • Save lightaime/d04e34770136e07d0143496880210ea6 to your computer and use it in GitHub Desktop.
Save lightaime/d04e34770136e07d0143496880210ea6 to your computer and use it in GitHub Desktop.
import copy
import torch.nn.functional as F
from torch_geometric.nn import (
Aggregation,
MaxAggregation,
MeanAggregation,
MultiAggregation,
SAGEConv,
SoftmaxAggregation,
StdAggregation,
SumAggregation,
VarAggregation,
)
class GNN(torch.nn.Module):
def __init__(self, hidden_channels, aggr='mean', aggr_kwargs=None):
super().__init__()
self.conv1 = SAGEConv(
dataset.num_node_features,
hidden_channels,
aggr=aggr,
aggr_kwargs=aggr_kwargs,
)
self.conv2 = SAGEConv(
hidden_channels,
dataset.num_classes,
aggr=copy.deepcopy(aggr),
aggr_kwargs=aggr_kwargs,
)
def forward(self, x, edge_index):
x = self.conv1(x, edge_index)
x = x.relu()
x = F.dropout(x, p=0.5, training=self.training)
x = self.conv2(x, edge_index)
return x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment