-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmodels.py
30 lines (24 loc) · 1.04 KB
/
models.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
import torch
import torch.nn as nn
# multi-layer perceptron classifier
class MLP(nn.Module):
def __init__(self,
input_dims:int,
num_classes:int):
"""[Multi-layer Perceptron classifier]
Args:
input_dims (int): [dimension of inputs]
num_classes (int): [number of output classes]
"""
super(MLP, self).__init__()
self.classifier = nn.Sequential(nn.BatchNorm1d(input_dims),
nn.Dropout(p=0.25, inplace=False),
nn.Linear(input_dims, 512, bias=False),
nn.ReLU(inplace=True),
nn.BatchNorm1d(512),
nn.Dropout(p=0.5, inplace=False),
nn.Linear(512, num_classes, bias=False))
def forward(self, x):
assert isinstance(x, torch.Tensor)
out = self.classifier(x)
return out