This repository has been archived by the owner on Jul 11, 2019. It is now read-only.
forked from annemwm/mood-map
-
Notifications
You must be signed in to change notification settings - Fork 0
/
model3.py
72 lines (63 loc) · 2.4 KB
/
model3.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
import torch
import torch.nn as nn
KERNEL_SIZE_CONV = 5
STRIDE = 1
PADDING = 2
KERNEL_SIZE_POOL = 2
NUM_CLASSES = 6
# with RELUs
class cnn_model(nn.Module):
def __init__(self):
super(cnn_model, self).__init__()
self.block1 = nn.Sequential(
nn.Conv2d(in_channels = 1, # 1, because grayscale
out_channels = 32, # model chooses 16 filters
kernel_size = KERNEL_SIZE_CONV,
stride = STRIDE,
padding = PADDING),
nn.BatchNorm2d(32, eps=1e-05, momentum=0.1, affine=True), # NEW, standardize the weights
nn.MaxPool2d(kernel_size = KERNEL_SIZE_POOL), # now image size is 48/2 = 24
nn.ReLU(),
nn.Dropout(p=0.5)
)
self.block2 = nn.Sequential(
nn.Conv2d(in_channels = 32, # convention: use powers of 2
out_channels = 64,
kernel_size = KERNEL_SIZE_CONV,
stride = STRIDE,
padding = PADDING),
nn.BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True),
nn.MaxPool2d(kernel_size = KERNEL_SIZE_POOL), # now image size is 24/2 = 12
nn.ReLU(),
nn.Dropout(p=0.5)
)
self.block3 = nn.Sequential(
nn.Conv2d(in_channels = 64,
out_channels = 128,
kernel_size = KERNEL_SIZE_CONV,
stride = STRIDE,
padding = PADDING),
nn.BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True),
nn.MaxPool2d(kernel_size = KERNEL_SIZE_POOL), # now image is 12/2 = 6
nn.ReLU(),
nn.Dropout(p=0.5)
)
# self.block4 = nn.Sequential(
# nn.Conv2d(in_channels = 128,
# out_channels = 256,
# kernel_size = KERNEL_SIZE_CONV, # now image is 6/2 = 3
# stride = STRIDE,
# padding = PADDING))
# # No pooling layer this time
self.block5 = nn.Sequential(
nn.Linear(128 * 6 * 6, 1000),
nn.ReLU(),
nn.Linear(1000, NUM_CLASSES) # in=6*6*256=9216, out=6 (6 possible emotions)
)
def forward(self, x):
out = self.block1(x)
out = self.block2(out)
out = self.block3(out)
#out = self.block4(out)
out = out.view(-1, 128 * 6 * 6) # flatten for nn.Linear
return self.block5(out)