Giter Club home page Giter Club logo

min2net's Introduction

End-to-End Multi-Task Learning for Subject-Independent Motor Imagery EEG Classification

Open In Colab Pypi Downloads DOI

Python API and the novel algorithm for motor imagery EEG recognition named MIN2Net. The API benefits BCI researchers ranging from beginners to experts. We demonstrate the examples in using the API for loading benchmark datasets, preprocessing, training, and validation of SOTA models, including MIN2Net. In summary, the API allows the researchers to construct the pipeline for benchmarking the newly proposed models and very recently developed SOTA models.


Getting started

Dependencies

  • Python==3.6.9
  • tensorflow-gpu==2.2.0
  • tensorflow-addons==0.9.1
  • scikit-learn>=0.24.1
  • wget>=3.2
  1. Create conda environment with dependencies
wget https://raw.githubusercontent.com/IoBT-VISTEC/MIN2Net/main/environment.yml
conda env create -f environment.yml
conda activate min2net

Installation:

  1. Using pip
pip install min2net
  1. Using the released python wheel
wget https://github.com/IoBT-VISTEC/MIN2Net/releases/download/v1.0.1/min2net-1.0.1-py3-none-any.whl
pip install min2net-1.0.1-py3-none-any.whl

Tutorial

Open in Colab

Citation

To cited our paper

P. Autthasan et al., "MIN2Net: End-to-End Multi-Task Learning for Subject-Independent Motor Imagery EEG Classification," in IEEE Transactions on Biomedical Engineering, doi: 10.1109/TBME.2021.3137184.

@ARTICLE{9658165,
  author={Autthasan, Phairot and Chaisaen, Rattanaphon and Sudhawiyangkul, Thapanun and Rangpong, Phurin and Kiatthaveephong, Suktipol and Dilokthanakul, Nat and Bhakdisongkhram, Gun and Phan, Huy and Guan, Cuntai and Wilaiprasitporn, Theerawit},
  journal={IEEE Transactions on Biomedical Engineering}, 
  title={MIN2Net: End-to-End Multi-Task Learning for Subject-Independent Motor Imagery EEG Classification}, 
  year={2022},
  volume={69},
  number={6},
  pages={2105-2118},
  doi={10.1109/TBME.2021.3137184}}

License

Copyright © 2021-All rights reserved by INTERFACES (BRAIN lab @ IST, VISTEC, Thailand). Distributed by an Apache License 2.0.

min2net's People

Contributors

iobt-vistec 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

Watchers

 avatar  avatar  avatar  avatar  avatar

min2net's Issues

'macro' is suitable average metric for f1-score of binary MI classification.

Since binary f1-score consider precision and recall, it does not consider TN.
Let me consider right hand class as the positive and left hand class as the negative. For this case, binary f1-score ignores left hand class.
Conversely, when the positive and negative labels are changed, the f1-score is different.
Because the binary MI classification is not a positive-negative problem, we should treat both class equally.
Therefore I suggest use macro f1-score for the binary MI classification.

Opimizer issue (found loss = `NaN` in second fold)

Due to TensorFlow's compilation issues, the second loop attempts to use the first initialize object of the optimizer in the __init__ function as the loss return NaN value (Even if the new model object is declared within the loop, the first initialize optimizer is attempted)

To resolve this issue, do not utilize the optimizer's initial value as provided by the __init__ function; instead, the optimizer must be assigned in each and every fold as in the example below:

for fold in range(1, 6):
    # the optimizer must be assigned in each and every fold
    optimizer = Adam(beta_1=0.9, beta_2=0.999, epsilon=1e-08)
    model = MIN2Net(optimizer =optimizer)

However, this issue does not affect the experimental results of our paper since we declared a new optimizer in every loop https://github.com/IoBT-VISTEC/MIN2Net/blob/main/experiments/train_MIN2Net_k-fold-CV.py#L41

I would like to express the MIN2Net model in pytorch, is that correct?

Only the MI-EEG classification part was expressed in pytorch. Does it match?

class Conv2D_Norm_Constrained(nn.Conv2d):
    def __init__(self, max_norm_val, norm_dim, **kwargs):
        super().__init__(**kwargs)
        self.max_norm_val = max_norm_val
        self.norm_dim = norm_dim

    def get_constrained_weights(self, epsilon=1e-8):
        norm = self.weight.norm(2, dim=self.norm_dim, keepdim=True)
        return self.weight * (torch.clamp(norm, 0, self.max_norm_val) / (norm + epsilon))

    def forward(self, input):
        return F.conv2d(input, self.get_constrained_weights(), self.bias, self.stride, self.padding, self.dilation, self.groups)

class ConstrainedLinear(nn.Linear):
    def forward(self, input):
        return F.linear(input, self.weight.clamp(min=-1.0, max=0.5), self.bias)
class MinNet(nn.Module): # input = (1,16,125)
  def __init__(self, input_shape=(1,400,20)):
    super().__init__()
    self.D, self.T, self.C = input_shape
    self.subsampling_size = 100
    self.pool_size_1 = (1,self.T//self.subsampling_size)
    self.en_conv = nn.Sequential(
                    Conv2D_Norm_Constrained(in_channels=1, out_channels=16, kernel_size=(1, 64), padding="same", max_norm_val=2.0, norm_dim=(0, 1, 2)),
                    nn.ELU(),
                    nn.BatchNorm2d(16,eps=1e-05, momentum=0.1),
                    nn.AvgPool2d((1,self.pool_size_1)),
                    nn.Flatten(),
                    ConstrainedLinear(32000,64),
                    nn.ELU(),
                    ConstrainedLinear(64,3)
                )
  def forward(self,x):
      x = self.en_conv(x)
      return x

google colab confliting error tensorflow-addons==0.9.1

Google colab occurs error.
Collecting min2net
Using cached min2net-1.0.1-py3-none-any.whl (58 kB)
Using cached min2net-1.0.0-py3-none-any.whl (57 kB)
ERROR: Cannot install min2net==1.0.0 and min2net==1.0.1 because these package versions have conflicting dependencies.

The conflict is caused by:
min2net 1.0.1 depends on tensorflow-addons==0.9.1
min2net 1.0.0 depends on tensorflow-addons==0.9.1

To fix this you could try to:

  1. loosen the range of package versions you've specified
  2. remove package versions to allow pip attempt to solve the dependency conflict
    But google colab only use tensorflow-addons >= 0.10.0.
    How I do solve this?

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.