{"id":19331896,"url":"https://github.com/zhangks98/eeg-adapt","last_synced_at":"2025-08-24T09:34:37.542Z","repository":{"id":37630130,"uuid":"247424389","full_name":"zhangks98/eeg-adapt","owner":"zhangks98","description":"Source Code for \"Adaptive Transfer Learning with Deep CNN for EEG Motor Imagery Classification\".","archived":false,"fork":false,"pushed_at":"2023-01-11T16:05:21.000Z","size":30034,"stargazers_count":90,"open_issues_count":0,"forks_count":38,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-02T05:11:22.266Z","etag":null,"topics":["cnn","deep-learning","eeg","motor-imagery"],"latest_commit_sha":null,"homepage":"https://doi.org/10.1016/j.neunet.2020.12.013","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zhangks98.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-03-15T07:58:00.000Z","updated_at":"2025-03-13T07:40:09.000Z","dependencies_parsed_at":"2023-02-09T03:46:01.864Z","dependency_job_id":null,"html_url":"https://github.com/zhangks98/eeg-adapt","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhangks98%2Feeg-adapt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhangks98%2Feeg-adapt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhangks98%2Feeg-adapt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhangks98%2Feeg-adapt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zhangks98","download_url":"https://codeload.github.com/zhangks98/eeg-adapt/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250340444,"owners_count":21414551,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cnn","deep-learning","eeg","motor-imagery"],"created_at":"2024-11-10T02:42:55.785Z","updated_at":"2025-04-22T23:32:34.842Z","avatar_url":"https://github.com/zhangks98.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"Codes for adaptation of a subject-independent deep convolutional neural network (CNN) based electroencephalography (EEG)-BCI system for decoding hand motor imagery (MI). Five schemes are presented, each of which fine-tunes an extensively trained, pre-trained model and adapt it to enhance the evaluation performance on a target subject.\n\n## Citation\n```\n@article{ZHANG20211,\ntitle = \"Adaptive transfer learning for EEG motor imagery classification with deep Convolutional Neural Network\",\njournal = \"Neural Networks\",\nvolume = \"136\",\npages = \"1 - 10\",\nyear = \"2021\",\nissn = \"0893-6080\",\ndoi = \"https://doi.org/10.1016/j.neunet.2020.12.013\",\nurl = \"http://www.sciencedirect.com/science/article/pii/S0893608020304305\",\nauthor = \"Kaishuo Zhang and Neethu Robinson and Seong-Whan Lee and Cuntai Guan\",\n}\n```\n\n## Summary of Results\n\n| Methodology | Mean (SD) | Median | Range (Max-Min) |\n|-|-|-|-|\n| Subject-Specific | 63.54 (14.25) | 60.50 | 57.00 (100.00-43.00) |\n| Subject-Independent | 84.19 (9.98) | 84.50 | 47.50 (99.50-52.00) |\n| Subject-Adaptive\u003cbr\u003e(Scheme 4, 80%) | 86.89 (11.41) | 88.50 | 44.00 (100.00-56.00) |\n\nA detailed subject-level result can be found in [result_table.pdf](result_table.pdf)\n\n## Resources\n- Raw Dataset: [Link](http://gigadb.org/dataset/100542)\n- Sample pre-trained subject-independent model: [Link](https://github.com/zhangks98/eeg-adapt/tree/master/pretrained_models)\n\n## Instructions\n### Install the dependencies\nIt is recommended to create a virtual environment with python version 3.7 and activate it before running the following:\n```sh\npip install -r requirements.txt\n```\n\n### Obtain the raw dataset\nDownload the raw dataset from the [resources](#resources) above, and save them to the same folder. To conserve space, you may only download files that ends with `EEG_MI.mat`.\n\n### Pre-process the raw dataset\nThe following command will read the raw dataset from the `$source` folder, and output the pre-processed data `KU_mi_smt.h5` into the `$target` folder.\n```sh\npython preprocess_h5_smt.py $source $target\n```\n\n### Training and evaluation\n#### Subject-specific classification\n```\nusage: train_within.py [-h] [-gpu GPU] [-start START] [-end END] [-subj SUBJ [SUBJ ...]] datapath outpath\n\nSubject-specific classification with KU Data\n\npositional arguments:\n  datapath              Path to the h5 data file\n  outpath               Path to the result folder\n\noptional arguments:\n  -h, --help            show this help message and exit\n  -gpu GPU              The gpu device index to use\n  -start START          Start of the subject index\n  -end END              End of the subject index (not inclusive)\n  -subj SUBJ [SUBJ ...]\n                        Explicitly set the subject number. This will override the start and end argument\n```\nTo train the subject-specific model for all subjects, run\n```sh\npython train_within.py $datapath $outpath\n```\n\n#### Subject-independent classification\n```\nusage: train_base.py [-h] -fold FOLD [-gpu GPU] datapath outpath\n\nSubject independent classification with KU Data\n\npositional arguments:\n  datapath    Path to the h5 data file\n  outpath     Path to the result folder\n\noptional arguments:\n  -h, --help  show this help message and exit\n  -fold FOLD  k-fold index, starts with 0\n  -gpu GPU    The gpu device to use\n```\nThe `$fold` index has a one-to-one mapping to the subject index, as we have shuffled the subjects in a pre-defined order (using random seed 20200205). This is listed in [subj-to-fold.csv](subj-to-fold.csv) file.\n\nTo train the subject-independent model for all subjects, run\n```sh\npython train_base.py $datapath $outpath -fold $fold\n```\nfor `$fold` ranging [0...53] inclusive.\n\nThis process is likely to take some time. We have provided some sample pre-trained models in the [resources](#resources) above.\n\n#### Subject-adaptive classification\n```\nusage: train_adapt.py [-h] [-scheme SCHEME] [-trfrate TRFRATE] [-lr LR] [-gpu GPU] datapath modelpath outpath\n\nSubject adaptative classification with KU Data\n\npositional arguments:\n  datapath          Path to the h5 data file\n  modelpath         Path to the base model folder\n  outpath           Path to the result folder\n\noptional arguments:\n  -h, --help        show this help message and exit\n  -scheme SCHEME    Adaptation scheme\n  -trfrate TRFRATE  The percentage of data for adaptation\n  -lr LR            Learning rate\n  -gpu GPU          The gpu device to use\n```\nAs an example, to train the subject-adaptive model for all subjects using the default configuration (scheme 4, adaptation rate 100%, learning rate 0.0005), run: \n```sh\npython train_adapt.py $datapath $modelpath $outpath\n```\nThe `$modelpath` corresponds to the result folder of the [subject-independent classification](#subject-independent-classification), or the path to the pre-trained model.\n\n### Training on multiple GPUs\nTo speed up training, you can make use of multiple GPUs. In the `tasks_*` folder, we provide a sample script for training on 8 GPUs. To generate these scripts, run:\n```sh\npython generate.py\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzhangks98%2Feeg-adapt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzhangks98%2Feeg-adapt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzhangks98%2Feeg-adapt/lists"}