Giter Club home page Giter Club logo

eeyhsong / eeg-transformer Goto Github PK

View Code? Open in Web Editor NEW
243.0 3.0 26.0 86 KB

i. A practical application of Transformer (ViT) on 2-D physiological signal (EEG) classification tasks. Also could be tried with EMG, EOG, ECG, etc. ii. Including the attention of spatial dimension (channel attention) and *temporal dimension*. iii. Common spatial pattern (CSP), an efficient feature enhancement method, realized with Python.

License: GNU General Public License v3.0

Python 88.41% MATLAB 11.59%
deep-learning attention-mechanism vit transformer attention common-spatial-pattern eeg eeg-classification physiological-signals

eeg-transformer's Introduction

The v1.0 has been discontinued, please refer to v2.0 - EEG Conformer.

   

EEG Transformer 2.0 will coming soon with extremely good performance!

Your next backbone for EEG decoding.

p.s. released before Nov. 2022 I guess.

EEG-Transformer

Transformer based Spatial-Temporal Feature Learning for EEG Decoding

arxiv.org/abs/2106.11170

At present, people usually use some methods based on convolutional neural networks (CNNs) for Electroencephalograph (EEG) decoding. However, CNNs have limitations in perceiving global dependencies, which is not adequate for common EEG paradigms with a strong overall relationship. Regarding this issue, we propose a novel EEG decoding method that mainly relies on the attention mechanism. The EEG data is firstly preprocessed and spatially filtered. And then, we apply attention transforming on the feature-channel dimension so that the model can enhance more relevant spatial features. The most crucial step is to slice the data in the time dimension for attention transforming, and finally obtain a highly distinguishable representation. At this time, global averaging pooling and a simple fully-connected layer are used to classify different categories of EEG data. Experiments on two public datasets indicate that the strategy of attention transforming effectively utilizes spatial and temporal features. And we have reached the level of the state-of-the-art in multi-classification of EEG, with fewer parameters. As far as we know, it is the first time that a detailed and complete method based on the transformer idea has been proposed in this field. It has good potential to promote the practicality of brain-computer interface (BCI).

Fig1

Hope this code can be useful. I would be very appreciate if you cite us in your paper. 😉

eeg-transformer's People

Contributors

eeyhsong avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

eeg-transformer's Issues

代码运行后accuracy不能达到论文所诉82%

作者您好,非常感谢您发表的这篇论文,在拜读了您的文章后对我产生了非常大的启发。
但是我在复现您的文章时,始终不能达到论文所诉的2a数据集上的82%的accuracy,我这边感觉可能是调参的问题,希望能得到您技术上的帮助。非常感谢!

How to apply it to a 2-class task?

It's an excellent work that inspired me a lot. Now I am appling it to a 2-class task for DatasetIV-2b. Which parameter should I change?
I've found some potential code, Could you help to locate the para that needs modifing? Thank you!
In Trans.py:
Line 130: forward_expansion=4
Line 167: emb_size=10, depth=3, n_classes=4
LIne 253: self.c_dim=4
In common_spatial_pattern.py:
Line 15: idx_3=... (comment this line?)
Line 18: in range(4) and following elif for n_class==3
Line 70: Wb = np.concatenate((W[0][:, 0:4], W[1][:, 0:4], W[2][:, 0:4], W[3][:, 0:4]), axis=1)
Thanks again.

Dataset 2a accuracy surprisingly lower than the studies results

Hello
After running the transformer a couple of times, I'm receiving significantly smaller results compared to the study's results. I've attached an image of one of my confusion matrices which in comparison with the study, is much worse.
image
The only code I've edited was for the purpose of using it in google collaborate, otherwise, all the code is the same as how it was here on GitHub. What would be the cause of this and am I missing something quite obvious that is missing?
Best
Merlin

Pretrained weights

Would it be possible to share the pre-trained weights of the transformer, I would like to transfer learn the transformer to a BCI task

Dataset labelling issue

Hello
I have been trying to get your getData.m function working but I have run into an issue with labelling the evaluation datasets. Each time I run the code, the labels for all of the subject's evaluation data are labelled as NaN, preventing the Trans.py code to have a test accuracy score other than 0.

I looked at the BCI competition IV website and subject 1 from dataset 2a should have class labels but when I run
[s, HDR] = sload('dir of A01E');
The HDR.ClassLabels are all NaN so am unsure where I am going wrong.
Any help would be appreciated.
Best
Merlin

关于数据划分的一个疑问

代码中是将所有576个trial合起来然后选516个用于训练。
如果改为按照A01_T用于训练,A01E用于测试这样的数据划分的话,即288个trial用于训练,288个trial用于测试,模型的结果看上去不是很理想。
请问大佬针对这种情况有什么可以优化的手段吗

Is the low accuracy problem related to my data preprocessing

Dear author,
hello, your work is very helpful to us, I had a problem when reproducing the model, my data preprocessing used the getdata file of this project to obtain data, but I did not do filtering processing, and the problem of model accuracy skewness occurred. Is this related to my data preprocessing.

About dataset

Hi there,
I'm trying to implement your code on the BCI IV 2a dataset. However, I'm wondering how is the structure of the label and data in your mat file since I couldn't rebuild the mat file based on the "getData.m" function. If you can provide a tree structure of the data regarding trials and labels, it will be clearer.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.