🧠 EEG/MEG self-supervised learning toolbox.
Project description
🔎 Overview
A minimalistic Python library for EEG/MEG deep learning research, primarely focused on self-supervised learning.
🚀 Example usage
Below you can see an example adapted for a SSL training workflow using the SimCLR framework.
import torch
from pytorch_metric_learning import losses
from neurocode.datasets import SimulatedDataset, RecordingDataset
from neurocode.samplers import SignalSampler
from neurocode.models import SignalNet
from neurocode.training import SimCLR
from neurocode.datautil import manifold_plot, history_plot
sample_data = SimulatedDataset("sample", seed=7815891891337)
sample_data.read_from_file("MEG/sample/sample_audvis_raw.fif")
# create random extrapolated data from the raw MEG recording,
# you need to provide a location to a forward solution (source space) to use
sample_data.simulate("MEG/sample/sample_audvis-meg-eeg-oct-6-fwd.fif")
dataset = RecordingDataset(sample_data.data(), sample_data.labels(), sfreq=200)
train, valid = dataset.train_valid_split(split=0.75)
samplers = {
'train': SignalSampler(train.data(), train.labels(), train.info(), ...),
'valid': SignalSampler(valid.data(), valid.labels(), valid.info(), ...),
}
device = "cuda" if torch.cuda.is_available() else "cpu"
model = SignalNet(...)
optimizer = torch.optim.Adam(model.parameters(), ...)
scheduler = torch.optim.lr_scheduler.CosineAnnealingLR(optimizer, ...)
criterion = losses.NTXentLoss()
# train the neural network using the self-supervised learning SimCLR framework,
# save or plot the history to see training loss evolution
simclr = SimCLR(model, device, ...)
history = simclr.fit(samplers, save_model=True)
📋 License
All code is to be held under a general MIT license, please see LICENSE for specific information.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
neurocode-0.1.0.tar.gz
(29.7 kB
view hashes)
Built Distribution
neurocode-0.1.0-py3-none-any.whl
(55.5 kB
view hashes)
Close
Hashes for neurocode-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | adc245dfc20547938d7f695a810044060bf026e16096ddf8ee65bd656d4da12a |
|
MD5 | da96b5f885bace3ad8dbd3596c02a1f0 |
|
BLAKE2b-256 | b885c1a136e6dba212089ebd050a50ed55ae8002bc229b32b37af7af3af4f223 |