Commit 1adf2398 authored by okiss's avatar okiss
Browse files

Update deepEye3.py

parent 276ea993
......@@ -9,6 +9,8 @@ from keras.callbacks import CSVLogger
def run(trainX, trainY):
logging.info("Starting DeepEye3.")
if config['split']:
config['model'] = config['model'] + '_cluster'
classifier = Classifier_DEEPEYE3(input_shape=config['deepeye3']['input_shape'])
hist = classifier.fit(trainX, trainY)
plot_loss(hist, config['model_dir'], config['model'], True)
......@@ -32,10 +34,37 @@ class Classifier_DEEPEYE3:
self.verbose = verbose
if build:
self.model = self._build_model(input_shape)
if config['split']:
self.model = self.split_model(input_shape)
else:
self.model = self._build_model(input_shape)
if self.verbose:
self.model.summary()
def split_model(self, input_shape):
input_layer = tf.keras.layers.Input(input_shape)
output = []
# run inception over the cluster
for c in config['cluster'].keys():
a = [input_shape[0]]
a.append(len(config['cluster'][c]))
input_shape = tuple(a)
output.append(self._build_model(input_shape,
X=tf.transpose(tf.nn.embedding_lookup(tf.transpose(input_layer),
config['cluster'][c]))))
# append the results and perform 1 dense layer with last_channel dimension and the output layer
x = tf.keras.layers.Concatenate()(output)
dense = tf.keras.layers.Dense(32, activation='relu')(x)
output_layer = tf.keras.layers.Dense(1, activation='sigmoid')(dense)
model = tf.keras.models.Model(inputs=input_layer, outputs=output_layer)
model.compile(loss='binary_crossentropy', optimizer=keras.optimizers.Adam(), metrics=['accuracy'])
return model
def _inception_module(self, input_tensor, nb_filters=32, use_bottleneck=True, kernel_size=40, bottleneck_size=32,
stride=1, activation='linear'):
......@@ -76,8 +105,12 @@ class Classifier_DEEPEYE3:
x = keras.layers.Activation('relu')(x)
return x
def _build_model(self, input_shape, use_residual=True, depth=9):
input_layer = tf.keras.layers.Input(input_shape)
def _build_model(self, input_shape, X=[], use_residual=True, depth=9):
if config['split']:
input_layer = X
else:
input_layer = tf.keras.layers.Input(input_shape)
x = input_layer
input_res = input_layer
......@@ -90,6 +123,8 @@ class Classifier_DEEPEYE3:
input_res = x
gap_layer = tf.keras.layers.GlobalAveragePooling1D()(x)
if config['split']:
return gap_layer
output_layer = tf.keras.layers.Dense(1, activation='sigmoid')(gap_layer)
model = tf.keras.models.Model(inputs=input_layer, outputs=output_layer)
model.compile(loss='binary_crossentropy', optimizer=keras.optimizers.Adam(), metrics=['accuracy'])
......
Supports Markdown
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