用tf.estimator提早停止,怎么样?

Car*_*omé 20 python neural-network keras tensorflow tensorflow-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,或许?

Car*_*omé 26

好消息!tf.estimator现在已经提前停止对主人的支持,看起来它将在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))
Run Code Online (Sandbox Code Playgroud)

  • 我也有类似的问题,找不到“ signal_early_stopping”。似乎是因为`early_stopping`挂钩只能放在TrainSpec挂钩中。为在EvalSpec挂钩中使用,将发生此错误。 (2认同)