| 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) |