[英]TensorFlow custom estimator stuck when calling evaluate after training
I made a custom estimator (see this colab ) in TensorFlow (v1.10) based on their guide . 我根据他们的指南在TensorFlow(v1.10)中制作了一个自定义估算器(参见本合作 )。
I trained the toy model with: 我训练玩具模型:
tf.estimator.train_and_evaluate(est, train_spec, eval_spec)
and then, with some test set data, try to evaluate the model with: 然后,使用一些测试集数据,尝试使用以下方法评估模型:
test_fn = lambda: input_fn(DATASET['test'], run_params)
test_res = est.evaluate(input_fn=test_fn)
(where the train_fn
and valid_fn
are functionally identical to test_fn
, eg sufficient for tf.estimator.train_and_evaluate
to work). (其中
train_fn
和valid_fn
在功能上与test_fn
相同,例如足以使tf.estimator.train_and_evaluate
工作)。
I would expect something to happen, however this is what I get: 我希望会发生一些事情,但这是我得到的:
INFO:tensorflow:Calling model_fn.
INFO:tensorflow:Done calling model_fn.
INFO:tensorflow:Starting evaluation at 2018-11-09-13:38:44
INFO:tensorflow:Graph was finalized.
INFO:tensorflow:Restoring parameters from ./test/model.ckpt-100
INFO:tensorflow:Running local_init_op.
INFO:tensorflow:Done running local_init_op.
and then it just runs forever. 然后它就会永远运行。
How come? 怎么会?
This is because you repeat the dataset indefinitely: 这是因为您无限期地重复数据集:
# In input_fn
dataset = dataset.repeat().batch(batch_size)
By default, estimator.evaluate() runs until the input_fn raises an end-of-input exception. 默认情况下,estimator.evaluate()会一直运行,直到input_fn引发输入结束异常。 Because you repeat the test dataset indefinitely, it never raises the exception and keeps running.
因为您无限期地重复测试数据集,所以它永远不会引发异常并继续运行。
You can either remove the repeat when testing, or run the evaluation for a given number of steps using the 'steps' argument as it is used in your original 'eval_spec'. 您可以在测试时删除重复,也可以使用原始'eval_spec'中使用的'steps'参数运行给定步数的评估。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.