Tar*_*ani 7 tensorflow tensorflow-estimator
我tf.estimator.train_and_evaluate()
用来训练我的自定义估算器。我的数据集按 8:1:1 进行分区,用于训练、评估和测试。在训练结束时,我想恢复最佳模型,并使用tf.estimator.Estimator.evaluate()
测试数据评估模型。目前最好的模型是使用tf.estimator.BestExporter
.
虽然tf.estimator.Estimator.evaluate()
接受checkpoint_path
和恢复变量,但我找不到任何简单的方法来使用由tf.estimator.BestExporter
. 我当然可以在训练期间保留所有检查点,并自己寻找最佳模型,但这似乎不太理想。
谁能告诉我一个简单的解决方法?也许可以将保存的模型转换为检查点?
也许你可以试试 tf.estimator.WarmStartSettings: https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/estimator/WarmStartSettings
它可以在 pb 文件中加载权重并继续训练,这对我的项目有效。
您可以按如下方式设置热启动:
ws = WarmStartSettings(ckpt_to_initialize_from="/[model_dir]/export/best-exporter/[timestamp]/variables/variables")
Run Code Online (Sandbox Code Playgroud)
然后一切都会好起来的
希望其他人能找到更干净的方法..
tf.estimator.BestExporter
导出最好的模型,如下所示:
<your_estimator.model_dir>
+--export
+--best_exporter
+--xxxxxxxxxx(timestamp)
+--saved_model.pb
+--variables
+--variables.data-00000-of-00001
+--variables.index
Run Code Online (Sandbox Code Playgroud)
另一方面,在 中your_estimator.model_dir
,检查点存储在三个文件中。
model.ckpt-xxxx.data-00000-of-00001
model.ckpt-xxxx.index
model.ckpt-xxxx.meta
Run Code Online (Sandbox Code Playgroud)
首先,我使用了tf.estimator.Estimator.evaluate(..., checkpoint_path='<your_estimator.model_dir>/export/best_exporter/<xxxxxxxxxx>/variables/variables')
,但这不起作用。
复制其中一个图元文件your_estimator.model_dir
并将其重命名为“variables.meta”后,评估似乎工作正常。
归档时间: |
|
查看次数: |
2968 次 |
最近记录: |