EarlyStopping

class tfsnippet.EarlyStopping(param_vars, initial_metric=None, checkpoint_dir=None, smaller_is_better=True, restore_on_error=False, cleanup=True, name=None)

Bases: tfsnippet.utils.concepts.DisposableContext

Early-stopping context object.

This class provides a object for memorizing the parameters for best metric, in an early-stopping context. An example of using this context:

with EarlyStopping(param_vars) as es:
    ...
    es.update(loss, global_step)
    ...

Where es.update(loss, global_step) should cause the parameters to be saved on disk if loss is better than the current best metric. One may also get the current best metric via es.best_metric.

Notes

If no loss is given via es.update, then the variables would keep their latest values when closing an early-stopping object.

Attributes Summary

best_metric Get the current best loss.
ever_updated Check whether or not update method has ever been called.

Methods Summary

update(metric[, global_step]) Update the best metric.

Attributes Documentation

best_metric

Get the current best loss.

ever_updated

Check whether or not update method has ever been called.

Methods Documentation

update(metric, global_step=None)

Update the best metric.

Parameters:
  • metric (float) – New metric value.
  • global_step (int) – Optional global step counter.
Returns:

Whether or not the best loss has been updated?

Return type:

bool