Creates early-stopping hook.

Returns a SessionRunHook that stops training when should_stop_fn returns True.

Usage example:

estimator = ...
hook = early_stopping.make_early_stopping_hook(
    estimator, should_stop_fn=make_stop_fn(...))
train_spec = tf.estimator.TrainSpec(..., hooks=[hook])
tf.estimator.train_and_evaluate(estimator, train_spec, ...)

Caveat: Current implementation supports early-stopping both training and evaluation in local mode. In distributed mode, training can be stopped but evaluation (where it's a separate job) will indefinitely wait for new model checkpoints to evaluate, so you will need other means to detect and stop it. Early-stopping evaluation in distributed mode requires changes in train_and_evaluate API and will be addressed in a future revision.

estimator A tf.estimator.Estimator instance.
should_stop_fn callable, function that takes no arguments and returns a bool. If the function returns True, stopping will be initiated by the chief.