Link Search Menu Expand Document

min2net.model.SpectralSpatialCNN

View source on GitHub

Table of contents

  1. min2net.model.SpectralSpatialCNN
    1. About SpectralSpatialCNN
    2. SpectralSpatialCNN class
    3. Build method
    4. Fit method
    5. Predict method
    6. Example

About SpectralSpatialCNN

If you use the SpectralSpatialCNN model in your research, please cite the following paper:

@ARTICLE{8897723,
  author={Kwon, O-Yeon and Lee, Min-Ho and Guan, Cuntai and Lee, Seong-Whan},
  journal={IEEE Transactions on Neural Networks and Learning Systems}, 
  title={Subject-Independent Brain–Computer Interfaces Based on Deep Convolutional Neural Networks}, 
  year={2020},
  volume={31},
  number={10},
  pages={3839-3852},
  doi={10.1109/TNNLS.2019.2946869}}

SpectralSpatialCNN class

Configures the model for training. Based on tf.keras.Model.

min2net.model.SpectralSpatialCNN()

Arguments:

ArgumentsDescriptionDefault
input_shapetuple of integers.
(#height, #width, #depth)
(28,28,1)
num_classint number of class.2
lossstr (name of objective function), objective function or tf.keras.losses.Loss instance.'sparse_categorical_crossentropy'
epochsint number of epochs to train the model.200
batch_sizeint or None. Number of samples per gradient update.100
optimizerstr (name of optimizer) or optimizer instance. See tf.keras.optimizers.Adam(beta_1=0.9, beta_2=0.999, epsilon=1e-08)
lrfloat the start learning rate1e-5
min_lrfloat lower bound on the learning rate. See tf.keras.callbacks.ReduceLROnPlateau.1e-6
factorfloat factor by which the learning rate will be reduced. See tf.keras.callbacks.ReduceLROnPlateau.0.25
patienceint number of epochs with no improvement after which learning rate will be reduced. See tf.keras.callbacks.ReduceLROnPlateau.10
es_patienceint number of epochs with no improvement after which training will be stopped. See tf.keras.callbacks.EarlyStopping.20
verbose0 or 1. Verbosity mode. 0 = silent, 1 = progress bar.1
log_pathstr path to save model‘logs’
model_namestr prefix to save model‘SpectralSpatialCNN’
**kwargsKeyword argument to pass into the function for replacing the variables of the model such as n_subbands, dropout_rate, f1_average, data_format, shuffle, metrics, monitor, mode, save_best_only, save_weight_only, seed, and class_balancing-

Build method

Build the model that group layers into an object with training and inference features.

SpectralSpatialCNN.build()

Returns: Model (tf.keras.Model): Model object


Fit method

Fit the model according to the given training and validation data. This method was implemented based on tf.keras.Model.fit(). The model weights and logs will save at 'log_path'.

SpectralSpatialCNN.fit(X_train, 
                       y_train, 
                       X_val, 
                       y_val)

Arguments:

ArgumentsDescription
X_trainndarray Training EEG signals. shape (#trial, #n_subbands, #height, #width, #depth)
y_trainndarray Label of training set. shape (#trial)
X_valndarray Validation EEG signals. shape (#trial, #n_subbands, #height, #width, #depth)
y_valndarray Label of validation set. shape (#trial)

Predict method

Generates output predictions & the loss value & metrics values for the model in test mode for the input samples. This medthod was implemented based on tf.keras.Model.predict() and tf.keras.Model.evaluate().

SpectralSpatialCNN.predict(X_test, 
               y_test)
ArgumentsDescription
X_testndarray Testing EEG signals. shape (#trial, #n_subbands, #height, #width, #depth)
y_testndarray Label of test set. shape (#trial)

Returns:

  • Y: dictionary of {y_true, y_pred}
  • evaluation: dictionary of {loss, accuracy, f1_score}

Example

from min2net.model import SpectralSpatialCNN
import numpy as np

model = SpectralSpatialCNN(input_shape=(28, 28, 1), num_class=2, dropout_rate=0.25, shuffle=True)
model.fit(X_train, y_train, X_val, y_val)

Y, evaluation = model.predict(X_test, y_test)