BigBros / seizure_detection.py
Thomas Chardonnens
fix model name
d14b595
raw
history blame contribute delete
No virus
1.12 kB
import torch
import torch.nn as nn
import torch.nn.functional as F
class SeizureDetector(nn.Module):
def init(self, num_classes=2):
super(SeizureDetector, self).init()
self.conv1= nn.Conv2d(1, 32, kernel_size=3, stride=1, padding=1) # 32, 32, 32
self.pool= nn.MaxPool2d(kernel_size=2, stride=2) # 32, 16, 16
self.conv2= nn.Conv2d(32, 64, kernel_size=3, stride=1, padding=1) # 64, 16, 16 -> 64, 8, 8
# Adding Batch Normalization
self.bn1 = nn.BatchNorm2d(32)
self.bn2 = nn.BatchNorm2d(64)
self.dropout = nn.Dropout(p=0.5) # Dropout with a probability of 50%
self.fc1= nn.Linear(64 * 8 * 8, 120)
self.fc2= nn.Linear(120, 32)
self.fc3= nn.Linear(32, num_classes)
def forward(self, x):
x = self.pool(F.relu(self.bn1(self.conv1(x)))) # 32, 32, 32
x = self.pool(F.relu(self.bn2(self.conv2(x)))) # 64, 8, 8
x = torch.flatten(x, 1)
x = self.dropout(F.relu(self.fc1(x))) # Apply dropout
x = self.dropout(F.relu(self.fc2(x))) # Apply dropout
x = self.fc3(x)
return x