estimator=...# Hook to stop training if loss becomes lower than 100.hook=early_stopping.stop_if_lower_hook(estimator,"loss",100)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.
If set, directory containing summary files with eval metrics. By
default, estimator.eval_dir() will be used.
min_steps
int, stop is never requested if global step is less than this
value. Defaults to 0.
run_every_secs
If specified, calls should_stop_fn at an interval of
run_every_secs seconds. Defaults to 60 seconds. Either this or
run_every_steps must be set.
run_every_steps
If specified, calls should_stop_fn every
run_every_steps steps. Either this or run_every_secs must be set.
Returns
An early-stopping hook of type SessionRunHook that periodically checks
if the given metric is lower than specified threshold and initiates
early stopping if true.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2023-10-06 UTC."],[],[],null,["# tf.estimator.experimental.stop_if_lower_hook\n\n\u003cbr /\u003e\n\n|------------------------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/estimator/tree/master/tensorflow_estimator/python/estimator/early_stopping.py#L155-L209) |\n\nCreates hook to stop if the given metric is lower than the threshold. (deprecated)\n\n#### View aliases\n\n\n**Compat aliases for migration**\n\nSee\n[Migration guide](https://www.tensorflow.org/guide/migrate) for\nmore details.\n\n\\`tf.compat.v1.estimator.experimental.stop_if_lower_hook\\`\n\n\u003cbr /\u003e\n\n tf.estimator.experimental.stop_if_lower_hook(\n estimator,\n metric_name,\n threshold,\n eval_dir=None,\n min_steps=0,\n run_every_secs=60,\n run_every_steps=None\n )\n\n| **Deprecated:** THIS FUNCTION IS DEPRECATED. It will be removed in a future version. Instructions for updating: Use tf.keras instead.\n\n#### Usage example:\n\n estimator = ...\n # Hook to stop training if loss becomes lower than 100.\n hook = early_stopping.stop_if_lower_hook(estimator, \"loss\", 100)\n train_spec = tf.estimator.TrainSpec(..., hooks=[hook])\n tf.estimator.train_and_evaluate(estimator, train_spec, ...)\n\nCaveat: Current implementation supports early-stopping both training and\nevaluation in local mode. In distributed mode, training can be stopped but\nevaluation (where it's a separate job) will indefinitely wait for new model\ncheckpoints to evaluate, so you will need other means to detect and stop it.\nEarly-stopping evaluation in distributed mode requires changes in\n`train_and_evaluate` API and will be addressed in a future revision.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|-------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `estimator` | A [`tf.estimator.Estimator`](../../../tf/estimator/Estimator) instance. |\n| `metric_name` | `str`, metric to track. \"loss\", \"accuracy\", etc. |\n| `threshold` | Numeric threshold for the given metric. |\n| `eval_dir` | If set, directory containing summary files with eval metrics. By default, `estimator.eval_dir()` will be used. |\n| `min_steps` | `int`, stop is never requested if global step is less than this value. Defaults to 0. |\n| `run_every_secs` | If specified, calls `should_stop_fn` at an interval of `run_every_secs` seconds. Defaults to 60 seconds. Either this or `run_every_steps` must be set. |\n| `run_every_steps` | If specified, calls `should_stop_fn` every `run_every_steps` steps. Either this or `run_every_secs` must be set. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| An early-stopping hook of type `SessionRunHook` that periodically checks if the given metric is lower than specified threshold and initiates early stopping if true. ||\n\n\u003cbr /\u003e"]]