"git@developer.sourcefind.cn:danggl/opencfd-scu.git" did not exist on "c62d2359d8d5891e75739da08fdbe351fb88bfb8"
model.py 1.38 KB
Newer Older
1
2
3
import torch.nn as nn
import torch.nn.functional as F

4
5
6
from dgl.nn.pytorch import GraphConv


7
8
9
10
11
12
13
14
15
16
17
18
19
class GCN(nn.Module):
    def __init__(self, g, in_feats, n_hidden, n_classes, activation, dropout):
        super(GCN, self).__init__()
        self.g = g
        self.gcn_1 = GraphConv(in_feats, n_hidden, activation=activation)
        self.gcn_2 = GraphConv(n_hidden, n_classes)
        self.dropout = nn.Dropout(p=dropout)

    def forward(self, features):
        h = self.gcn_1(self.g, features)
        h = self.dropout(h)
        preds = self.gcn_2(self.g, h)
        return preds
20

21
22
23
24
25
26
27
28
29
30
31
32
33
    def embed(self, inputs):
        h_1 = self.gcn_1(self.g, inputs)
        return h_1.detach()


class RECT_L(nn.Module):
    def __init__(self, g, in_feats, n_hidden, activation, dropout=0.0):
        super(RECT_L, self).__init__()
        self.g = g
        self.gcn_1 = GraphConv(in_feats, n_hidden, activation=activation)
        self.fc = nn.Linear(n_hidden, in_feats)
        self.dropout = dropout
        nn.init.xavier_uniform_(self.fc.weight.data)
34

35
36
37
38
39
    def forward(self, inputs):
        h_1 = self.gcn_1(self.g, inputs)
        h_1 = F.dropout(h_1, p=self.dropout, training=self.training)
        preds = self.fc(h_1)
        return preds
40

41
42
43
    # Detach the return variables
    def embed(self, inputs):
        h_1 = self.gcn_1(self.g, inputs)
44
        return h_1.detach()