RSM-CoDG:Region-aware Spatiotemporal Modeling with Collaborative Domain Generalization for Cross-Subject EEG Emotion Recognition
RSM-CoDG is an EEG emotion recognition pipeline exemplified on the SEED-III (seed3) dataset, and can be adapted to other datasets with the same 62-channel, 5-band DE-format. It combines:
- A region-aware graph module (RGRM) to model spatial structure across 62 EEG channels and 5 frequency bands.
- A multi-scale temporal transformer (MSTT) for local and sparse global temporal attention.
- A collaborative domain generalization head (CoDG) with three complementary losses (attention contrastive, feature orthogonality, MMD) to improve cross-subject transfer.
Training follows leave-one-subject-out: each fold holds one subject out for testing while the remaining subjects are sources. TensorBoard logs and checkpoints are saved per fold.
main.py— CLI entry, experiment setup, LOSO loop.model.py— RGRM, MSTT, CoDG, and model wrappers.preprocess.py— SEED-III data loading and windowing utilities.GradientReverseLayer.py,event.py— auxiliary components/utilities.
- Python 3.8+ (tested with PyTorch GPU)
- PyTorch, torchvision (CUDA build recommended)
- NumPy, SciPy
- scikit-learn (for optional detailed eval)
- tensorboard
Install (minimal):
pip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu121
pip install numpy scipy scikit-learn tensorboard- Set
--seed3_pathto the root directory containing SEED-III DE features and labels. For other datasets, point the path flags to your data root and provide matching label/layout conventions. - Expected structure:
<seed3_path>/
label.mat
1/<subject>_<...>.mat
2/<subject>_<...>.mat
3/<subject>_<...>.mat
sessionselects the subfolder (1,2, or3).- Each
.matunder a session contains keys starting withde_LDS*(62 channels × 5 bands × time).label.matholds session labels.
Example with seed3 (session 1, batch 512, default hyperparameters):
python main.py \
--dataset_name seed3 \
--session 1 \
--seed3_path /path/to/seed3/ \
--way RSM-CoDG/seed3 \
--index RSMCoDG_512 \
--batch_size 512 \
--epoch_training 200 \
--lr 1e-4 --weight_decay 5e-4Key flags:
--way,--index: tag TensorBoard and checkpoint folders.--dg_warmup_epochs,--dg_max_weight: schedule DG losses.--weight_feature_orthogonal,--weight_attention_contrastive,--weight_feature_mmd: weights for the three DG losses.--patience: early stopping patience.
Outputs:
- TensorBoard logs:
data/session<session>/<way>/<index>/ - Checkpoints/config:
model/<way>/<index>/(*_rsm_codg_model.pth,*_config.json)
During training each fold is evaluated on the held-out subject every epoch; best checkpoints per fold are stored. For standalone testing of a saved model, use the helpers in test.py (e.g., test_rsm_codg).
If you use RSM-CoDG in your research, please cite the corresponding paper
@article{wu2026region,
title={Region-aware Spatiotemporal Modeling with Collaborative Domain Generalization for Cross-Subject EEG Emotion Recognition},
author={Wu, Weiwei and Li, Yueyang and Shi, Yuhu and Zeng, Weiming and Qin, Lang and Yang, Yang and Zhou, Ke and Zhang, Zhiguo and Siok, Wai Ting and Wang, Nizhuan},
journal={arXiv preprint arXiv:2601.15615},
year={2026}
}