def fit(self, model: keras.models.Model, X, y): tensor_board = keras.callbacks.TensorBoard( log_dir=self.context.tensor_board_dir, histogram_freq=1) early_stopping = keras.callbacks.EarlyStopping(monitor='val_loss', mode='auto', patience=20) model.fit(X, y, batch_size=self.context.batch_size, epochs=self.context.epochs, validation_split=self.context.validation_split, callbacks=[tensor_board, early_stopping]) return model
def train(self, full_model: keras.models.Model, input_data, epochs=100, validation_data=None, validation_split=None, batch_size=32, **kwargs): """Train the given autoencoder model with the builder's configuration.""" given_input_shape = input_data.shape[1:] if given_input_shape != self.__input_shape: raise ValueError( f"Input shape {given_input_shape} does not match {self.__input_shape}" ) callbacks = [] if self.__early_stopping is not None and ( validation_data is not None or validation_split is not None): callbacks.append( keras.callbacks.EarlyStopping(patience=self.__early_stopping)) return full_model.fit(input_data, input_data, epochs=epochs, batch_size=batch_size, callbacks=callbacks, validation_data=validation_data, validation_split=validation_split, shuffle=True, **kwargs)