-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathquick_example.py
More file actions
27 lines (23 loc) · 801 Bytes
/
quick_example.py
File metadata and controls
27 lines (23 loc) · 801 Bytes
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
import torch
import torch.nn as nn
from models.cbramod import CBraMod
from einops.layers.torch import Rearrange
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
model = CBraMod().to(device)
model.load_state_dict(torch.load('pretrained_weights/pretrained_weights.pth', map_location=device))
model.proj_out = nn.Identity()
classifier = nn.Sequential(
Rearrange('b c s p -> b (c s p)'),
nn.Linear(22*4*200, 4*200),
nn.ELU(),
nn.Dropout(0.1),
nn.Linear(4 * 200, 200),
nn.ELU(),
nn.Dropout(0.1),
nn.Linear(200, 4),
).to(device)
# mock_eeg.shape = (batch_size, num_of_channels, time_segments, points_per_patch)
mock_eeg = torch.randn((8, 22, 4, 200)).to(device)
# logits.shape = (batch_size, num_of_classes)
logits = classifier(model(mock_eeg))
print(logits.shape)