C++ equivalent of python: tf.Graph.get_tensor_by_name() in Tensorflow?

后端 未结 3 1235
滥情空心
滥情空心 2020-12-18 07:23

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

3条回答
  •  长情又很酷
    2020-12-18 08:20

    In case anybody is interested, here is how you extract the shape of an arbitrary sensor from graph_def using the tensorflow C++ API

    vector get_shape_of_tensor(tensorflow::GraphDef graph_def, std::string name_tensor)
    {
        vector tensor_shape;
        for (int i=0; i < graph_def.node_size(); ++i) {
            if (graph_def.node(i).name() == name_tensor) {
                auto node = graph_def.node(i);
                auto attr_map = node.attr();
                for (auto it=attr_map.begin(); it != attr_map.end(); it++) {
                    auto key = it->first;
                    auto value = it->second;
                    if (value.has_shape()) {
                        auto shape = value.shape();
                        for (int i=0; i

提交回复
热议问题