neuralmonkey.tf_manager module

TensorFlow Manager.

TensorFlow manager is a helper object in Neural Monkey which manages TensorFlow sessions, execution of the computation graph, and saving and restoring of model variables.

class neuralmonkey.tf_manager.TensorFlowManager(num_sessions: int, num_threads: int, save_n_best: int = 1, minimize_metric: bool = False, variable_files: Union[List[str], NoneType] = None, gpu_allow_growth: bool = True, per_process_gpu_memory_fraction: float = 1.0, enable_tf_debug: bool = False) → None

Bases: object

Inteface between computational graph, data and TF sessions.

sessions

List of active Tensorflow sessions.

__init__(num_sessions: int, num_threads: int, save_n_best: int = 1, minimize_metric: bool = False, variable_files: Union[List[str], NoneType] = None, gpu_allow_growth: bool = True, per_process_gpu_memory_fraction: float = 1.0, enable_tf_debug: bool = False) → None

Initialize a TensorflowManager.

At this moment the graph must already exist. This method initializes required number of TensorFlow sessions and initializes them with provided variable files if they are provided.

Parameters:
  • num_sessions – Number of sessions to be initialized.
  • num_threads – Number of threads sessions will run in.
  • save_n_best – How many best models to keep
  • minimize_metric – Whether the best model is the one with the lowest or the highest score
  • variable_files – List of variable files.
  • gpu_allow_growth – TF to allocate incrementally, not all at once.
  • per_process_gpu_memory_fraction – Limit TF memory use.
best_vars_file
execute(dataset: neuralmonkey.dataset.dataset.Dataset, execution_scripts, train=False, compute_losses=True, summaries=True, batch_size=None, log_progress: int = 0) → List[neuralmonkey.runners.base_runner.ExecutionResult]
init_saving(vars_prefix: str) → None
initialize_model_parts(runners, save=False) → None

Initialize model parts variables from their checkpoints.

restore(variable_files: Union[str, List[str]]) → None
restore_best_vars() → None
save(variable_files: Union[str, List[str]]) → None
validation_hook(score: float, epoch: int, batch: int) → None
neuralmonkey.tf_manager.get_default_tf_manager()