Tensorflow中的C ++等价于python:tf.Graph.get_tensor_by_name()? [英] C++ equivalent of python: tf.Graph.get_tensor_by_name() in Tensorflow?

查看:183
本文介绍了Tensorflow中的C ++等价于python:tf.Graph.get_tensor_by_name()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Tensorflow中python的tf.Graph.get_tensor_by_name(name)相当于C ++吗?谢谢!

What is the C++ equivalent of python: tf.Graph.get_tensor_by_name(name) in Tensorflow? Thanks!

这是我要运行的代码,但输出为空的

Here is the code I am trying to run, but I get an empty output:

Status status = NewSession(SessionOptions(), &session); // create new session
ReadBinaryProto(tensorflow::Env::Default(), model, &graph_def); // read Graph
session->Create(graph_def); // add Graph to Tensorflow session 
std::vector<tensorflow::Tensor> output; // create Tensor to store output
std::vector<string> vNames; // vector of names for required graph nodes
vNames.push_back("some_name"); // I checked names and they are presented in loaded Graph

session->Run({}, vNames, {}, &output); // ??? As a result I have empty output


推荐答案

有一种方法直接从graph_def获取神经节点。
,如果您只想要节点的形状类型: some_name:

there is a way to get neural node from graph_def directly. if u only want the shape\type of node: "some_name":

void readPB(GraphDef & graph_def)
{

    int i;
    for (i = 0; i < graph_def.node_size(); i++)
    {
        if (graph_def.node(i).name() == "inputx")
        {
            graph_def.node(i).PrintDebugString();
        }
    }
}

结果:

name: "inputx"
op: "Placeholder"
attr {
  key: "dtype"
  value {
    type: DT_FLOAT
  }
}
attr {
  key: "shape"
  value {
    shape {
      dim {
        size: -1
      }
      dim {
        size: 5120
      }
    }
  }
}

尝试节点的成员函数并获取信息。

try member functins of the node and get the informations.

这篇关于Tensorflow中的C ++等价于python:tf.Graph.get_tensor_by_name()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆