Thomas Chardonnens
commited on
Commit
•
9039685
1
Parent(s):
e62353e
update model arch
Browse files- seizure_detection.py +10 -16
seizure_detection.py
CHANGED
@@ -3,37 +3,31 @@ import torch.nn as nn
|
|
3 |
import torch.nn.functional as F
|
4 |
|
5 |
|
6 |
-
class
|
7 |
-
def
|
8 |
-
super(
|
9 |
-
self.conv1= nn.Conv2d(1, 32, kernel_size=3, stride=1, padding=1) # 32,
|
10 |
|
11 |
-
self.pool= nn.MaxPool2d(kernel_size=2, stride=2) # 32,
|
12 |
|
13 |
-
self.conv2= nn.Conv2d(32, 64, kernel_size=3, stride=1, padding=1) # 64,
|
14 |
-
self.conv3= nn.Conv2d(64, 128, kernel_size=3, stride=1, padding=1) # 128, 56, 56 -> 128, 28, 28
|
15 |
-
self.conv4= nn.Conv2d(128, 256, kernel_size=3, stride=1, padding=1) # 256, 28, 28 -> 256, 14, 14
|
16 |
|
17 |
# Adding Batch Normalization
|
18 |
self.bn1 = nn.BatchNorm2d(32)
|
19 |
self.bn2 = nn.BatchNorm2d(64)
|
20 |
-
self.bn3 = nn.BatchNorm2d(128)
|
21 |
-
self.bn4 = nn.BatchNorm2d(256)
|
22 |
|
23 |
self.dropout = nn.Dropout(p=0.5) # Dropout with a probability of 50%
|
24 |
|
25 |
-
self.fc1= nn.Linear(
|
26 |
self.fc2= nn.Linear(120, 32)
|
27 |
self.fc3= nn.Linear(32, num_classes)
|
28 |
|
29 |
def forward(self, x):
|
30 |
-
x = self.pool(F.relu(self.bn1(self.conv1(x)))) # 32,
|
31 |
-
x = self.pool(F.relu(self.bn2(self.conv2(x)))) # 64,
|
32 |
-
x = self.pool(F.relu(self.bn3(self.conv3(x)))) # 128, 28, 28
|
33 |
-
x = self.pool(F.relu(self.bn4(self.conv4(x)))) # 256, 14, 14
|
34 |
|
35 |
x = torch.flatten(x, 1)
|
36 |
x = self.dropout(F.relu(self.fc1(x))) # Apply dropout
|
37 |
x = self.dropout(F.relu(self.fc2(x))) # Apply dropout
|
38 |
x = self.fc3(x)
|
39 |
-
return x
|
|
|
3 |
import torch.nn.functional as F
|
4 |
|
5 |
|
6 |
+
class SeizureDetectionCNN(nn.Module):
|
7 |
+
def init(self, num_classes=2):
|
8 |
+
super(SeizureDetectionCNN, self).init()
|
9 |
+
self.conv1= nn.Conv2d(1, 32, kernel_size=3, stride=1, padding=1) # 32, 32, 32
|
10 |
|
11 |
+
self.pool= nn.MaxPool2d(kernel_size=2, stride=2) # 32, 16, 16
|
12 |
|
13 |
+
self.conv2= nn.Conv2d(32, 64, kernel_size=3, stride=1, padding=1) # 64, 16, 16 -> 64, 8, 8
|
|
|
|
|
14 |
|
15 |
# Adding Batch Normalization
|
16 |
self.bn1 = nn.BatchNorm2d(32)
|
17 |
self.bn2 = nn.BatchNorm2d(64)
|
|
|
|
|
18 |
|
19 |
self.dropout = nn.Dropout(p=0.5) # Dropout with a probability of 50%
|
20 |
|
21 |
+
self.fc1= nn.Linear(64 * 8 * 8, 120)
|
22 |
self.fc2= nn.Linear(120, 32)
|
23 |
self.fc3= nn.Linear(32, num_classes)
|
24 |
|
25 |
def forward(self, x):
|
26 |
+
x = self.pool(F.relu(self.bn1(self.conv1(x)))) # 32, 32, 32
|
27 |
+
x = self.pool(F.relu(self.bn2(self.conv2(x)))) # 64, 8, 8
|
|
|
|
|
28 |
|
29 |
x = torch.flatten(x, 1)
|
30 |
x = self.dropout(F.relu(self.fc1(x))) # Apply dropout
|
31 |
x = self.dropout(F.relu(self.fc2(x))) # Apply dropout
|
32 |
x = self.fc3(x)
|
33 |
+
return x
|