我训练了一个模型,并像下面这样提前停止。训练过程停止后,分数可能会降低一点。但是BestExporter应该可以帮助我们保存最佳模型。那我该如何使用测试数据评估该模型呢?
exporter = tf.estimator.BestExporter(
name="best_exporter",
serving_input_receiver_fn=serving_input_fn,
exports_to_keep=5) # this will keep the 5 best checkpoints
os.makedirs(model.eval_dir())
early_stopping = tf.contrib.estimator.stop_if_no_increase_hook(model, metric_name='eval_auc', max_steps_without_increase=20000, run_every_secs=400)
train_spec = tf.estimator.TrainSpec(input_fn=make_input_fn('/hdfs/user/reco/sample_v1', 10), hooks=[early_stopping])
eval_spec = tf.estimator.EvalSpec(input_fn=make_evaluate_input_fn(), exporters=exporter, throttle_secs=120)
tf.estimator.train_and_evaluate(model, train_spec, eval_spec)