Tensorflow get shape from Graph Def in C++

问题内容:

I’m trying to get shape of input tensor in C++ before I do any inference calls. So I can do it only from Graph Def.

I’m trying like:

 auto att = graph_def.node(i).attr();
 att["shape"].PrintDebugString();
 Tensor tensor;
 std::cerr << tensor.FromProto(att["shape"].tensor()) << std::endl;

And it returs false. While PrintDebugString prints:

shape { dim {
size: -1 } dim {
size: 1024 } dim {
size: 1024 } dim {
size: 3 } }

So all I need is to get that 1024x1024x3. I’m not very familiar with Protobuf protocol and for me is totally unclear how to do that.

问题评论:

    
I don’t have the C++ API installed, so this suggestion might be wrong, but this operation will give you the size of the considered dimension in Python: graphDef.node[i].attr['shape'].dim[j].size. Note that node, shape, dim are google protobuf::Message derivatives.

原文地址:

https://stackoverflow.com/questions/47753701/tensorflow-get-shape-from-graph-def-in-c

Add a Comment