def _train_top_model(self):
    ' Train Top Model\n\n        Train fully connected top model of the network.\n\n        '
    self._load_features()
    model = self._build_top_model(input_shape=self._features['train']['bottleneck'].shape[1:])
    model.compile(optimizer=self.getkwarg('top_opt', 'adam'), loss=self.getkwarg('top_loss', 'binary_crossentropy'), metrics=self.getkwarg('top_metrics', ['accuracy']))
    top_model_file = '{}.h5'.format(self._top_model_file)
    callbacks = []
    callbacks.append(ModelCheckpoint(top_model_file, monitor='val_loss', verbose=self._verbose, save_best_only=True, save_weights_only=True, mode='auto', period=1))
    if self.getkwarg('top_early_stop', True):
        min_delta = self.getkwarg('top_min_delta', 0.001)
        patience = self.getkwarg('top_patience', 10)
        callbacks.append(EarlyStopping(monitor='val_loss', min_delta=min_delta, patience=patience, verbose=self._verbose))
    callbacks.append(ReduceLROnPlateau(monitor='val_loss', factor=0.5, patience=5, min_delta=0.001, cooldown=2, verbose=self._verbose))
    self.history = model.fit(self._features['train']['bottleneck'], self._features['train']['labels'], epochs=self._epochs_top, batch_size=self._batch_size_top, callbacks=callbacks, validation_data=(self._features['valid']['bottleneck'], self._features['valid']['labels']), verbose=self._verbose)
    model.save_weights(top_model_file)
Train Top Model

Train fully connected top model of the network.
def _train_top_model(self):
    ' Train Top Model\n\n        Train fully connected top model of the network.\n\n        '
    self._load_features()
    model = self._build_top_model(input_shape=self._features['train']['bottleneck'].shape[1:])
    model.compile(optimizer=self.getkwarg('top_opt', 'adam'), loss=self.getkwarg('top_loss', 'binary_crossentropy'), metrics=self.getkwarg('top_metrics', ['accuracy']))
    top_model_file = '{}.h5'.format(self._top_model_file)
    callbacks = []
    callbacks.append(ModelCheckpoint(top_model_file, monitor='val_loss', verbose=self._verbose, save_best_only=True, save_weights_only=True, mode='auto', period=1))
    if self.getkwarg('top_early_stop', True):
        min_delta = self.getkwarg('top_min_delta', 0.001)
        patience = self.getkwarg('top_patience', 10)
        callbacks.append(EarlyStopping(monitor='val_loss', min_delta=min_delta, patience=patience, verbose=self._verbose))
    callbacks.append(ReduceLROnPlateau(monitor='val_loss', factor=0.5, patience=5, min_delta=0.001, cooldown=2, verbose=self._verbose))
    self.history = model.fit(self._features['train']['bottleneck'], self._features['train']['labels'], epochs=self._epochs_top, batch_size=self._batch_size_top, callbacks=callbacks, validation_data=(self._features['valid']['bottleneck'], self._features['valid']['labels']), verbose=self._verbose)
    model.save_weights(top_model_file)