Is there some way to save best model only with tensorflow.estimator.train_and_evaluate()?

前端 未结 3 1724
耶瑟儿~
耶瑟儿~ 2021-02-09 10:46

I try retrain TF Object Detection API model from checkpoint with already .config file for training pipeline with tf.estimator.train_and_evaluate() method like in models/research

3条回答
  •  星月不相逢
    2021-02-09 11:14

    I have been using https://github.com/bluecamel/best_checkpoint_copier which works well for me.

    Example:

    best_copier = BestCheckpointCopier(
       name='best', # directory within model directory to copy checkpoints to
       checkpoints_to_keep=10, # number of checkpoints to keep
       score_metric='metrics/total_loss', # metric to use to determine "best"
       compare_fn=lambda x,y: x.score < y.score, # comparison function used to determine "best" checkpoint (x is the current checkpoint; y is the previously copied checkpoint with the highest/worst score)
       sort_key_fn=lambda x: x.score,
       sort_reverse=False) # sort order when discarding excess checkpoints
    

    pass it to your eval_spec:

    eval_spec = tf.estimator.EvalSpec(
       ...
       exporters=best_copier,
       ...)
    

提交回复
热议问题