-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmodel.py
36 lines (29 loc) · 1.3 KB
/
model.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 torch
import torch.nn as nn
import torch_geometric.nn as gnn
import torch.nn.functional as F
class GCN(nn.Module):
'''
“Semi-supervised Classification with Graph Convolutional Networks”
https://arxiv.org/abs/1609.02907
In paper, two layer
'''
def __init__(self, config, in_channels, out_channels):
'''
in_channels : num of node features
out_channels: num of class
'''
super().__init__()
self.config = config
self.hidden_dim = config.hidden_dim
self.dropout_rate = config.dropout_rate
self.conv1 = gnn.GCNConv(in_channels, self.hidden_dim, improved = False, cached=True, bias=True, normalize=True)
self.conv2 = gnn.GCNConv(self.hidden_dim, out_channels, improved = False, cached=True, bias=True, normalize=True)
def forward(self, data):
x, edge_index = data.x, data.edge_index
x = self.conv1(x, edge_index)
x = F.relu(x)
#x = F.dropout(x, p=self.dropout_rate) #If no drop out, accuracy 0.75 --> 0.80
x = self.conv2(x, edge_index)
#x = F.dropout(x, p=self.dropout_rate) #In, https://github.com/tkipf/gcn/blob/master/gcn/models.py , there are two dropout.. But performance bad.
return x