提前停止使用tf.estimator,怎么办? [英] Early stopping with tf.estimator, how?

查看:504
本文介绍了提前停止使用tf.estimator,怎么办?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在TensorFlow 1.4中使用了tf.estimatortf.estimator.train_and_evaluate很棒,但是我需要尽早停止.首选的添加方式是什么?

I'm using tf.estimator in TensorFlow 1.4 and tf.estimator.train_and_evaluate is great but I need early stopping. What's the prefered way of adding that?

我认为这是某个地方的tf.train.SessionRunHook.我看到有一个带有ValidationMonitor的旧的contrib程序包,它似乎早已停止,但在1.4中似乎不再存在.还是将来首选的方法是依靠tf.keras(使用它确实很容易尽早停止)而不是tf.estimator/tf.layers/tf.data?

I assume there is some tf.train.SessionRunHook somewhere for this. I saw that there was an old contrib package with a ValidationMonitor that seemed to have early stopping, but it doesn't seem to be around anymore in 1.4. Or will the preferred way in the future be to rely on tf.keras (with which early stopping is really easy) instead of tf.estimator/tf.layers/tf.data, perhaps?

推荐答案

好消息! tf.estimator现在具有对master的早期停止支持,并且看起来将在1.10中.

Good news! tf.estimator now has early stopping support on master and it looks like it will be in 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))

这篇关于提前停止使用tf.estimator,怎么办?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆