gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 13:36:53 26 4
gpt4 key购买 nike

How to access values in protos in TensorFlow?类似,但不适合这种情况。

我在TensorProto中看到了bytes tensor_content属性。我正在尝试通过以下方式获取有关节点的信息:

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"
}
}
}

最佳答案

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)

关于tensorflow - 如何在TensorFlow中的TensorProto中访问tensor_content值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44125403/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com