/EEG-ATCNet

Attention temporal convolutional network for EEG-based motor imagery classification

Primary LanguagePythonApache License 2.0Apache-2.0

EEG-ATCNet

PWC

This repository provides code for the Attention Temporal Convolutional Network (ATCNet) proposed in the paper: Physics-informed attention temporal convolutional network for EEG-based motor imagery classification

Authors: Hamdi Altaheri, Ghulam Muhammad, Mansour Alsulaiman

Center of Smart Robotics Research, King Saud University, Saudi Arabia

In addition to the proposed ATCNet model, the models.py file includes the implementation of other related methods, which can be compared with ATCNet, including:

This repository includes the implementation of the following attention schemes in the attention_models.py file:

These attention blocks can be called using the attention_block(net, attention_model) method in the attention_models.py file, where 'net' is the input layer and 'attention_model' indicates the type of the attention mechanism, which has five options: None, 'mha', 'mhla', 'cbam', and 'se'.

Example: 
    input = Input(shape = (10, 100, 1))   
    block1 = Conv2D(1, (1, 10))(input)
    block2 = attention_block(block1,  'mha') # mha: multi-head self-attention
    output = Dense(4, activation="softmax")(Flatten()(block2))

The preprocess.py file loads and divides the dataset based on two approaches:

  1. Subject-specific (subject-dependent) approach. In this approach, we used the same training and testing data as the original BCI-IV-2a competition division, i.e., trials in session 1 for training, and trials in session 2 for testing.
  2. Leave One Subject Out (LOSO) approach. LOSO is used for Subject-independent evaluation. In LOSO, the model is trained and evaluated by several folds, equal to the number of subjects, and for each fold, one subject is used for evaluation and the others for training. The LOSO evaluation technique ensures that separate subjects (not visible in the training data) are usedto evaluate the model.

The get_data() method in the preprocess.py file is used to load the dataset and split it into training and testing. This method uses the subject-specific approach by default. If you want to use the subject-independent (LOSO) approach, set the parameter LOSO = True.

About ATCNet

ATCNet model consists of three main blocks:

  1. Convolutional (CV) block: encodes low-level spatio-temporal information within the MI-EEG signal into a sequence of high-level temporal representations through three convolutional layers.
  2. Attention (AT) block: highlights the most important information in the temporal sequence using a multi-head self-attention (MSA).
  3. Temporal convolutional (TC) block: extracts high-level temporal features from the highlighted information using a temporal convolutional layer
  • ATCNet model also utilizes the convolutional-based sliding window to augment MI data and boost the performance of MI classification efficiently.

The components of the ATCNet model

The components of the proposed ATCNet model

Visualize the transition of data in the ATCNet model.

The components of the proposed ATCNet model

Development environment

Models were trained and tested by a single GPU, Nvidia GTX 2070 8GB (Driver Version: 512.78, CUDA 11.3), using Python 3.7 with TensorFlow framework. Anaconda 3 was used on Ubuntu 20.04.4 LTS and Windows 11. The following packages are required:

  • TensorFlow 2.7
  • matplotlib 3.5
  • NumPy 1.20
  • scikit-learn 1.0
  • SciPy 1.7

Dataset

The BCI Competition IV-2a dataset needs to be downloaded and the data path placed at 'data_path' variable in main.py file. The dataset can be downloaded from here.

References

If you find this work useful in your research, please use the following BibTeX entry for citation

@article{9852687,
  title={Physics-informed attention temporal convolutional network for EEG-based motor imagery classification}, 
  author={Altaheri, Hamdi and Muhammad, Ghulam and Alsulaiman, Mansour},
  journal={IEEE Transactions on Industrial Informatics}, 
  year={2022},
  doi={10.1109/TII.2022.3197419}
  }
  
@article{altaheri2021deep,
  title={Deep learning techniques for classification of electroencephalogram (EEG) motor imagery (MI) signals: a review},
  author={Altaheri, Hamdi and Muhammad, Ghulam and Alsulaiman, Mansour and Amin, Syed Umar and Altuwaijri, Ghadir Ali and Abdul, Wadood and Bencherif, Mohamed A and Faisal, Mohammed},
  journal={Neural Computing and Applications},
  pages={1--42},
  year={2021},
  publisher={Springer}
}