【问题标题】:Export Tensorflow Estimator导出 TensorFlow 估计器
【发布时间】:2018-05-06 12:16:29
【问题描述】:

我正在尝试使用基于 API tf.estimator 的 Tensorflow (r1.4) 构建 CNN。这是一个罐头模型。这个想法是在 python 中使用 estimator 来训练和评估网络,并通过加载训练后生成的 pb 文件来使用没有 estimator 的 C++ 中的预测。

我的第一个问题是,这可能吗?

如果是,则训练部分有效,预测部分也有效(在没有估算器的情况下生成 pb 文件)但是当我从估算器加载 pb 文件时它不起作用。

我收到此错误:"Data loss: Can't parse saved_model.pb as binary proto" 我的 pyhon 代码导出我的模型:

feature_spec = {'input_image': parsing_ops.FixedLenFeature(dtype=dtypes.float32, shape=[1, 48 * 48])}
export_input_fn = tf.estimator.export.build_parsing_serving_input_receiver_fn(feature_spec)

input_fn = tf.estimator.inputs.numpy_input_fn(self.eval_features,
                                              self.eval_label,
                                              shuffle=False,
                                              num_epochs=1)
eval_result = self.model.evaluate(input_fn=input_fn, name='eval')
exporter = tf.estimator.FinalExporter('save_model', export_input_fn)
exporter.export(estimator=self.model, export_path=MODEL_DIR,
                checkpoint_path=self.model.latest_checkpoint(),
                eval_result=eval_result,
                is_the_final_export=True)

它不适用于tf.estimator.Estimator.export_savedmodel()

如果你们中有人知道关于带有固定模型的估算器以及如何导出它的明确教程,我很感兴趣

【问题讨论】:

    标签: python tensorflow tensorflow-estimator


    【解决方案1】:

    请看github上的this issue,看来你也有同样的问题。显然(至少在使用 estimator.export_savedmodel 时)您应该使用 LoadSavedModel 而不是 ReadBinaryProto 加载图形,因为它没有保存为 graphdef 文件。

    您会在here 找到更多关于如何使用它的说明:

     const string export_dir = ...
    SavedModelBundle bundle;
    ...
    LoadSavedModel(session_options, run_options, export_dir, {kSavedModelTagTrain},
                   &bundle);
    

    我似乎找不到 c++ 的 SavedModelBundle 文档以供以后使用,但它可能接近 the same class in Java,在这种情况下,它基本上包含会话和您将使用的图表。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-04
      • 1970-01-01
      • 2018-06-15
      • 2019-01-04
      • 2019-04-29
      相关资源
      最近更新 更多