【问题标题】:How to import trained tf.contrib.learn.dnnclassifier using C_API如何使用 C_API 导入训练有素的 tf.contrib.learn.dnnclassifier
【发布时间】:2018-04-12 14:07:19
【问题描述】:

如何使用 C_API 导入经过训练的 DNNClassifer?我尝试使用 TF_LoadSessionFromSavedModel,但它引发了以下错误:

I tensorflow/cc/saved_model/loader.cc:284] 加载 SavedModel:失败。

这里是C部分的代码:

    const char* export_dir = "path_to_trained_model/folder_with_trained_model";
    const char* tags_[1] = {"import"};

    TF_Graph* graph_new = TF_NewGraph();
    TF_Buffer* meta_graph_def= TF_NewBuffer();
    TF_SessionOptions* opt = TF_NewSessionOptions();
    TF_Buffer* run_options = TF_NewBufferFromString("", 0);
    TF_Status* s = TF_NewStatus();

    TF_Session* session1= TF_LoadSessionFromSavedModel(
            opt, run_options,  export_dir,
            tags_, 1,  graph_new,
            meta_graph_def, s);

【问题讨论】:

  • 你想用 c++ 训练这个模型吗?或者只是加载一个冻结的模型并运行推理?
  • 只加载训练好的模型并运行评估;该模型被训练为 tf.contrib.learn.dnnclassifier,我将检查点和图形保存在定义的目录中
  • 你有冷冻模型吗?通常带有扩展名 .pb ?
  • 我无法冻结 dnnclassifier,但我有 .pbtxt(也可以翻译成 .pb)以及保存在检查点的 .meta 和 .index 文件
  • 那么对不起。我知道如何加载和使用 .pb 文件。当您使用 python 将其保存为冻结模型时。

标签: python c++ tensorflow c-api


【解决方案1】:

我最近遇到了同样的错误。真正帮助我的是看看 TF_Message(s)(这个表达式应该返回一个以 null 结尾的 c 字符串(即 char*))指向什么。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-11-26
    • 2017-11-06
    • 2019-09-09
    • 1970-01-01
    • 2018-09-19
    • 1970-01-01
    • 2018-08-30
    • 1970-01-01
    相关资源
    最近更新 更多