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

前端 未结 3 1723
耶瑟儿~
耶瑟儿~ 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:07

    If you are training using the models repo of tensorflow/models. models/research/object_detection/model_lib.py file create_train_and_eval_specs function can be modified to include the best exporter:

    final_exporter = tf.estimator.FinalExporter(
        name=final_exporter_name, serving_input_receiver_fn=predict_input_fn)
    
    best_exporter = tf.estimator.BestExporter(
        name="best_exporter",
        serving_input_receiver_fn=predict_input_fn,
        event_file_pattern='eval_eval/*.tfevents.*',
        exports_to_keep=5)
    exporters = [final_exporter, best_exporter]
    
    train_spec = tf.estimator.TrainSpec(
        input_fn=train_input_fn, max_steps=train_steps)
    
    eval_specs = [
        tf.estimator.EvalSpec(
            name=eval_spec_name,
            input_fn=eval_input_fn,
            steps=eval_steps,
            exporters=exporters)
    ]
    

提交回复
热议问题