-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmodel_18class.py
67 lines (62 loc) · 2.3 KB
/
model_18class.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
import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.autograd import Variable
from torch.nn.parameter import Parameter
#from torch.nn.init import xavier_normal
class Net_18(nn.Module):
def __init__(self, class_num=18, base_features=36, window_length=128, input_channels=128):
super(Net_18, self).__init__()
self.class_num = class_num
self.conv1 = nn.Sequential(
nn.Conv2d(in_channels=1, # for EMG images, the channels is 1. not the signal channels: input_channels
out_channels=base_features,
kernel_size=3, stride=1, padding=1),
nn.BatchNorm2d(base_features),
nn.ReLU(),
nn.MaxPool2d(kernel_size=2, stride=2)
)
self.conv2 = nn.Sequential(
nn.Conv2d(in_channels=base_features,
out_channels=base_features,
kernel_size=3, stride=1, padding=1),
nn.BatchNorm2d(base_features),
nn.ReLU(),
nn.MaxPool2d(kernel_size=2, stride=2)
)
self.conv3 = nn.Sequential(
nn.Conv2d(in_channels=base_features,
out_channels=base_features,
kernel_size=1, stride=1),
nn.BatchNorm2d(base_features),
nn.ReLU(),
nn.MaxPool2d(kernel_size=2, stride=2)
)
self.conv4 = nn.Sequential(
nn.Conv2d(in_channels=base_features,
out_channels=base_features,
kernel_size=1, stride=1),
nn.BatchNorm2d(base_features),
nn.ReLU(),
nn.Dropout(p=0.5),
nn.MaxPool2d(kernel_size=2, stride=2)
)
self.fcn1 = nn.Sequential(
nn.Linear(2304, 512),
nn.ReLU(),
nn.Dropout(p=0.5),
nn.Linear(512, 128),
nn.ReLU(),
nn.Dropout(p=0.5)
)
self.fcn2 = nn.Linear(128, self.class_num)
def forward(self, x):
x = torch.unsqueeze(x, 1)
x = self.conv1(x)
x = self.conv2(x)
x = self.conv3(x)
x = self.conv4(x)
x = self.fcn1(x.view(x.size(0), -1))
x = self.fcn2(x)
x = F.softmax(x, dim=1)
return x