forked from snap-stanford/roland
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.py
26 lines (18 loc) · 818 Bytes
/
example.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
import torch.nn as nn
from graphgym.register import register_head
class ExampleNodeHead(nn.Module):
'''Head of GNN, node prediction'''
def __init__(self, dim_in, dim_out):
super(ExampleNodeHead, self).__init__()
self.layer_post_mp = nn.Linear(dim_in, dim_out, bias=True)
def _apply_index(self, batch):
if batch.node_label_index.shape[0] == batch.node_label.shape[0]:
return batch.node_feature[batch.node_label_index], batch.node_label
else:
return batch.node_feature[batch.node_label_index], \
batch.node_label[batch.node_label_index]
def forward(self, batch):
batch = self.layer_post_mp(batch)
pred, label = self._apply_index(batch)
return pred, label
register_head('example', ExampleNodeHead)