-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.py
86 lines (64 loc) · 2.25 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import torch
from torch import nn
import torch.nn.functional as F
def modelloader(modelname):
modelloaders = {"mini" : mini,
"mini_no_setup" : mini_no_setup,
"small_no_batch_norm" : small_no_batch_norm,
"small" : small,
"medium": medium,
"large" : large}
return modelloaders[modelname]
# for cli debugging purposes
def mini_no_setup():
return nn.Sequential(
nn.Conv2d(in_channels=1, out_channels=2, kernel_size=3, stride=10),
nn.ReLU(inplace=True),
nn.MaxPool2d(kernel_size=2, stride=2),
nn.BatchNorm2d(2, momentum=1, affine=False),
Flatten(),
nn.Linear(2, 5)).to("cpu")
# for debugging purposes
def mini(hparams):
return nn.Sequential(
nn.Conv2d(in_channels=1, out_channels=2, kernel_size=3, stride=10),
nn.ReLU(inplace=True),
nn.MaxPool2d(kernel_size=2, stride=2),
Flatten(),
nn.Linear(2, hparams.n_way)).to(hparams.device)
def small_no_batch_norm(hparams):
return nn.Sequential(
nn.Conv2d(1, 64, 3),
nn.ReLU(inplace=True),
nn.MaxPool2d(2, 2),
nn.Conv2d(64, 64, 3),
nn.ReLU(inplace=True),
nn.MaxPool2d(2, 2),
nn.Conv2d(64, 64, 3),
nn.ReLU(inplace=True),
nn.MaxPool2d(2, 2),
Flatten(),
nn.Linear(64, hparams.n_way)).to(hparams.device)
def small(hparams):
return nn.Sequential(
nn.Conv2d(1, 64, 3),
nn.BatchNorm2d(64, momentum=1, affine=True),
nn.ReLU(inplace=True),
nn.MaxPool2d(2, 2),
nn.Conv2d(64, 64, 3),
nn.BatchNorm2d(64, momentum=1, affine=True),
nn.ReLU(inplace=True),
nn.MaxPool2d(2, 2),
nn.Conv2d(64, 64, 3),
nn.BatchNorm2d(64, momentum=1, affine=True),
nn.ReLU(inplace=True),
nn.MaxPool2d(2, 2),
Flatten(),
nn.Linear(64, hparams.n_way)).to(hparams.device)
def medium():
pass
def large():
pass
class Flatten(nn.Module):
def forward(self, input):
return input.view(input.size(0), -1)