如何使用TF2在最新的Tensorflow对象检测API V2中保存最佳模型?

问题描述

最近,我正在尝试使用带有TF2的Tensorflow对象检测API V2,并且我已经成功地训练了网络。

但是,我发现有关如何保存最佳模型的信息很少。

我找到了一些简单的教程,对这些细节的讨论不多。

我发现了类似的问题here,但是最好的答案是修改legacy/trainer.py,这似乎已经过时了。

我还发现了另一个类似的问题here,但是答案是关于exporters中的model_lib.py,但是我在{{1 }}

因此,对于V2,我应该修改哪个文件以保存最佳模型?

解决方法

假设您使用的是TF2 Object Detection repository中的官方脚本,那么会有一个tensorflow/models/research/object_detection/exporter_main_v2.py文件用于保存模型。

用法

python .\exporter_main_v2.py \
    --input_type image_tensor \
    --pipeline_config_path .\...\pipeline.config \
    --trained_checkpoint_dir .\...\training \
    --output_directory .\...\my_model

来源: https://tensorflow-object-detection-api-tutorial.readthedocs.io/en/latest/training.html#exporting-a-trained-model