-
Notifications
You must be signed in to change notification settings - Fork 6
/
gcn.py
40 lines (28 loc) · 962 Bytes
/
gcn.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import ipdb
import torch
import torch.nn as nn
import torch.nn.functional as F
from torch_geometric.nn import GCNConv
class GCN(nn.Module):
def __init__(self, nfeat, nhid, nclass, dropout):
super(GCN, self).__init__()
self.body = GCN_Body(nfeat,nhid,dropout)
self.fc = nn.Linear(nhid, nclass)
for m in self.modules():
self.weights_init(m)
def weights_init(self, m):
if isinstance(m, nn.Linear):
torch.nn.init.xavier_uniform_(m.weight.data)
if m.bias is not None:
m.bias.data.fill_(0.0)
def forward(self, x, edge_index):
x = self.body(x, edge_index)
x = self.fc(x)
return x
class GCN_Body(nn.Module):
def __init__(self, nfeat, nhid, dropout):
super(GCN_Body, self).__init__()
self.gc1 = GCNConv(nfeat, nhid)
def forward(self, x, edge_index):
x = self.gc1(x, edge_index)
return x