Link Search Menu Expand Document

min2net.model.MIN2Net_without_triplet

View source on GitHub

Table of contents

  1. min2net.model.MIN2Net_without_triplet
    1. MIN2Net_without_triplet class
    2. Build method
    3. Fit method
    4. Predict method
    5. Example

MIN2Net_without_triplet class

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

min2net.model.MIN2Net_without_triplet()

Arguments:

ArgumentsDescriptionDefault
input_shapetuple of integers.
(1, #time_point, #channel)
(1,400,20)
num_classint number of class.2
losslist of str (name of objective function), objective function or tf.keras.losses.Loss instance.[mean_squared_error,
'sparse_categorical_crossentropy']
loss_weightslist of float [β1,β2] to weight the loss contributions of different model outputs.[1., 1.]
latent_dimint or None. If None, latent_dim is equal to number of channels C or 64 for 2- or 3-class classification, respectively.None
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-2
min_lrfloat lower bound on the learning rate. See tf.keras.callbacks.ReduceLROnPlateau.1e-3
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.20
es_patienceint number of epochs with no improvement after which training will be stopped. See tf.keras.callbacks.EarlyStopping.50
verbose0 or 1. Verbosity mode. 0 = silent, 1 = progress bar.1
log_pathstr path to save model‘logs’
model_namestr prefix to save model‘MIN2Net_without_triplet’
**kwargsKeyword argument to pass into the function for replacing the variables of the model such as 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.

MIN2Net_without_triplet.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'.

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

Arguments:

ArgumentsDescription
X_trainndarray Training EEG signals. shape (#trial, #depth, #time_point, #channel)
y_trainndarray Label of training set. shape (#trial)
X_valndarray Validation EEG signals. shape (#trial, #depth, #time_point, #channel)
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 method was implemented based on tf.keras.Model.predict() and tf.keras.Model.evaluate().

MIN2Net_without_triplet.predict(X_test, 
                                y_test)
ArgumentsDescription
X_testndarray Testing EEG signals. shape (#trial, #depth, #time_point, #channel)
y_testndarray Label of test set. shape (#trial)

Returns:

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

Example

from min2net.model import MIN2Net_without_triplet
import numpy as np

model = MIN2Net_without_triplet(input_shape=(1, 400, 20), num_class=2, monitor='val_loss', shuffle=True)
model.fit(X_train, y_train, X_val, y_val)

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