-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathmodel.py
More file actions
43 lines (37 loc) · 1.12 KB
/
model.py
File metadata and controls
43 lines (37 loc) · 1.12 KB
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
37
38
39
40
41
42
43
import torch
from torch import nn
import torch.nn.functional as F
from .loss import PULoss
CONFIG_NAME = 'config.json'
WEIGHTS_NAME = 'pytorch_model.bin'
class PUModel(nn.Module):
"""
Basic Multi-layer perceptron as described in "Positive-Unlabeled Learning with Non-Negative Risk Estimator"
"""
def __init__(self):
super(PUModel, self).__init__()
self.fc1 = nn.Linear(784,300, bias=False)
self.bn1 = nn.BatchNorm1d(300)
self.fc2 = nn.Linear(300,300, bias=False)
self.bn2 = nn.BatchNorm1d(300)
self.fc3 = nn.Linear(300,300, bias=False)
self.bn3 = nn.BatchNorm1d(300)
self.fc4 = nn.Linear(300,300, bias=False)
self.bn4 = nn.BatchNorm1d(300)
self.fc5 = nn.Linear(300,1)
def forward(self, x):
x = x.view(x.size()[0], -1)
x = self.fc1(x)
x = self.bn1(x)
x = F.relu(x)
x = self.fc2(x)
x = self.bn2(x)
x = F.relu(x)
x = self.fc3(x)
x = self.bn3(x)
x = F.relu(x)
x = self.fc4(x)
x = self.bn4(x)
x = F.relu(x)
x = self.fc5(x)
return x