提前停止使用tf.estimator,怎么办?
我tf.estimator
在TensorFlow
1.4中使用过,tf.estimator.train_and_evaluate
虽然很好,但我需要尽早停止。首选的添加方式是什么?
我认为这有些tf.train.SessionRunHook
地方。我看到有一个旧的contrib程序包,ValidationMonitor
它似乎已经提前停止,但在1.4中似乎不再存在。还是将来首选的方法是依靠tf.keras
(真的很容易尽早停止)而不是依靠tf.estimator/tf.layers/tf.data
?
-
好消息!
tf.estimator
现在已经在master上提供了早期停止支持,并且看起来将在1.10中。estimator = tf.estimator.Estimator(model_fn, model_dir) os.makedirs(estimator.eval_dir()) # TODO This should not be expected IMO. early_stopping = tf.contrib.estimator.stop_if_no_decrease_hook( estimator, metric_name='loss', max_steps_without_decrease=1000, min_steps=100) tf.estimator.train_and_evaluate( estimator, train_spec=tf.estimator.TrainSpec(train_input_fn, hooks=[early_stopping]), eval_spec=tf.estimator.EvalSpec(eval_input_fn))