SPOClab-ca / dn3

The fusion of MNE and PyTorch for accelerated deep-neural-network based BCI-systems and Neurophysiology signal analysis.
BSD 3-Clause "New" or "Revised" License
64 stars 19 forks source link

Fixed issue with epoch ID -> class label mapping. #78

Closed zeyus closed 2 years ago

zeyus commented 2 years ago

If you specify events with names mapping to IDs, dn3 incorrectly maps the event name (string) to the classifier label, this fails with a KeyError like:

  File "C:\tools\miniconda3\envs\eegtorch\lib\site-packages\dn3\data\dataset.py", line 433, in <lambda>
    return np.apply_along_axis(lambda x: self.epoch_codes_to_class_labels[x[0]], 1,
KeyError: 108

The data in this case is stored in MNE fif files, and contains a stim channel with int markers which track a single sample where the stimuli was presented, I also tried using event IDs as a list without a name string, but the issue was the same.

this PR maintains the mapping but uses the value rather than the key for the mapping.

Sample config yaml:

Configuratron:
  sfreq: 100
  preload: True
  deep1010: True
  preload: True
  architecture:
    layers: 16
    activation: 'relu'
    dropout: 0.1
use_gpu: True
test_fraction: 0.2
datasets:
  clencher:
    dataset_id: 1
    name: "CogSci clencher"
    toplevel: "./data_nn/"
    filename_format: "grasp_{subject}_{session}_raw"
    tmin: -0.1
    tlen: 4.0
    data_min: True
    data_max: True
    hpf: 0.1
    lpf: 49
    events:
      108: "l"
      110: "n"
    picks:
      - C3
      - P3
    lr: 0.00001
    train_params:
      folds: 3
    training_configuration:
      batch_size: 8
      epochs: 100
zeyus commented 2 years ago

since i've been working on my forked dn3 the main branch has extra commits now, i'll reopen this PR with a bugfix branch. of course if the changes i make turn out useful / work well, I'll create separate PRs for them.