Braindecode 1.8.1.dev181458649__tar.gz → 1.8.1.dev181501004__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (211) hide show
  1. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/NOTICE.txt +1 -0
  2. {braindecode-1.8.1.dev181458649/braindecode.egg-info → braindecode-1.8.1.dev181501004}/PKG-INFO +1 -1
  3. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/augmentation/__init__.py +2 -0
  4. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/augmentation/functional.py +48 -0
  5. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/augmentation/transforms.py +52 -1
  6. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/datasets/base.py +5 -0
  7. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/models/__init__.py +2 -0
  8. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/models/barista.py +23 -11
  9. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/models/base.py +18 -0
  10. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/models/brant.py +18 -7
  11. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/models/codebrain.py +75 -11
  12. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/models/csbrain.py +24 -12
  13. braindecode-1.8.1.dev181501004/braindecode/models/duin.py +454 -0
  14. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/models/eeg_clip.py +3 -0
  15. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/models/epint.py +4 -0
  16. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/models/mscformer.py +21 -1
  17. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/models/neurorvq.py +115 -29
  18. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/models/neurorvq_tokenizer.py +30 -10
  19. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/models/reve.py +117 -39
  20. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/models/sleepfm.py +62 -12
  21. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/models/steegformer.py +16 -9
  22. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/models/summary.csv +1 -0
  23. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/models/util.py +5 -0
  24. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/modules/__init__.py +2 -1
  25. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/modules/attention.py +37 -9
  26. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/modules/blocks.py +121 -5
  27. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/modules/channels.py +77 -0
  28. braindecode-1.8.1.dev181501004/braindecode/version.py +1 -0
  29. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004/braindecode.egg-info}/PKG-INFO +1 -1
  30. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode.egg-info/SOURCES.txt +1 -0
  31. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/docs/api.rst +9 -0
  32. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/docs/whats_new.rst +49 -0
  33. braindecode-1.8.1.dev181458649/braindecode/version.py +0 -1
  34. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/LICENSE.txt +0 -0
  35. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/MANIFEST.in +0 -0
  36. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/README.rst +0 -0
  37. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/__init__.py +0 -0
  38. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/augmentation/base.py +0 -0
  39. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/classifier.py +0 -0
  40. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/datasets/__init__.py +0 -0
  41. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/datasets/_notebook_viewer.py +0 -0
  42. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/datasets/bbci.py +0 -0
  43. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/datasets/bcicomp.py +0 -0
  44. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/datasets/bids/__init__.py +0 -0
  45. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/datasets/bids/datasets.py +0 -0
  46. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/datasets/bids/format.py +0 -0
  47. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/datasets/bids/hub.py +0 -0
  48. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/datasets/bids/hub_format.py +0 -0
  49. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/datasets/bids/hub_io.py +0 -0
  50. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/datasets/bids/hub_validation.py +0 -0
  51. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/datasets/bids/iterable.py +0 -0
  52. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/datasets/chb_mit.py +0 -0
  53. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/datasets/collate.py +0 -0
  54. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/datasets/mne.py +0 -0
  55. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/datasets/moabb.py +0 -0
  56. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/datasets/nmt.py +0 -0
  57. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/datasets/registry.py +0 -0
  58. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/datasets/siena.py +0 -0
  59. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/datasets/sleep_physio_challe_18.py +0 -0
  60. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/datasets/sleep_physionet.py +0 -0
  61. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/datasets/tuh.py +0 -0
  62. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/datasets/utils.py +0 -0
  63. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/datasets/xy.py +0 -0
  64. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/datautil/__init__.py +0 -0
  65. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/datautil/channel_utils.py +0 -0
  66. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/datautil/hub_formats.py +0 -0
  67. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/datautil/serialization.py +0 -0
  68. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/datautil/util.py +0 -0
  69. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/eegneuralnet.py +0 -0
  70. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/functional/__init__.py +0 -0
  71. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/functional/_real_dft.py +0 -0
  72. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/functional/functions.py +0 -0
  73. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/functional/initialization.py +0 -0
  74. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/models/atcnet.py +0 -0
  75. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/models/attentionbasenet.py +0 -0
  76. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/models/attn_sleep.py +0 -0
  77. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/models/axon.py +0 -0
  78. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/models/bendr.py +0 -0
  79. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/models/biot.py +0 -0
  80. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/models/brainbert.py +0 -0
  81. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/models/brainmodule.py +0 -0
  82. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/models/brainomni.py +0 -0
  83. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/models/cbramod.py +0 -0
  84. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/models/config.py +0 -0
  85. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/models/contrawr.py +0 -0
  86. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/models/ctnet.py +0 -0
  87. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/models/dance.py +0 -0
  88. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/models/deep4.py +0 -0
  89. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/models/deepsleepnet.py +0 -0
  90. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/models/dgcnn.py +0 -0
  91. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/models/diver1.py +0 -0
  92. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/models/eegconformer.py +0 -0
  93. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/models/eegdino.py +0 -0
  94. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/models/eeginception_erp.py +0 -0
  95. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/models/eeginception_mi.py +0 -0
  96. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/models/eegitnet.py +0 -0
  97. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/models/eegminer.py +0 -0
  98. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/models/eegnet.py +0 -0
  99. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/models/eegnex.py +0 -0
  100. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/models/eegpt.py +0 -0
  101. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/models/eegsimpleconv.py +0 -0
  102. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/models/eegsym.py +0 -0
  103. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/models/eegtcnet.py +0 -0
  104. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/models/emg2qwerty.py +0 -0
  105. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/models/fbcnet.py +0 -0
  106. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/models/fblightconvnet.py +0 -0
  107. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/models/fbmsnet.py +0 -0
  108. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/models/gcnsnet.py +0 -0
  109. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/models/guetschel2026.py +0 -0
  110. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/models/hybrid.py +0 -0
  111. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/models/ifnet.py +0 -0
  112. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/models/labram.py +0 -0
  113. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/models/luna.py +0 -0
  114. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/models/mapa.py +0 -0
  115. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/models/medformer.py +0 -0
  116. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/models/meta_neuromotor.py +0 -0
  117. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/models/mirepnet.py +0 -0
  118. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/models/msvtnet.py +0 -0
  119. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/models/mvpformer.py +0 -0
  120. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/models/neuropose.py +0 -0
  121. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/models/patchedtransformer.py +0 -0
  122. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/models/popt.py +0 -0
  123. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/models/sccnet.py +0 -0
  124. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/models/seizure_transformer.py +0 -0
  125. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/models/sensingdynamics.py +0 -0
  126. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/models/shallow_fbcsp.py +0 -0
  127. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/models/signal_jepa.py +0 -0
  128. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/models/sinc_shallow.py +0 -0
  129. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/models/sleep_stager_blanco_2020.py +0 -0
  130. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/models/sleep_stager_chambon_2018.py +0 -0
  131. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/models/sparcnet.py +0 -0
  132. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/models/sstdpn.py +0 -0
  133. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/models/syncnet.py +0 -0
  134. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/models/tcformer.py +0 -0
  135. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/models/tcn.py +0 -0
  136. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/models/tfm_tokenizer.py +0 -0
  137. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/models/tidnet.py +0 -0
  138. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/models/tmsanet.py +0 -0
  139. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/models/tsinception.py +0 -0
  140. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/models/usleep.py +0 -0
  141. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/models/vemg2pose.py +0 -0
  142. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/models/zuna.py +0 -0
  143. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/modules/activation.py +0 -0
  144. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/modules/convolution.py +0 -0
  145. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/modules/dance_modules.py +0 -0
  146. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/modules/filter.py +0 -0
  147. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/modules/layers.py +0 -0
  148. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/modules/linear.py +0 -0
  149. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/modules/linear_attention.py +0 -0
  150. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/modules/parametrization.py +0 -0
  151. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/modules/popt_modules.py +0 -0
  152. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/modules/quantization.py +0 -0
  153. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/modules/stats.py +0 -0
  154. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/modules/util.py +0 -0
  155. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/modules/wrapper.py +0 -0
  156. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/preprocessing/__init__.py +0 -0
  157. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/preprocessing/eegprep_preprocess.py +0 -0
  158. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/preprocessing/mne_preprocess.py +0 -0
  159. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/preprocessing/preprocess.py +0 -0
  160. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/preprocessing/util.py +0 -0
  161. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/preprocessing/windowers.py +0 -0
  162. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/regressor.py +0 -0
  163. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/samplers/__init__.py +0 -0
  164. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/samplers/base.py +0 -0
  165. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/samplers/ssl.py +0 -0
  166. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/training/__init__.py +0 -0
  167. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/training/callbacks.py +0 -0
  168. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/training/losses.py +0 -0
  169. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/training/scoring.py +0 -0
  170. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/util.py +0 -0
  171. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/visualization/__init__.py +0 -0
  172. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/visualization/activations.py +0 -0
  173. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/visualization/attribution.py +0 -0
  174. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/visualization/confusion_matrices.py +0 -0
  175. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/visualization/frequency.py +0 -0
  176. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/visualization/metrics.py +0 -0
  177. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/visualization/sanity.py +0 -0
  178. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode/visualization/topology.py +0 -0
  179. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode.egg-info/dependency_links.txt +0 -0
  180. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode.egg-info/requires.txt +0 -0
  181. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/braindecode.egg-info/top_level.txt +0 -0
  182. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/docs/Makefile +0 -0
  183. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/docs/_templates/autosummary/class.rst +0 -0
  184. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/docs/_templates/autosummary/class_in_subdir.rst +0 -0
  185. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/docs/_templates/autosummary/function.rst +0 -0
  186. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/docs/_templates/autosummary/function_in_subdir.rst +0 -0
  187. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/docs/agent_docs.rst +0 -0
  188. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/docs/cite.rst +0 -0
  189. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/docs/conf.py +0 -0
  190. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/docs/help.rst +0 -0
  191. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/docs/index.rst +0 -0
  192. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/docs/install/install.rst +0 -0
  193. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/docs/install/install_pip.rst +0 -0
  194. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/docs/install/install_source.rst +0 -0
  195. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/docs/models/categorization/attention.rst +0 -0
  196. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/docs/models/categorization/channel.rst +0 -0
  197. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/docs/models/categorization/convolution.rst +0 -0
  198. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/docs/models/categorization/filterbank.rst +0 -0
  199. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/docs/models/categorization/gnn.rst +0 -0
  200. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/docs/models/categorization/interpretable.rst +0 -0
  201. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/docs/models/categorization/lbm.rst +0 -0
  202. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/docs/models/categorization/recurrent.rst +0 -0
  203. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/docs/models/categorization/spd.rst +0 -0
  204. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/docs/models/models.rst +0 -0
  205. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/docs/models/models_categorization.rst +0 -0
  206. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/docs/models/models_table.rst +0 -0
  207. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/docs/models/models_visualization.rst +0 -0
  208. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/docs/sg_execution_times.rst +0 -0
  209. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/docs/user_guide/channel_strategies.rst +0 -0
  210. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/pyproject.toml +0 -0
  211. {braindecode-1.8.1.dev181458649 → braindecode-1.8.1.dev181501004}/setup.cfg +0 -0
@@ -40,6 +40,7 @@ The following components are licensed under the MIT License:
40
40
 
41
41
  - `braindecode/models/ctnet.py`
42
42
  - `braindecode/models/dance.py`
43
+ - `braindecode/models/duin.py`
43
44
  - `braindecode/models/medformer.py`
44
45
  - `braindecode/models/tcformer.py`
45
46
  - `braindecode/models/ifnet.py`
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: braindecode
3
- Version: 1.8.1.dev181458649
3
+ Version: 1.8.1.dev181501004
4
4
  Summary: Deep learning software to decode EEG, ECG or MEG signals
5
5
  Author-email: Robin Tibor Schirrmeister <robintibor@gmail.com>, Bruno Aristimunha Pinto <b.aristimunha@gmail.com>, Alexandre Gramfort <agramfort@meta.com>
6
6
  Maintainer-email: Alexandre Gramfort <agramfort@meta.com>, Bruno Aristimunha Pinto <b.aristimunha@gmail.com>, Robin Tibor Schirrmeister <robintibor@gmail.com>
@@ -10,6 +10,7 @@ from .transforms import (
10
10
  ChannelsReref,
11
11
  ChannelsShuffle,
12
12
  ChannelsSymmetry,
13
+ CutMix,
13
14
  FrequencyShift,
14
15
  FTSurrogate,
15
16
  GaussianNoise,
@@ -36,6 +37,7 @@ __all__ = [
36
37
  "SignFlip",
37
38
  "FTSurrogate",
38
39
  "ChannelsShuffle",
40
+ "CutMix",
39
41
  "ChannelsDropout",
40
42
  "GaussianNoise",
41
43
  "ChannelsSymmetry",
@@ -1075,6 +1075,54 @@ def mixup(
1075
1075
  return X_mix, (y_a, y_b, lam)
1076
1076
 
1077
1077
 
1078
+ def cutmix(
1079
+ X: torch.Tensor,
1080
+ y: torch.Tensor,
1081
+ idx_perm: torch.Tensor,
1082
+ cut_t_start: torch.Tensor,
1083
+ cut_t_len: torch.Tensor,
1084
+ ) -> tuple[torch.Tensor, torch.Tensor]:
1085
+ """Paste a time region of shuffled examples into the original examples.
1086
+
1087
+ See [1]_ for details.
1088
+
1089
+ Parameters
1090
+ ----------
1091
+ X : torch.Tensor
1092
+ EEG data in form ``batch_size, n_channels, n_times``
1093
+ y : torch.Tensor
1094
+ Target of length ``batch_size``
1095
+ idx_perm : torch.Tensor
1096
+ Permuted indices of example that are mixed into original examples.
1097
+ cut_t_start : torch.Tensor
1098
+ Start index of the pasted time region for each example.
1099
+ cut_t_len : torch.Tensor
1100
+ Length of the pasted time region for each example.
1101
+
1102
+ Returns
1103
+ -------
1104
+ tuple
1105
+ ``X``, ``y``. Where ``X`` is augmented and ``y`` is a tuple of length
1106
+ 3 containing the labels of the two mixed examples and the fraction of
1107
+ each example kept from the original, ``1 - cut_t_len / n_times``.
1108
+
1109
+ References
1110
+ ----------
1111
+ .. [1] Sangdoo Yun, Dongyoon Han, Seong Joon Oh, Sanghyuk Chun,
1112
+ Junsuk Choe, Youngjoon Yoo (2019). CutMix: Regularization Strategy
1113
+ to Train Strong Classifiers with Localizable Features. In 2019
1114
+ IEEE/CVF International Conference on Computer Vision (ICCV)
1115
+ Online: https://arxiv.org/abs/1905.04899
1116
+ """
1117
+ n_times = X.shape[-1]
1118
+ t = torch.arange(n_times, device=X.device)
1119
+ start = cut_t_start[:, None]
1120
+ in_cut = (t >= start) & (t < start + cut_t_len[:, None])
1121
+ X_mix = torch.where(in_cut[:, None], X[idx_perm], X)
1122
+ lam = (n_times - cut_t_len).to(X.dtype) / n_times
1123
+ return X_mix, (y.clone(), y[idx_perm].clone(), lam)
1124
+
1125
+
1078
1126
  def segmentation_reconstruction(
1079
1127
  X: torch.Tensor,
1080
1128
  y: torch.Tensor,
@@ -3,6 +3,7 @@
3
3
  # Gustavo Rodrigues <gustavenrique01@gmail.com>
4
4
  # Bruna Lopes <brunajaflopes@gmail.com>
5
5
  # Sarthak Tayal <sarthaktayal2@gmail.com>
6
+ # Anton Soloviev <anton@praviel.com>
6
7
  #
7
8
  # License: BSD (3-clause)
8
9
 
@@ -24,6 +25,7 @@ from .functional import (
24
25
  channels_permute,
25
26
  channels_rereference,
26
27
  channels_shuffle,
28
+ cutmix,
27
29
  frequency_shift,
28
30
  ft_surrogate,
29
31
  gaussian_noise,
@@ -1095,6 +1097,55 @@ class Mixup(Transform):
1095
1097
  }
1096
1098
 
1097
1099
 
1100
+ class CutMix(Mixup):
1101
+ """Implements CutMix for EEG data.
1102
+
1103
+ A random time region of each example is replaced by the same region of
1104
+ a shuffled example of the batch, see [1]_. As in the reference code [2]_,
1105
+ a coefficient ``lam`` is drawn from a Beta distribution, the region is
1106
+ ``(1 - lam) * n_times`` long (the 1-D analogue of the cut area ratio
1107
+ ``1 - lam``) around a uniformly drawn center, it is clipped at the trial
1108
+ boundaries, and ``lam`` is then recomputed from the pasted length.
1109
+
1110
+ Like :class:`Mixup`, it applies to whole batches and returns targets
1111
+ ``(y_a, y_b, lam)`` for :func:`braindecode.training.mixup_criterion`.
1112
+
1113
+ Parameters
1114
+ ----------
1115
+ alpha : float
1116
+ Parameter of the Beta distribution of ``lam``. ``alpha <= 0`` cuts
1117
+ nothing.
1118
+ beta_per_sample : bool (default=False)
1119
+ By default, one ``lam`` per batch is drawn. If True, one per sample.
1120
+ random_state : int | numpy.random.Generator, optional
1121
+ Seed to be used to instantiate numpy random number generator instance.
1122
+ Defaults to None.
1123
+
1124
+ References
1125
+ ----------
1126
+ .. [1] Sangdoo Yun, Dongyoon Han, Seong Joon Oh, Sanghyuk Chun,
1127
+ Junsuk Choe, Youngjoon Yoo (2019). CutMix: Regularization Strategy
1128
+ to Train Strong Classifiers with Localizable Features. In 2019
1129
+ IEEE/CVF International Conference on Computer Vision (ICCV)
1130
+ Online: https://arxiv.org/abs/1905.04899
1131
+ .. [2] https://github.com/clovaai/CutMix-PyTorch/blob/master/train.py
1132
+ """
1133
+
1134
+ operation = staticmethod(cutmix) # type: ignore[assignment]
1135
+
1136
+ def get_augmentation_params(self, *batch):
1137
+ """Return idx_perm and the cut_t_start, cut_t_len of each region."""
1138
+ params = super().get_augmentation_params(*batch)
1139
+ lam = params.pop("lam")
1140
+ n_times = batch[0].shape[-1]
1141
+ half = ((1 - lam) * n_times).long() // 2
1142
+ center = torch.as_tensor(self.rng.randint(n_times, size=len(lam)))
1143
+ center = center.to(lam.device)
1144
+ start = (center - half).clamp(min=0)
1145
+ end = (center + half).clamp(max=n_times)
1146
+ return dict(params, cut_t_start=start, cut_t_len=end - start)
1147
+
1148
+
1098
1149
  class SegmentationReconstruction(Transform):
1099
1150
  """Segmentation Reconstruction from Lotte (2015) [Lotte2015]_.
1100
1151
 
@@ -1283,7 +1334,7 @@ class MaskEncoding(Transform):
1283
1334
  )
1284
1335
 
1285
1336
  time_start = self.rng.randint(
1286
- 0, n_times - segment_length, (batch_size, self.n_segments)
1337
+ 0, n_times - segment_length + 1, (batch_size, self.n_segments)
1287
1338
  )
1288
1339
  time_start = torch.from_numpy(time_start)
1289
1340
 
@@ -1900,6 +1900,11 @@ class BaseConcatDataset(ConcatDataset, HubDatasetMixin, Generic[T]):
1900
1900
  dataset description.
1901
1901
  """
1902
1902
  description = pd.DataFrame(description)
1903
+ if len(description.columns) and len(description) != len(self.datasets):
1904
+ raise ValueError(
1905
+ f"Length of values ({len(description)}) does not match "
1906
+ f"number of datasets ({len(self.datasets)})."
1907
+ )
1903
1908
  for key, value in description.items():
1904
1909
  for ds, value_ in zip(self.datasets, value):
1905
1910
  ds.set_description({key: value_}, overwrite=overwrite)
@@ -22,6 +22,7 @@ from .deep4 import Deep4Net
22
22
  from .deepsleepnet import DeepSleepNet
23
23
  from .dgcnn import DGCNN
24
24
  from .diver1 import DIVER1
25
+ from .duin import DuIN
25
26
  from .eeg_clip import EEGCLIP
26
27
  from .eegconformer import EEGConformer
27
28
  from .eegdino import EEGDINO
@@ -119,6 +120,7 @@ __all__ = [
119
120
  "Deep4Net",
120
121
  "DeepSleepNet",
121
122
  "DIVER1",
123
+ "DuIN",
122
124
  "BrainModule",
123
125
  "Brant",
124
126
  "EEGCLIP",
@@ -14,6 +14,7 @@ from braindecode.models.base import EEGModuleMixin
14
14
  from braindecode.models.util import extract_channel_locations_from_chs_info
15
15
  from braindecode.modules import GatedLinearUnit, PatchTokenizer
16
16
  from braindecode.modules.attention import _scaled_dot_product_attention
17
+ from braindecode.modules.blocks import _check_on_non_divisible, _patch_count
17
18
 
18
19
 
19
20
  class BaRISTA(EEGModuleMixin, nn.Module, license="other"):
@@ -77,7 +78,8 @@ class BaRISTA(EEGModuleMixin, nn.Module, license="other"):
77
78
  .. rubric:: Temporal, Spatial, and Spectral Encoding
78
79
 
79
80
  - Temporal encoding uses non-overlapping patches and patch-index rotary
80
- embeddings. Samples beyond the last complete patch are dropped.
81
+ embeddings. By default a trailing partial patch is right zero-padded;
82
+ ``on_non_divisible="crop"`` drops it, as the reference does.
81
83
  - Spatial encoding uses dataset-provided coordinate or region indices.
82
84
  ``spatial_scale="none"`` disables it.
83
85
  - The CNN operates on waveforms. There is no explicit spectral transform.
@@ -94,7 +96,8 @@ class BaRISTA(EEGModuleMixin, nn.Module, license="other"):
94
96
  Treebank's coordinate convention.
95
97
 
96
98
  With ``pooling="mean"``, channel counts and window lengths can vary between
97
- batches, provided each window contains a full patch. Pass each recording's
99
+ batches (with ``on_non_divisible="crop"``, provided each window contains a
100
+ full patch). Pass each recording's
98
101
  indices to :meth:`forward`; otherwise it uses the constructor's indices
99
102
  or MNE positions. All samples in one batch
100
103
  share a montage. The encoder uses PyTorch attention on separate batch
@@ -141,9 +144,13 @@ class BaRISTA(EEGModuleMixin, nn.Module, license="other"):
141
144
  in millimetres when deriving indices from ``chs_info``.
142
145
  patch_size : int
143
146
  Number of samples per temporal patch, default 512 (250 ms at the
144
- paper's 2048 Hz). Windows are tokenized into whole patches, so a window
145
- that is not a multiple of ``patch_size`` loses its trailing samples, as
146
- in the reference.
147
+ paper's 2048 Hz).
148
+ on_non_divisible : {"pad", "crop", "error"}, default="pad"
149
+ How :class:`~braindecode.modules.PatchTokenizer` treats a time axis that
150
+ is not a multiple of ``patch_size`` (right zero-pad, crop, or raise).
151
+ The reference implementation crops (``"crop"``: the trailing samples
152
+ are lost); both give the same model and output when ``n_times`` is a
153
+ multiple of ``patch_size``.
147
154
  d_model : int
148
155
  Token embedding dimension.
149
156
  n_layers : int
@@ -180,6 +187,9 @@ class BaRISTA(EEGModuleMixin, nn.Module, license="other"):
180
187
  Systems 38. https://arxiv.org/abs/2512.12135
181
188
  """
182
189
 
190
+ # Configs and checkpoints saved before ``on_non_divisible`` existed cropped.
191
+ _legacy_on_non_divisible = "crop"
192
+
183
193
  def __init__(
184
194
  self,
185
195
  # --- signal-related (handled by EEGModuleMixin) ---
@@ -195,6 +205,7 @@ class BaRISTA(EEGModuleMixin, nn.Module, license="other"):
195
205
  spatial_indices: list[int] | list[list[int]] | None = None,
196
206
  coord_bins: int = 200,
197
207
  patch_size: int = 512,
208
+ on_non_divisible: str = "pad",
198
209
  d_model: int = 64,
199
210
  n_layers: int = 12,
200
211
  num_heads: int = 4,
@@ -243,8 +254,7 @@ class BaRISTA(EEGModuleMixin, nn.Module, license="other"):
243
254
  raise ValueError(f"{name} must be positive, got {value}.")
244
255
  if cnn_depth < 0:
245
256
  raise ValueError(f"cnn_depth must be non-negative, got {cnn_depth}.")
246
- if self.n_times < patch_size:
247
- raise ValueError("n_times must contain at least one full patch.")
257
+ _check_on_non_divisible(on_non_divisible)
248
258
  if d_model % num_heads:
249
259
  raise ValueError(
250
260
  f"d_model ({d_model}) must be divisible by num_heads ({num_heads})."
@@ -258,6 +268,7 @@ class BaRISTA(EEGModuleMixin, nn.Module, license="other"):
258
268
  self.spatial_scale = spatial_scale
259
269
  self.coord_bins = coord_bins
260
270
  self.patch_size = patch_size
271
+ self.on_non_divisible = on_non_divisible
261
272
  self.d_model = d_model
262
273
  self.n_layers = n_layers
263
274
  self.num_heads = num_heads
@@ -266,14 +277,15 @@ class BaRISTA(EEGModuleMixin, nn.Module, license="other"):
266
277
  self.drop_prob = drop_prob
267
278
  self.activation = activation
268
279
 
269
- # The trailing samples are dropped when n_times is not a multiple of
270
- # patch_size, as in the reference.
271
- self.n_patches = self.n_times // patch_size
280
+ # ceil(n_times / patch_size) with "pad"; floor with "crop" (the
281
+ # reference: trailing samples dropped, raises below one patch); exact
282
+ # with "error" (raises otherwise). The learned pooling is sized to it.
283
+ self.n_patches = _patch_count(self.n_times, patch_size, on_non_divisible)
272
284
 
273
285
  self.patch_tokenizer = PatchTokenizer(
274
286
  patch_size=patch_size,
275
287
  n_times=self.n_times,
276
- on_non_divisible="crop",
288
+ on_non_divisible=on_non_divisible,
277
289
  output_order="patch_channel",
278
290
  )
279
291
  # Every (patch, channel) pair is encoded independently, so the grid is
@@ -608,9 +608,24 @@ class EEGModuleMixin(_BaseHubMixin, metaclass=_BraindecodeDocstringMeta):
608
608
  """
609
609
  config = dict(config) # shallow copy
610
610
  config.pop("braindecode_version", None)
611
+ cls._fill_legacy_defaults(config)
611
612
  resolve_type_kwargs(cls, config)
612
613
  return cls(**config)
613
614
 
615
+ @classmethod
616
+ def _fill_legacy_defaults(cls, kwargs: dict) -> None:
617
+ """Rebuild configs saved before ``on_non_divisible`` existed as they were.
618
+
619
+ Models that used to crop a time axis not divisible by their patch size
620
+ set ``_legacy_on_non_divisible = "crop"``. A saved config or checkpoint
621
+ without the ``on_non_divisible`` key then loads with ``"crop"``, so its
622
+ head and position tables keep their shapes; a new model defaults to
623
+ ``"pad"``.
624
+ """
625
+ legacy = getattr(cls, "_legacy_on_non_divisible", None)
626
+ if legacy is not None and "on_non_divisible" not in kwargs:
627
+ kwargs["on_non_divisible"] = legacy
628
+
614
629
  def _set_n_outputs(self, n_outputs: int) -> None:
615
630
  """Record a new ``n_outputs`` on the model and its saved configs.
616
631
 
@@ -911,6 +926,9 @@ class EEGModuleMixin(_BaseHubMixin, metaclass=_BraindecodeDocstringMeta):
911
926
  ):
912
927
  model_kwargs.pop("braindecode_version", None)
913
928
  filename = model_kwargs.pop("filename", None)
929
+ # The Hub mixin passes only the keys of config.json (plus the
930
+ # caller's), so a missing key means a pre-on_non_divisible save.
931
+ cls._fill_legacy_defaults(model_kwargs)
914
932
  resolve_type_kwargs(cls, model_kwargs)
915
933
 
916
934
  # Read saved n_outputs from config.json to detect when the
@@ -13,6 +13,7 @@ from einops.layers.torch import Rearrange, Reduce
13
13
  from braindecode.functional import spectral_input
14
14
  from braindecode.models.base import EEGModuleMixin
15
15
  from braindecode.modules import PatchTokenizer
16
+ from braindecode.modules.blocks import _check_on_non_divisible, _patch_count
16
17
 
17
18
  # Standard rhythmic-activity bands (Hz) used by Brant's frequency encoding,
18
19
  # from the paper (§ Frequency encoding): theta, alpha, beta, gamma1-5.
@@ -96,6 +97,8 @@ class Brant(EEGModuleMixin, nn.Module, license="apache-2.0"):
96
97
  ``return_features=True`` returns ``cls_token=None``. The learned temporal
97
98
  positions require the runtime signal length to equal the configured
98
99
  ``n_times``, and the input must have the configured ``n_chans`` channels.
100
+ A window that is not a multiple of ``patch_size`` is right zero-padded to
101
+ ``ceil(n_times / patch_size)`` patches by default (``on_non_divisible``).
99
102
 
100
103
  The upstream model operates on signals down-sampled to **250 Hz**, but its
101
104
  band-power features are computed at a fixed 256 Hz (upstream
@@ -127,6 +130,11 @@ class Brant(EEGModuleMixin, nn.Module, license="apache-2.0"):
127
130
  patch_size : int, optional
128
131
  Number of time samples per patch fed to the encoders. Default 250
129
132
  (1 s at 250 Hz). The paper's large architecture uses 1500 (see above).
133
+ on_non_divisible : {"pad", "crop", "error"}, default="pad"
134
+ How :class:`~braindecode.modules.PatchTokenizer` treats a time axis that
135
+ is not a multiple of ``patch_size`` (right zero-pad, crop, or raise).
136
+ The reference implementation crops (``"crop"``); both give the same
137
+ model and output when ``n_times`` is a multiple of ``patch_size``.
130
138
  embed_dim : int, optional
131
139
  Model width ``D`` (patch embedding size). Default 256.
132
140
  ffn_dim : int, optional
@@ -156,6 +164,9 @@ class Brant(EEGModuleMixin, nn.Module, license="apache-2.0"):
156
164
  NeurIPS. Code: https://github.com/yzz673/Brant (Apache-2.0).
157
165
  """
158
166
 
167
+ # Configs and checkpoints saved before ``on_non_divisible`` existed cropped.
168
+ _legacy_on_non_divisible = "crop"
169
+
159
170
  def __init__(
160
171
  self,
161
172
  # braindecode parameters
@@ -168,6 +179,7 @@ class Brant(EEGModuleMixin, nn.Module, license="apache-2.0"):
168
179
  *,
169
180
  # model-specific parameters
170
181
  patch_size: int = 250,
182
+ on_non_divisible: str = "pad",
171
183
  embed_dim: int = 256,
172
184
  ffn_dim: int = 384,
173
185
  temporal_n_layers: int = 4,
@@ -192,6 +204,7 @@ class Brant(EEGModuleMixin, nn.Module, license="apache-2.0"):
192
204
  del n_outputs, n_chans, chs_info, n_times, input_window_seconds, sfreq
193
205
 
194
206
  self.patch_size = patch_size
207
+ self.on_non_divisible = on_non_divisible
195
208
  self.embed_dim = embed_dim
196
209
  self.ffn_dim = ffn_dim
197
210
  self.temporal_n_layers = temporal_n_layers
@@ -207,12 +220,10 @@ class Brant(EEGModuleMixin, nn.Module, license="apache-2.0"):
207
220
  )
208
221
  # Number of patches per channel, fixed by the input length. The learnable
209
222
  # temporal positional encoding is sized to it, hence n_times is required.
210
- self.seq_len = self.n_times // self.patch_size
211
- if self.seq_len < 1:
212
- raise ValueError(
213
- f"n_times ({self.n_times}) must be >= patch_size "
214
- f"({self.patch_size}) to form at least one patch."
215
- )
223
+ # ceil for "pad", floor for "crop" (raises below one patch), exact for
224
+ # "error" (raises otherwise): the count the tokenizer produces.
225
+ _check_on_non_divisible(on_non_divisible)
226
+ self.seq_len = _patch_count(self.n_times, self.patch_size, on_non_divisible)
216
227
 
217
228
  # Shared non-overlapping patching (same tokenizer as the other
218
229
  # transformer foundation models); non-learnable, so it is a pure reshape
@@ -222,7 +233,7 @@ class Brant(EEGModuleMixin, nn.Module, license="apache-2.0"):
222
233
  patch_size=self.patch_size,
223
234
  n_times=self.n_times,
224
235
  learnable=False,
225
- on_non_divisible="crop",
236
+ on_non_divisible=on_non_divisible,
226
237
  )
227
238
  # braindecode-native: band-power computed inside forward (see module).
228
239
  self.band_power = _BandPowerFeatures(
@@ -14,11 +14,15 @@ import torch.nn.functional as F
14
14
  from torch import nn
15
15
  from torch.nn.utils.parametrizations import weight_norm
16
16
 
17
- from braindecode.functional import spectral_input
17
+ from braindecode.functional import _real_dft, spectral_input
18
18
  from braindecode.functional.functions import _next_fast_len
19
19
  from braindecode.models.base import EEGModuleMixin
20
20
  from braindecode.modules.attention import _hpu_lazy
21
21
 
22
+ # Cache of one-sided DFT cosine/sine bases keyed by (device, n_fft): the TUEG
23
+ # geometry reuses one basis for every block, forward and backward.
24
+ _REAL_DFT_BASIS: Dict[Tuple[str, int], Tuple[torch.Tensor, torch.Tensor]] = {}
25
+
22
26
 
23
27
  class CodeBrain(EEGModuleMixin, nn.Module):
24
28
  r"""CodeBrain: Scalable Code EEG Pre-Training for Unified Downstream BCI Tasks.
@@ -528,16 +532,23 @@ class _GConv(nn.Module):
528
532
  # so any FFT length >= 2 * seq_len works: take a 5-smooth (fast) one.
529
533
  start = seq_len if self.bidirectional else 0
530
534
  n_fft = 2 * _next_fast_len(seq_len)
531
- # kernel_freq: (channels, d_model, freq_bins)
532
- # spectral_input(x) dtype: x's, at least float32 (the reference's .float()).
533
- x_in = spectral_input(x)
534
- kernel_freq = torch.fft.rfft(kernel.roll(start, -1).to(x_in), n=n_fft)
535
- # x_freq: (batch, d_model, freq_bins)
536
- x_freq = torch.fft.rfft(x_in, n=n_fft)
537
- # out_freq: (batch, channels, d_model, freq_bins)
538
- out_freq = torch.einsum("bhl,chl->bchl", x_freq, kernel_freq)
539
- # out: (batch, channels, d_model, seq_len)
540
- out = torch.fft.irfft(out_freq, n=n_fft)[..., start : start + seq_len].to(x)
535
+ if not torch.jit.is_scripting() and _real_dft.needs_real_dft(x):
536
+ # Intel Gaudi (HPU) has no complex tensors: the torch.fft path
537
+ # below is offloaded to the host (~120 ms/block/step in copies).
538
+ # The real-valued equivalent runs the DFT as MME matmuls on the
539
+ # device (~32 ms/block). CPU/CUDA keep the torch.fft path.
540
+ out = self._forward_real_dft(x, kernel, start, n_fft).to(x.dtype)
541
+ else:
542
+ # kernel_freq: (channels, d_model, freq_bins)
543
+ # spectral_input(x) dtype: x's, at least float32 (the reference's .float()).
544
+ x_in = spectral_input(x)
545
+ kernel_freq = torch.fft.rfft(kernel.roll(start, -1).to(x_in), n=n_fft)
546
+ # x_freq: (batch, d_model, freq_bins)
547
+ x_freq = torch.fft.rfft(x_in, n=n_fft)
548
+ # out_freq: (batch, channels, d_model, freq_bins)
549
+ out_freq = torch.einsum("bhl,chl->bchl", x_freq, kernel_freq)
550
+ # out: (batch, channels, d_model, seq_len)
551
+ out = torch.fft.irfft(out_freq, n=n_fft)[..., start : start + seq_len].to(x)
541
552
 
542
553
  # Skip connection via learnable D matrix
543
554
  # (batch, channels, d_model, seq_len)
@@ -562,6 +573,59 @@ class _GConv(nn.Module):
562
573
  return out, kernel
563
574
  return out, None
564
575
 
576
+ @torch.jit.unused
577
+ @_real_dft.fp32_island
578
+ def _forward_real_dft(self, x, kernel, start, n_fft):
579
+ # Real-valued equivalent of the torch.fft spectral section above, for
580
+ # devices without complex tensors (Intel Gaudi / HPU), in float32 with
581
+ # autocast disabled. The kernel is rolled to lags -L..L-1 exactly as
582
+ # above, so the bins match torch.fft.rfft(..., n=n_fft); the product
583
+ # is the complex multiplication as 4 real broadcast elementwise ops;
584
+ # the inverse is _real_dft.real_irfft and the [start:start+seq_len]
585
+ # read matches the torch path's window. ``torch.jit.unused`` keeps
586
+ # this branch out of the scripted graph: CPU/CUDA never take it, and
587
+ # HPU does not run under torch.jit.script. The cosine/sine basis is
588
+ # cached per (device, n_fft): one basis serves every block.
589
+ key = (str(x.device), n_fft)
590
+ basis = _REAL_DFT_BASIS.get(key)
591
+ if basis is None:
592
+ cosine, sine = _real_dft.real_dft_basis(
593
+ n_fft, device=x.device, dtype=torch.float32
594
+ )
595
+ basis = (cosine, sine)
596
+ _REAL_DFT_BASIS[key] = basis
597
+ cosine, sine = basis
598
+ seq_len = x.size(-1)
599
+ k_rolled = kernel.roll(start, -1)
600
+ # Re/Im of rfft(kernel, n=n_fft): pad/crop rows to n_fft, matmul.
601
+ # NOTE: after the bidirectional combine the kernel length is
602
+ # 2 * seq_len, not seq_len, so pad by its own length (torch.fft
603
+ # with n=n_fft pads/crops the same way).
604
+ k_len = k_rolled.size(-1)
605
+ if k_len < n_fft:
606
+ k_pad = F.pad(k_rolled.float(), (0, n_fft - k_len))
607
+ elif k_len > n_fft:
608
+ k_pad = k_rolled[..., :n_fft].float()
609
+ else:
610
+ k_pad = k_rolled.float()
611
+ k_re = k_pad @ cosine.transpose(0, 1)
612
+ k_im = -(k_pad @ sine.transpose(0, 1))
613
+ # Re/Im of rfft(x, n=n_fft) (x already padded below via the same op).
614
+ x_pad = F.pad(x.float(), (0, n_fft - seq_len))
615
+ x_re = x_pad @ cosine.transpose(0, 1)
616
+ x_im = -(x_pad @ sine.transpose(0, 1))
617
+ # Complex product as 4 real broadcast elementwise ops.
618
+ out_re = x_re.unsqueeze(1) * k_re.unsqueeze(0) - x_im.unsqueeze(
619
+ 1
620
+ ) * k_im.unsqueeze(0)
621
+ out_im = x_re.unsqueeze(1) * k_im.unsqueeze(0) + x_im.unsqueeze(
622
+ 1
623
+ ) * k_re.unsqueeze(0)
624
+ out = _real_dft.real_irfft(out_re, out_im, n=n_fft)[
625
+ ..., start : start + seq_len
626
+ ]
627
+ return out
628
+
565
629
 
566
630
  class _Conv(nn.Module):
567
631
  def __init__(self, in_channels, out_channels, kernel_size=3, dilation=1):
@@ -15,12 +15,12 @@ from typing import Dict, List, Optional, Tuple, Union
15
15
 
16
16
  import torch
17
17
  import torch.nn.functional as F
18
- from einops.layers.torch import Rearrange
19
18
  from torch import Tensor, nn
20
19
 
21
20
  from braindecode.models.base import EEGModuleMixin
22
21
  from braindecode.models.cbramod import _PatchEmbedding
23
22
  from braindecode.modules import FeedForwardBlock
23
+ from braindecode.modules.blocks import PatchTokenizer, _patch_count
24
24
 
25
25
  log = logging.getLogger(__name__)
26
26
 
@@ -210,6 +210,9 @@ class CSBrain(EEGModuleMixin, nn.Module):
210
210
  ----------
211
211
  patch_size : int, default=200
212
212
  Temporal patch size in samples (200 samples = 1 second at 200 Hz).
213
+ on_non_divisible : {"pad", "crop", "error"}, default="pad"
214
+ How :class:`~braindecode.modules.PatchTokenizer` treats a time axis that
215
+ is not a multiple of ``patch_size`` (right zero-pad, crop, or raise).
213
216
  dim_feedforward : int, default=800
214
217
  Dimension of the feedforward network in the encoder layers.
215
218
  n_layer : int, default=12
@@ -292,6 +295,7 @@ class CSBrain(EEGModuleMixin, nn.Module):
292
295
  input_window_seconds=None,
293
296
  sfreq=None,
294
297
  patch_size: int = 200,
298
+ on_non_divisible: str = "pad",
295
299
  dim_feedforward: int = 800,
296
300
  n_layer: int = 12,
297
301
  nhead: int = 8,
@@ -314,16 +318,16 @@ class CSBrain(EEGModuleMixin, nn.Module):
314
318
  sfreq=sfreq,
315
319
  )
316
320
  del n_chans, chs_info, n_times, input_window_seconds, sfreq, n_outputs
317
- n_times = self._n_times_or_none()
318
- if n_times is not None and n_times % patch_size:
319
- raise ValueError(
320
- f"n_times ({n_times}) must be a multiple of patch_size ({patch_size})."
321
- )
322
-
323
- self.rearrange = Rearrange(
324
- "batch n_chans (n_patch patch_size) -> batch n_chans n_patch patch_size",
321
+ try:
322
+ tokenizer_n_times = self.n_times
323
+ except ValueError: # unknown length: nothing to check at construction
324
+ tokenizer_n_times = patch_size
325
+ self.rearrange = PatchTokenizer(
325
326
  patch_size=patch_size,
327
+ n_times=tokenizer_n_times,
328
+ on_non_divisible=on_non_divisible,
326
329
  )
330
+ self._on_non_divisible = on_non_divisible
327
331
  # CBraMod's patch encoder: conv stem + rFFT magnitude + depthwise-conv PE.
328
332
  # CBraMod creates the positional-encoding conv before the conv stem, so
329
333
  # build it with the RNG forked (CPU and the default device's generator
@@ -429,14 +433,23 @@ class CSBrain(EEGModuleMixin, nn.Module):
429
433
  except ValueError:
430
434
  return None
431
435
 
436
+ def _n_patch(self) -> int | None:
437
+ n_times = self._n_times_or_none()
438
+ if n_times is None:
439
+ return None
440
+ # ceil for "pad", floor for "crop" (raises below one patch): the count
441
+ # the tokenizer produces.
442
+ return _patch_count(n_times, self._patch_size, self._on_non_divisible)
443
+
432
444
  def _make_task_head(self) -> nn.Sequential:
433
445
  # Three-layer MLP head of the reference fine-tuning models: flatten
434
446
  # (chans, patches, emb_dim) -> n_patch * emb_dim -> emb_dim -> n_outputs.
435
447
  # n_chans / n_times may come from chs_info / input_window_seconds.
436
448
  # Without them the layers are lazy and the hidden width falls back to
437
449
  # 4 * emb_dim, the reference value for 4 s windows.
438
- n_chans, n_times = self._n_chans_or_none(), self._n_times_or_none()
439
- if n_times is None or n_chans is None:
450
+ n_chans = self._n_chans_or_none()
451
+ n_patch = self._n_patch()
452
+ if n_patch is None or n_chans is None:
440
453
  return nn.Sequential(
441
454
  nn.Flatten(),
442
455
  nn.LazyLinear(self._head_hidden_dim or 4 * self._emb_dim),
@@ -447,7 +460,6 @@ class CSBrain(EEGModuleMixin, nn.Module):
447
460
  nn.Dropout(self._head_drop_prob),
448
461
  nn.LazyLinear(self.n_outputs),
449
462
  )
450
- n_patch = n_times // self._patch_size
451
463
  hidden = self._head_hidden_dim or n_patch * self._emb_dim
452
464
  return nn.Sequential(
453
465
  nn.Flatten(),