Add library and pipeline tag, include paper and Github info
#1
by
nielsr
HF Staff
- opened
README.md
CHANGED
|
@@ -1,4 +1,111 @@
|
|
| 1 |
---
|
| 2 |
license: apache-2.0
|
|
|
|
|
|
|
| 3 |
---
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
license: apache-2.0
|
| 3 |
+
library_name: pytorch
|
| 4 |
+
pipeline_tag: other
|
| 5 |
---
|
| 6 |
+
|
| 7 |
+
### There is the pretrained weights of CBraMod.
|
| 8 |
+
|
| 9 |
+
# CBraMod: A Criss-Cross Brain Foundation Model for EEG Decoding
|
| 10 |
+
|
| 11 |
+
[](https://arxiv.org/abs/2412.07236)
|
| 12 |
+
[](https://openreview.net/forum?id=NPNUHgHF2w)
|
| 13 |
+
[](https://huggingface.co/weighting666/CBraMod)
|
| 14 |
+

|
| 15 |
+
|
| 16 |
+
<div align="center">
|
| 17 |
+
<img src="figure/CBraMod_logo.png" style="width: 15%;" />
|
| 18 |
+
</div>
|
| 19 |
+
|
| 20 |
+
<p align="center">
|
| 21 |
+
π <a href="#-about">About</a>
|
| 22 |
+
| π¨ <a href="#-setup">Setup</a>
|
| 23 |
+
| π’ <a href="#-how-to-pretrain">How to Pretrain</a>
|
| 24 |
+
| β΅ <a href="#-how-to-finetune">How to Finetune</a>
|
| 25 |
+
| π <a href="#-quick-start">Quick Start</a>
|
| 26 |
+
| π <a href="#-citation">Citation</a>
|
| 27 |
+
</p>
|
| 28 |
+
|
| 29 |
+
π₯ NEWS: The paper "_CBraMod: A Criss-Cross Brain Foundation Model for EEG Decoding_" has been accepted by ICLR 2025!
|
| 30 |
+
|
| 31 |
+
## π About
|
| 32 |
+
We propose **CBraMod**, a novel EEG foundation model, for EEG decoding on various clinical and BCI application.
|
| 33 |
+
The preprint version of our paper is available at [arXiv](https://arxiv.org/abs/2412.07236).
|
| 34 |
+
The camera-ready version of the paper will be available at [OpenReview](https://openreview.net/forum?id=NPNUHgHF2w).
|
| 35 |
+
<div align="center">
|
| 36 |
+
<img src="figure/model.png" style="width:100%;" />
|
| 37 |
+
</div>
|
| 38 |
+
|
| 39 |
+
## π¨ Setup
|
| 40 |
+
Install [Python](https://www.python.org/downloads/).
|
| 41 |
+
|
| 42 |
+
Install [PyTorch](https://pytorch.org/get-started/locally/).
|
| 43 |
+
|
| 44 |
+
Install other requirements:
|
| 45 |
+
```commandline
|
| 46 |
+
pip install -r requirements.txt
|
| 47 |
+
```
|
| 48 |
+
|
| 49 |
+
## π’ How to Pretrain
|
| 50 |
+
You can pretrain CBraMod on our pretraining dataset or your custom pretraining dataset using the following code:
|
| 51 |
+
```commandline
|
| 52 |
+
python pretrain_main.py
|
| 53 |
+
```
|
| 54 |
+
We have released a pretrained checkpoint on [Hugginfaceπ€](https://huggingface.co/weighting666/CBraMod).
|
| 55 |
+
|
| 56 |
+
## β΅ How to Finetune
|
| 57 |
+
You can finetune CBraMod on our selected downstream datasets using the following code:
|
| 58 |
+
```commandline
|
| 59 |
+
python finetune_main.py
|
| 60 |
+
```
|
| 61 |
+
|
| 62 |
+
## π Quick Start
|
| 63 |
+
You can fine-tune the pretrained CBraMod on your custom downstream dataset using the following example code:
|
| 64 |
+
```python
|
| 65 |
+
import torch
|
| 66 |
+
import torch.nn as nn
|
| 67 |
+
from models.cbramod import CBraMod
|
| 68 |
+
from einops.layers.torch import Rearrange
|
| 69 |
+
|
| 70 |
+
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
|
| 71 |
+
model = CBraMod().to(device)
|
| 72 |
+
model.load_state_dict(torch.load('pretrained_weights/pretrained_weights.pth', map_location=device))
|
| 73 |
+
model.proj_out = nn.Identity()
|
| 74 |
+
classifier = nn.Sequential(
|
| 75 |
+
Rearrange('b c s p -> b (c s p)'),
|
| 76 |
+
nn.Linear(22*4*200, 4*200),
|
| 77 |
+
nn.ELU(),
|
| 78 |
+
nn.Dropout(0.1),
|
| 79 |
+
nn.Linear(4 * 200, 200),
|
| 80 |
+
nn.ELU(),
|
| 81 |
+
nn.Dropout(0.1),
|
| 82 |
+
nn.Linear(200, 4),
|
| 83 |
+
).to(device)
|
| 84 |
+
|
| 85 |
+
# mock_eeg.shape = (batch_size, num_of_channels, time_segments, points_per_patch)
|
| 86 |
+
mock_eeg = torch.randn((8, 22, 4, 200)).to(device)
|
| 87 |
+
|
| 88 |
+
# logits.shape = (batch_size, num_of_classes)
|
| 89 |
+
logits = classifier(model(mock_eeg))
|
| 90 |
+
```
|
| 91 |
+
|
| 92 |
+
## π Citation
|
| 93 |
+
If you're using this repository in your research or applications, please cite using the following BibTeX:
|
| 94 |
+
```bibtex
|
| 95 |
+
@inproceedings{wang2025cbramod,
|
| 96 |
+
title={{CB}raMod: A Criss-Cross Brain Foundation Model for {EEG} Decoding},
|
| 97 |
+
author={Jiquan Wang and Sha Zhao and Zhiling Luo and Yangxuan Zhou and Haiteng Jiang and Shijian Li and Tao Li and Gang Pan},
|
| 98 |
+
booktitle={The Thirteenth International Conference on Learning Representations},
|
| 99 |
+
year={2025},
|
| 100 |
+
url={https://openreview.net/forum?id=NPNUHgHF2w}
|
| 101 |
+
}
|
| 102 |
+
```
|
| 103 |
+
|
| 104 |
+
## β Star History
|
| 105 |
+
<div align="center">
|
| 106 |
+
<a href="https://star-history.com/#wjq-learning/CBraMod&Date">
|
| 107 |
+
<img src="https://api.star-history.com/svg?repos=wjq-learning/CBraMod&type=Date" style="width: 80%;" />
|
| 108 |
+
</a>
|
| 109 |
+
</div>
|
| 110 |
+
|
| 111 |
+
Code: https://github.com/wjq-learning/CBraMod
|