Skip to content

Instantly share code, notes, and snippets.

@rohithteja
Created August 10, 2021 11:37
Show Gist options
  • Save rohithteja/f27bbf24822c6988046371630ddcde2a to your computer and use it in GitHub Desktop.
Save rohithteja/f27bbf24822c6988046371630ddcde2a to your computer and use it in GitHub Desktop.
Graph Convolutional Network
import torch.nn as nn
import torch.nn.functional as F
from torch_geometric.nn import GCNConv
# GCN model with 2 layers
class Net(torch.nn.Module):
def __init__(self):
super(Net, self).__init__()
self.conv1 = GCNConv(data.num_features, 16)
self.conv2 = GCNConv(16, int(data.num_classes))
def forward(self):
x, edge_index = data.x, data.edge_index
x = F.relu(self.conv1(x, edge_index))
x = F.dropout(x, training=self.training)
x = self.conv2(x, edge_index)
return F.log_softmax(x, dim=1)
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
data = data.to(device)
model = Net().to(device)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment