-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmodel_classifier.py
58 lines (49 loc) · 2.21 KB
/
model_classifier.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
import torch
from torch import nn
from .Multitask import MultitaskSSVEP
class MultitaskSSVEPClassifier(nn.Module):
"""
Using multi-task learning to capture signals simultaneously from the fovea efficiently and the neighboring targets in the peripheral vision generate a visual response map. A calibration-free user-independent solution, desirable for clinical diagnostics. A stepping stone for an objective assessment of glaucoma patients’ visual field.
Learn more about this model at https://jinglescode.github.io/ssvep-multi-task-learning/
This model is a multi-class classifier.
Usage:
model = MultitaskSSVEPClassifier(
num_channel=11,
num_classes=40,
signal_length=250,
)
x = torch.randn(2, 11, 250)
print("Input shape:", x.shape) # torch.Size([2, 11, 250])
y = model(x)
print("Output shape:", y.shape) # torch.Size([2, 40])
Cite:
@inproceedings{khok2020deep,
title={Deep Multi-Task Learning for SSVEP Detection and Visual Response Mapping},
author={Khok, Hong Jing and Koh, Victor Teck Chang and Guan, Cuntai},
booktitle={2020 IEEE International Conference on Systems, Man, and Cybernetics (SMC)},
pages={1280--1285},
year={2020},
organization={IEEE}
}
"""
def __init__(self, num_channel=10, num_classes=4, signal_length=1000, filters_n1=4, kernel_window_ssvep=59, kernel_window=19, conv_3_dilation=4, conv_4_dilation=4):
super().__init__()
self.base = MultitaskSSVEP(num_channel, num_classes, signal_length, filters_n1, kernel_window_ssvep, kernel_window, conv_3_dilation, conv_4_dilation)
self.fc = nn.Linear(num_classes*2, out_features=num_classes)
def forward(self, x):
x = self.base(x)
x = torch.flatten(x, start_dim=1)
x = self.fc(x)
return x
def test():
model = MultitaskSSVEPClassifier(
num_channel=11,
num_classes=40,
signal_length=250,
)
x = torch.randn(2, 11, 250)
print("Input shape:", x.shape) # torch.Size([2, 11, 250])
y = model(x)
print("Output shape:", y.shape) # torch.Size([2, 40])
if __name__ == "__main__":
test()