創建 early-stopping 掛鉤。
用法
tf.estimator.experimental.make_early_stopping_hook(
estimator, should_stop_fn, run_every_secs=60, run_every_steps=None
)參數
-
estimatortf.estimator.Estimator實例。 -
should_stop_fncallable,不帶參數並返回bool的函數。如果函數返回True,停止將由酋長發起。 -
run_every_secs如果指定,則以run_every_secs秒的間隔調用should_stop_fn。默認為 60 秒。必須設置這個或run_every_steps。 -
run_every_steps如果指定,則每run_every_steps步驟調用should_stop_fn。必須設置這個或run_every_secs。
返回
-
SessionRunHook定期執行should_stop_fn並在函數返回True時啟動提前停止。
拋出
-
TypeError如果estimator不是tf.estimator.Estimator類型。 -
ValueError如果同時設置了run_every_secs和run_every_steps。
返回當 should_stop_fn 返回 True 時停止訓練的 SessionRunHook。
使用示例:
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, ...)
警告:當前實現支持 early-stopping 在本地模式下進行訓練和評估。在分布式模式下,可以停止訓練,但評估(這是一項單獨的工作)將無限期地等待新模型檢查點的評估,因此您將需要其他方法來檢測和停止它。分布式模式下的Early-stopping 評估需要更改train_and_evaluate API,並將在未來的修訂版中解決。
相關用法
- Python tf.estimator.experimental.stop_if_lower_hook用法及代碼示例
- Python tf.estimator.experimental.stop_if_no_increase_hook用法及代碼示例
- Python tf.estimator.experimental.LinearSDCA用法及代碼示例
- Python tf.estimator.experimental.RNNClassifier用法及代碼示例
- Python tf.estimator.experimental.stop_if_higher_hook用法及代碼示例
- Python tf.estimator.experimental.InMemoryEvaluatorHook用法及代碼示例
- Python tf.estimator.experimental.RNNEstimator用法及代碼示例
- Python tf.estimator.experimental.stop_if_no_decrease_hook用法及代碼示例
- Python tf.estimator.TrainSpec用法及代碼示例
- Python tf.estimator.LogisticRegressionHead用法及代碼示例
- Python tf.estimator.MultiHead用法及代碼示例
- Python tf.estimator.PoissonRegressionHead用法及代碼示例
- Python tf.estimator.WarmStartSettings用法及代碼示例
- Python tf.estimator.RunConfig用法及代碼示例
- Python tf.estimator.MultiLabelHead用法及代碼示例
- Python tf.estimator.BaselineEstimator用法及代碼示例
- Python tf.estimator.DNNLinearCombinedEstimator用法及代碼示例
- Python tf.estimator.Estimator用法及代碼示例
- Python tf.estimator.LinearRegressor用法及代碼示例
- Python tf.estimator.LinearEstimator用法及代碼示例
注:本文由純淨天空篩選整理自tensorflow.org大神的英文原創作品 tf.estimator.experimental.make_early_stopping_hook。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
