How to access tensor_content values in TensorProto in TensorFlow?

前端 未结 2 2085
花落未央
花落未央 2021-01-02 13:49

Similar to How to access values in protos in TensorFlow? but doesn\'t cater for this case.

I see a bytes tensor_content attribute in TensorProto. I\'m t

相关标签:
2条回答
  • 2021-01-02 13:55

    Decode tensor_array bytes and then reshape with given shape:

    for node in tf.get_default_graph.as_graph_def().node:
        tensor_bytes = node.attr["value"].tensor.tensor_content
        tensor_dtype = node.attr["value"].tensor.dtype
        tensor_shape = [x.size for x in node.attr["value"].tensor.tensor_shape.dim]
        tensor_array = tf.decode_raw(tensor_bytes, tensor_dtype)
        tensor_array = tf.reshape(tensor_array, tensor_shape)
    
    0 讨论(0)
  • 2021-01-02 14:05
    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)
    
    0 讨论(0)
提交回复
热议问题