Given graph, a directory to write outputs to (output_dir), and some ops,
run a training loop. The given train_op performs one step of training on the
model. The loss_op represents the objective function of the training. It is
expected to increment the global_step_tensor, a scalar integer tensor
counting training steps. This function uses Supervisor to initialize the
graph (from a checkpoint if one is available in output_dir), write summaries
defined in the graph, and write regular checkpoints as defined by
Training continues until global_step_tensor evaluates to max_steps, or, if
fail_on_nan_loss, until loss_op evaluates to NaN. In that case the
program is terminated with exit code 1.
A graph to train. It is expected that this graph is not in use
A directory to write outputs to.
An op that performs one training step when run.
A scalar loss tensor.
A tensor representing the global step. If none is given,
one is extracted from the graph using the same logic as in Supervisor.
An op that initializes the graph. If None, use Supervisor's
A dictionary that maps Tensor objects to feed values.
This feed dictionary will be used when init_op is evaluated.
Optional callable passed to Supervisor to initialize the model.
Output logs regularly. The logs contain timing data and the
Whether the current process is the chief supervisor in
charge of restoring the model and running standard services.
The master string to use when preparing the session.
Save a checkpoint every
supervisor_save_model_secs seconds when training.
The maximum number of recent checkpoint files to
keep. As new files are created, older files are deleted. If None or 0,
all checkpoint files are kept. This is simply passed as the max_to_keep
arg to tf.compat.v1.train.Saver constructor.
Save summaries every
supervisor_save_summaries_steps seconds when training.
A function that is called every iteration to produce a feed_dict
passed to session.run calls. Optional.
Trains for this many steps (e.g. current global step + steps).
If true, raise NanLossDuringTrainingError if loss_op
evaluates to NaN. If false, continue training as if nothing happened.
List of BaseMonitor subclass instances. Used for callbacks
inside the training loop.
Number of total steps for which to train model. If None,
train forever. Two calls fit(steps=100) means 200 training iterations.
On the other hand two calls of fit(max_steps=100) means, second call
will not do any iteration since first call did all 100 steps.