运动想象顶刊代码复现-2,数据集BCI IV-2a(python3.7+TensorFlow2.4.0)

记录自己学习过程中复现的代码 

原论文(出版时间2022.8)

Physics-Informed Attention Temporal Convolutional Network for EEG-Based Motor Imagery Classification
 

 期刊:( 影响因子11.6+)

IEEE TRANSACTIONS ON INDUSTRIAL INFORMATICS

摘要

英文:The brain-computer interface (BCI) is a cutting-edge technology that has the potential to change the world. Electroencephalogram (EEG) motor imagery (MI) signal has been used extensively in many BCI applications to assist disabled people, control devices or environments, and even augment human capabilities. However, the limited performance of brain signal decoding is restricting the broad growth of the BCI industry. In this article, we propose an attention-based temporal convolutional network (ATCNet) for EEG-based motor imagery classifification. The ATCNet model utilizes multiple techniques to boost the performance of MI classifification with a relatively small number of parameters. ATCNet employs scientifific machine learning to design a domain-specifific deep learning model with interpretable and explainable features, multihead self-attention to highlight the most valuable features in MI-EEG data, temporal convolutional network to extract high-level temporal features, and convolutional-based sliding window to augment the MI-EEG data effificiently. The proposed model outperforms the current state-of-the-art techniques in the BCI Competition IV-2a dataset with an accuracy of 85.38% and 70.97% for the subject-dependent and subject-independent modes, respectively.

翻译:脑机接口(BCI)是一项有可能改变世界的前沿技术。脑电图(EEG)运动图像(MI)信号已被广泛用于许多BCI应用中以协助残疾人控制设备或环境、甚至增强人的能力。然而大脑信号解码的有限性能限制了BCI行业的广泛发展。在这篇文章中,我们提出了一个基于注意力的时间卷积网络(ATCNet)用于基于EEG的运动图像分类。该ATCNet模型利用多种技术来提高MI分类的性能,参数数量相对较少。ATCNet采用了科学的机器学习来设计一个特定领域的深度学习模型,具有可解释和可说明的特征,多头自我关注来突出MI-EEG数据中最有价值的特征,时间卷积网络来提取高层次的时间特征,以及基于卷积的滑动特征。颞部卷积网络提取高层次的时间特征,基于卷积的滑动窗口有效地增强了MI-EEG数据。所提出的模型在BCI中的表现优于目前最先进的技术。在IV-2a数据集中,提议的模型优于目前最先进的技术,准确率为85.38%和70.97%。

 技术路线图

 

 实验环境

CUDA = 11.0

cudnn = 8.0

python = 3.7

tensorflow =2.4.0

实验结果

Subject: 1   best_run: 1   acc: 0.9149   kappa: 0.8866   avg_acc: 0.8629 +- 0.0124   avg_kappa: 0.8171 +- 0.0166
Subject: 2   best_run: 1   acc: 0.8090   kappa: 0.7454   avg_acc: 0.6448 +- 0.0326   avg_kappa: 0.5264 +- 0.0435
Subject: 3   best_run: 1   acc: 0.9861   kappa: 0.9815   avg_acc: 0.9410 +- 0.0143   avg_kappa: 0.9213 +- 0.0191
Subject: 4   best_run: 1   acc: 0.8264   kappa: 0.7685   avg_acc: 0.7677 +- 0.0258   avg_kappa: 0.6903 +- 0.0344
Subject: 5   best_run: 1   acc: 0.8681   kappa: 0.8241   avg_acc: 0.8017 +- 0.0142   avg_kappa: 0.7356 +- 0.0189
Subject: 6   best_run: 5   acc: 0.8194   kappa: 0.7593   avg_acc: 0.7118 +- 0.0170   avg_kappa: 0.6157 +- 0.0227
Subject: 7   best_run: 10  acc: 0.7257   kappa: 0.6343   avg_acc: 0.8986 +- 0.0296   avg_kappa: 0.8648 +- 0.0394
Subject: 8   best_run: 7   acc: 0.9271   kappa: 0.9028   avg_acc: 0.8722 +- 0.0133   avg_kappa: 0.8296 +- 0.0178
Subject: 9   best_run: 1   acc: 0.9080   kappa: 0.8773   avg_acc: 0.8778 +- 0.0186   avg_kappa: 0.8370 +- 0.0247

Average of 9 subjects - best runs:
Accuracy = 0.8650   Kappa = 0.8200

Average of 9 subjects x 10 runs (average of 90 experiments):
Accuracy = 0.8198   Kappa = 0.7598
 

 

源码

已上传我的资源:https://download.csdn.net/download/Nan_Feng_ya/88915595icon-default.png?t=N7T8https://download.csdn.net/download/Nan_Feng_ya/88915595

 结束

BCI Competition IV 2a数据集转换为Legacy TU Dataset的Python代码如下: ```python import numpy as np import mne # Load the BCI Competition IV 2a dataset data_train = np.load('A01T.npz') data_test = np.load('A01E.npz') # Extract features and labels from the dataset X_train = data_train['data'] y_train = data_train['labels'] X_test = data_test['data'] y_test = data_test['labels'] # Reshape the data arrays to match the Legacy TU Dataset format X_train = X_train.reshape(-1, 22, 1000).transpose(0, 2, 1) y_train = y_train.reshape(-1) X_test = X_test.reshape(-1, 22, 1000).transpose(0, 2, 1) y_test = y_test.reshape(-1) # Create MNE Raw objects for both the training and testing data ch_names = ['Fz', 'FC3', 'FC1', 'FCz', 'FC2', 'FC4', 'C5', 'C3', 'C1', 'Cz', 'C2', 'C4', 'C6', 'CP3', 'CP1', 'CPz', 'CP2', 'CP4', 'P1', 'Pz', 'P2', 'POz'] sfreq = 250 info = mne.create_info(ch_names=ch_names, sfreq=sfreq, ch_types='eeg') raw_train = mne.io.RawArray(X_train, info) raw_test = mne.io.RawArray(X_test, info) # Add event markers for the labels in both the training and testing data events_train = np.vstack((np.arange(len(y_train)), np.zeros(len(y_train)), y_train)).T events_test = np.vstack((np.arange(len(y_test)), np.zeros(len(y_test)), y_test)).T raw_train.add_events(events_train, stim_channel='STI 014') raw_test.add_events(events_test, stim_channel='STI 014') # Save the MNE Raw objects as .fif files mne.io.write_raw_fif(raw_train, 'A01T_raw.fif', overwrite=True) mne.io.write_raw_fif(raw_test, 'A01E_raw.fif', overwrite=True) ``` 这段代码假设您已经将BCI Competition IV 2a数据集下载到当前工作目录中,并已将其命名为"A01T.npz"和"A01E.npz"。代码使用NumPy和MNE库来加载、处理和保存数据。它首先从.npz文件中提取数据和标签,并将其转换为符合Legacy TU Dataset格式的形式。然后,代码使用MNE库创建了两个Raw对象,一个用于训练数据,另一个用于测试数据。最后,代码将标签添加为事件标记,并将MNE Raw对象保存为.fif文件。
评论 27
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值