【问题标题】:Connecting nodes of different GraphDef's连接不同 GraphDef 的节点
【发布时间】:2017-10-10 01:46:34
【问题描述】:

在 Python 中,我有一个冻结的 graph.pb,我目前正在 C++ 环境中使用它。现在输入张量的数据当前在 CPU 上进行了预处理,但我想在另一个 GraphDef 中执行此步骤以在 GPU 上运行它,但我似乎找不到连接两个 GraphDef 之间节点的方法的。

假设我的冻结图有一个名为 mid 的输入/占位符,我想将其与下面的预处理步骤联系起来

tf::GraphDef create_graph_extension() {
    tf::Scope root = tf::Scope::NewRootScope();

    auto a = tf::ops::Const(root.WithOpName("in"), {(float) 23.0, (float) 31.0});
    auto b = tf::ops::Identity(root.WithOpName("mid"), a);

    tf::GraphDef graph;
    TF_CHECK_OK(root.ToGraphDef(&graph));
    return graph;
}

我通常使用session->Extend() 在同一个会话中运行多个图表,但始终确保它们的节点名称是唯一的。对于我希望连接的非唯一节点名称,我收到错误

Failed to install graph:
Invalid argument: GraphDef argument to Extend includes node 'mid', which 
was created by a previous call to Create or Extend in this session.

附:似乎至少在 python 中是可能的 (link)

【问题讨论】:

    标签: c++ tensorflow


    【解决方案1】:

    您可以使用为 Python 建议的相同想法来实现您正在寻找的东西 - 将一个 GraphDef 导入另一个并重新映射输入。

    如果您确实使用了 C API(具有 stability guarantees),您需要查看:

    这些是在 C++ ImportGraphDef 函数之上实现的,您可以直接使用该函数(尽管它似乎还不是导出的 C++ API 的一部分)

    希望对您有所帮助。

    【讨论】:

      猜你喜欢
      • 2021-07-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-13
      • 1970-01-01
      • 2018-12-26
      • 2014-01-05
      • 1970-01-01
      相关资源
      最近更新 更多