-
Notifications
You must be signed in to change notification settings - Fork 4
/
maml.py
42 lines (34 loc) · 1.03 KB
/
maml.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
37
38
39
40
41
import torch
import torch.nn as nn
# from torchsummary import summary
class Maml(nn.Module):
def __init__(self):
super(Maml, self).__init__()
self.conv_layer = nn.Sequential(
nn.BatchNorm2d(1),
nn.ReLU(),
nn.Conv2d(1, 64, 3, padding=1),
nn.BatchNorm2d(64),
nn.ReLU(),
nn.Conv2d(64, 64, 3, padding=1),
nn.BatchNorm2d(64),
nn.ReLU(),
nn.Conv2d(64, 64, 3, padding=1),
nn.BatchNorm2d(64),
nn.ReLU(),
nn.Conv2d(64, 64, 3, padding=1),
)
self.linear_layer = nn.Sequential(
nn.Linear(64 * 28 * 28, 1024),
nn.Sigmoid(),
nn.Dropout(0.5),
nn.Linear(1024, 5),
)
def forward(self, x):
x = self.conv_layer(x)
x = x.view(-1, 64 * 28 * 28)
x = self.linear_layer(x)
return x
if __name__ == "__main__":
maml = Maml()
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")