To receive notifications about scheduled maintenance, please subscribe to the mailing-list gitlab-operations@sympa.ethz.ch. You can subscribe to the mailing-list at https://sympa.ethz.ch

Commit dff2e182 authored by zpgeng's avatar zpgeng
Browse files

Corrected the deepEye.py

parent aae7af90
......@@ -45,16 +45,17 @@ class Classifier_DEEPEYE:
self.model.save_weights(self.output_directory + 'model_init.hdf5')
@staticmethod
def _eeg_preprocessing(input_tensor, F1=8, D=2, kernLength=125):
def _eeg_preprocessing(self, input_tensor, F1=8, D=2, kernLength=125):
"""
Static method since this function does not receive any reference argument from this class.
"""
# EEGNet feature extraction
Chans = input_tensor.shape[0]
Chans = input_tensor.shape[1]
Samples = input_tensor.shape[2]
# Filter slides horizontally
horizontal_tensor = Conv2D(F1, (1, kernLength), padding='same',
input_shape=input_tensor.shape,
input_shape=(Chans, Samples, 1),
use_bias=False)(input_tensor)
horizontal_tensor = BatchNormalization()(horizontal_tensor)
......@@ -65,20 +66,19 @@ class Classifier_DEEPEYE:
vertical_tensor = BatchNormalization()(vertical_tensor)
eeg_tensor = Activation('elu')(vertical_tensor)
# Reshape the tensor (128, 1, 500) to (128, 500), and feed into the inception module
output_tensor = tf.reshape(eeg_tensor, (D*F1, -1))
# Reshape the tensor (129, 500, 1) to (129, 500), and feed into the inception module
output_tensor = eeg_tensor[:, 0, :, :]
output_tensor = tf.transpose(output_tensor, perm=[0, 2, 1]) # For the input of Inception it should be
# transposed.
return output_tensor
def _inception_module(self, input_tensor, stride=1, F1=8, D=2, kernLength=125, activation='linear'):
eeg_tensor = self._eeg_preprocessing(input_tensor, F1, D, kernLength)
def _inception_module(self, input_tensor, stride=1, activation='linear'):
if self.use_bottleneck and int(eeg_tensor.shape[-1]) > 1:
if self.use_bottleneck and int(input_tensor.shape[-1]) > 1:
input_inception = keras.layers.Conv1D(filters=self.bottleneck_size, kernel_size=1,
padding='same', activation=activation, use_bias=False)(eeg_tensor)
padding='same', activation=activation, use_bias=False)(input_tensor)
else:
input_inception = eeg_tensor
input_inception = input_tensor
# kernel_size_s = [3, 5, 8, 11, 17]
kernel_size_s = [self.kernel_size // (2 ** i) for i in range(3)]
......@@ -90,7 +90,7 @@ class Classifier_DEEPEYE:
use_bias=False)(input_inception))
max_pool_1 = keras.layers.MaxPool1D(pool_size=3, strides=stride, padding='same')(
eeg_tensor) # I think it should be eeg_tensor here!
input_tensor) # I think it should be eeg_tensor here!
conv_6 = keras.layers.Conv1D(filters=self.nb_filters, kernel_size=1, padding='same', activation=activation,
use_bias=False)(max_pool_1)
......@@ -102,22 +102,21 @@ class Classifier_DEEPEYE:
x = keras.layers.Activation(activation='relu')(x)
return x
def _shortcut_layer(self, input_tensor, out_tensor, F1=8, D=2, kernLength=125):
eeg_tensor = self._eeg_preprocessing(input_tensor, F1, D, kernLength)
@staticmethod
def _shortcut_layer(self, input_tensor, out_tensor):
shortcut_y = keras.layers.Conv1D(filters=int(out_tensor.shape[-1]), kernel_size=1,
padding='same', use_bias=False)(
eeg_tensor) # I think it should be eeg_tensor here!
padding='same', use_bias=False)(input_tensor)
shortcut_y = keras.layers.normalization.BatchNormalization()(shortcut_y)
x = keras.layers.Add()([shortcut_y, out_tensor])
x = keras.layers.Activation('relu')(x)
return x
def build_model(self, input_shape, nb_classes):
input_layer = keras.layers.Input(input_shape)
x = input_layer
input_res = input_layer
def build_model(self, input_shape, nb_classes, F1=8, D=2, kernLength=125):
input_layer = keras.layers.Input((input_shape[0], input_shape[1], 1))
eeg_tensor = self._eeg_preprocessing(input_layer, F1, D, kernLength)
x = eeg_tensor
input_res = eeg_tensor
for d in range(self.depth):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment