bruAristimunha commited on
Commit
857f1e3
·
verified ·
1 Parent(s): 089a70c

Add Braindecode-format MIRepNet checkpoint

Browse files
LICENSE ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Dingkun Liu
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
README.md ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ library_name: braindecode
3
+ license: mit
4
+ tags:
5
+ - braindecode
6
+ - eeg
7
+ - motor-imagery
8
+ - foundation-model
9
+ ---
10
+
11
+ # MIRepNet
12
+
13
+ Braindecode-format re-host of the official MIRepNet checkpoint released by
14
+ Liu et al. The checkpoint can be loaded directly through Braindecode's standard
15
+ Hugging Face integration:
16
+
17
+ ```python
18
+ from braindecode.models import MIRepNet
19
+
20
+ model = MIRepNet.from_pretrained("braindecode/mirepnet-pretrained")
21
+
22
+ # Fine-tuning for another task replaces the released three-class head.
23
+ model = MIRepNet.from_pretrained(
24
+ "braindecode/mirepnet-pretrained",
25
+ n_outputs=4,
26
+ )
27
+ ```
28
+
29
+ ## Released configuration
30
+
31
+ - 45 channels in the order stored in `mirepnet_channels.json`
32
+ - 1,000 samples at 250 Hz
33
+ - 256-dimensional embedding
34
+ - 6 Transformer blocks with 8 heads
35
+ - 3-output supervised pretraining head
36
+
37
+ The paper's 8--30 Hz filtering, resampling, channel-template preparation, and
38
+ Euclidean alignment are preprocessing steps and are not performed by the model.
39
+
40
+ ## Provenance and conversion
41
+
42
+ - Official code: https://github.com/staraink/MIRepNet at revision
43
+ `edb80d7605f75ba8b72b417a124cc9db07385f72`
44
+ - Official checkpoint: https://huggingface.co/starself/MIRepNet at revision
45
+ `9bac0439c0d3e9ffdb40ca675d61a51b439a446e`
46
+ - Source file: `MIRepNet.pth`, SHA-256
47
+ `432288958007e344a5a84a9ffe9d0e5e5c0cb616aef86c85522375a3f4da9aaf`
48
+
49
+ All 109 downstream tensors were converted. The 34 pretraining-only tensors
50
+ (`mask_token`, `decoder.*`, and the upstream `embedding.chan_embed.weight`,
51
+ which is not used by the released forward pass) were intentionally omitted.
52
+ Against the official implementation, maximum absolute error was `2.38e-7` for
53
+ pooled features and `1.19e-7` for logits. The conversion is reproducible with
54
+ `convert_mirepnet_checkpoint.py`.
55
+
56
+ The source code and checkpoint are distributed under the MIT License. The
57
+ original copyright notice is preserved in `LICENSE`.
58
+
59
+ ## Limitations
60
+
61
+ The official repository does not document the semantic ordering of the three
62
+ pretraining-head outputs. Replace the head with `n_outputs=...` and fine-tune it
63
+ for downstream use unless that label mapping has been independently verified.
64
+ Dataset licenses are separate from the checkpoint's MIT license.
65
+
66
+ ## Citation
67
+
68
+ ```bibtex
69
+ @article{LIU2026115966,
70
+ title = {MIRepNet: A pipeline and pre-trained model for EEG-based motor imagery classification},
71
+ journal = {Knowledge-Based Systems},
72
+ volume = {343},
73
+ pages = {115966},
74
+ year = {2026},
75
+ issn = {0950-7051},
76
+ doi = {10.1016/j.knosys.2026.115966},
77
+ url = {https://www.sciencedirect.com/science/article/pii/S0950705126006921},
78
+ author = {Dingkun Liu and Zhu Chen and Jingwei Luo and Shijie Lian and Yuheng Chen and Shaojie Hou and Xiaolian Zhu and Dongrui Wu}
79
+ }
80
+ ```
config.json ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "n_outputs": 3,
3
+ "n_chans": 45,
4
+ "chs_info": null,
5
+ "n_times": 1000,
6
+ "input_window_seconds": null,
7
+ "sfreq": 250,
8
+ "embed_dim": 256,
9
+ "n_filters_time": 64,
10
+ "n_filters_spat": 128,
11
+ "filter_time_length": 25,
12
+ "pool_time_length": 75,
13
+ "pool_time_stride": 15,
14
+ "num_layers": 6,
15
+ "num_heads": 8,
16
+ "feedforward_expansion": 4,
17
+ "activation": "torch.nn.modules.activation.ELU",
18
+ "activation_trans": "torch.nn.modules.activation.GELU",
19
+ "drop_prob": 0.5,
20
+ "att_drop_prob": 0.5,
21
+ "feedforward_drop_prob": 0.5,
22
+ "attention_scale": null,
23
+ "return_features": false,
24
+ "braindecode_version": "1.8.0dev0"
25
+ }
convert_mirepnet_checkpoint.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Convert the official MIRepNet checkpoint to Braindecode Hub format."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import argparse
6
+ import hashlib
7
+ from pathlib import Path
8
+
9
+ import torch
10
+
11
+ from braindecode.models import MIRepNet
12
+
13
+
14
+ SOURCE_SHA256 = "432288958007e344a5a84a9ffe9d0e5e5c0cb616aef86c85522375a3f4da9aaf"
15
+
16
+
17
+ def main() -> None:
18
+ parser = argparse.ArgumentParser()
19
+ parser.add_argument("source", type=Path)
20
+ parser.add_argument("output", type=Path)
21
+ args = parser.parse_args()
22
+
23
+ if hashlib.sha256(args.source.read_bytes()).hexdigest() != SOURCE_SHA256:
24
+ raise ValueError("Source checkpoint SHA-256 does not match the official file.")
25
+
26
+ source = torch.load(args.source, map_location="cpu", weights_only=True)
27
+ model = MIRepNet(n_chans=45, n_outputs=3, n_times=1000, sfreq=250)
28
+ incompatible = model.load_state_dict(source, strict=False)
29
+ expected_unexpected = {
30
+ "mask_token",
31
+ "embedding.chan_embed.weight",
32
+ *(key for key in source if key.startswith("decoder.")),
33
+ }
34
+ if (
35
+ incompatible.missing_keys
36
+ or set(incompatible.unexpected_keys) != expected_unexpected
37
+ ):
38
+ raise RuntimeError(f"Unexpected conversion result: {incompatible}")
39
+ model.save_pretrained(args.output)
40
+
41
+
42
+ if __name__ == "__main__":
43
+ main()
mirepnet_channels.json ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [
2
+ "F7",
3
+ "F5",
4
+ "F3",
5
+ "F1",
6
+ "FZ",
7
+ "F2",
8
+ "F4",
9
+ "F6",
10
+ "F8",
11
+ "FT7",
12
+ "FC5",
13
+ "FC3",
14
+ "FC1",
15
+ "FCZ",
16
+ "FC2",
17
+ "FC4",
18
+ "FC6",
19
+ "FT8",
20
+ "T7",
21
+ "C5",
22
+ "C3",
23
+ "C1",
24
+ "CZ",
25
+ "C2",
26
+ "C4",
27
+ "C6",
28
+ "T8",
29
+ "TP7",
30
+ "CP5",
31
+ "CP3",
32
+ "CP1",
33
+ "CPZ",
34
+ "CP2",
35
+ "CP4",
36
+ "CP6",
37
+ "TP8",
38
+ "P7",
39
+ "P5",
40
+ "P3",
41
+ "P1",
42
+ "PZ",
43
+ "P2",
44
+ "P4",
45
+ "P6",
46
+ "P8"
47
+ ]
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a3a7eb0f100b703cd40ee2ed634dbc04d1f6ae04931404299dc2f81c4175559b
3
+ size 20583836
pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:59aae4feec85074ba7ab7f7e492b281cb861f0e529d5bf1dbd81c0ca04b2a3aa
3
+ size 20613566