我使用tf.estimator.train_and_evaluate()来训练我的自定义估计器。我的数据集被划分为8:1:1,用于培训、评估和测试。在培训结束时,我希望恢复最佳模型,并使用tf.estimator.Estimator.evaluate()对测试数据进行评估。当前最好的模型是使用tf.estimator.BestExporter导出的。
虽然tf.estimator.Estimator.evaluate()接受checkpoint_path并恢复变量,但我无法找到任何简单的方法来使用tf.estimator.BestExporter生成的导出模型。当然,我可以在训练期间保留所有的检查点,自己寻找最好的模型,但这似乎不太理想。
有人能告诉我一个简单的解决办法吗?也许可以将保存的模型转换为检查点?
发布于 2018-11-07 07:06:22
希望其他人能找到一种更清洁的方法。
tf.estimator.BestExporter导出最好的模型如下:
<your_estimator.model_dir>
+--export
+--best_exporter
+--xxxxxxxxxx(timestamp)
+--saved_model.pb
+--variables
+--variables.data-00000-of-00001
+--variables.index另一方面,在your_estimator.model_dir中,检查点存储在三个文件中。
model.ckpt-xxxx.data-00000-of-00001
model.ckpt-xxxx.index
model.ckpt-xxxx.meta首先,我使用了tf.estimator.Estimator.evaluate(..., checkpoint_path='<your_estimator.model_dir>/export/best_exporter/<xxxxxxxxxx>/variables/variables'),但这不起作用。
在复制your_estimator.model_dir中的一个元文件并将其重命名为"variables.meta“之后,评估似乎正常工作。
发布于 2020-07-03 08:09:18
也许你可以试试tf.estimator.WarmStartSettings:docs/python/tf/估值器/WarmStartSettings
它可以加载在pb文件中的权重,并继续训练,这是我的项目。
您可以按以下方式设置“温暖启动”:
ws = WarmStartSettings(ckpt_to_initialize_from="/[model_dir]/export/best-exporter/[timestamp]/variables/variables")然后一切都会好起来
发布于 2019-10-11 17:20:07
基于@SumNeuron的Github问题的解决方案,tf.contrib.estimator.SavedModelEstimator是将保存的模型加载到Estimator的方法。
以下几点对我来说是可行的:
estimator = tf.contrib.estimator.SavedModelEstimator(saved_model_dir)
prediction_results = estimator.predict(input_fn)令人费解的是,这基本上是完全没有文件的。
https://stackoverflow.com/questions/53184109
复制相似问题