[英]TensorFlow custom estimator stuck when calling evaluate after training
我根據他們的指南在TensorFlow(v1.10)中制作了一個自定義估算器(參見本合作 )。
我訓練玩具模型:
tf.estimator.train_and_evaluate(est, train_spec, eval_spec)
然后,使用一些測試集數據,嘗試使用以下方法評估模型:
test_fn = lambda: input_fn(DATASET['test'], run_params)
test_res = est.evaluate(input_fn=test_fn)
(其中train_fn
和valid_fn
在功能上與test_fn
相同,例如足以使tf.estimator.train_and_evaluate
工作)。
我希望會發生一些事情,但這是我得到的:
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.
然后它就會永遠運行。
怎么會?
這是因為您無限期地重復數據集:
# In input_fn
dataset = dataset.repeat().batch(batch_size)
默認情況下,estimator.evaluate()會一直運行,直到input_fn引發輸入結束異常。 因為您無限期地重復測試數據集,所以它永遠不會引發異常並繼續運行。
您可以在測試時刪除重復,也可以使用原始'eval_spec'中使用的'steps'參數運行給定步數的評估。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.