如何在TensorFlow中访问TensorProto中的tensor_content值?

jks*_*hin 6 tensorflow

类似于如何在TensorFlow中访问protos中的值?但不适合这种情况.

bytes tensor_contentTensorProto中看到了一个属性.我正试图通过以下方式获取有关节点的信息:

for node in tf.get_default_graph().as_graph_def().node: node.attr['value'].tensor.tensor_content # decode these bytes

有关信息,节点的打印如下所示:

name: "conv2d/convolution/Shape"
op: "Const"
device: "/device:GPU:0"
attr {
  key: "dtype"
  value {
    type: DT_INT32
  }
}
attr {
  key: "value"
  value {
    tensor {
      dtype: DT_INT32
      tensor_shape {
        dim {
          size: 4
        }
      }
      tensor_content: "\003\000\000\000\003\000\000\000\001\000\000\000 \000\000\000"
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

jks*_*hin 10

from tensorflow.python.framework import tensor_util

for n in tf.get_default_graph().as_graph_def().node:
    print tensor_util.MakeNdarray(n.attr['value'].tensor)
Run Code Online (Sandbox Code Playgroud)

  • 还有`tf.make_ndarray`。 (5认同)