像python中的xml etree一样解析pbtxt(tensorflow)

时间:2018-01-15 08:00:31

标签: tensorflow protocol-buffers

我正在使用pbtxt格式的TensorFlow图。

pbtxt文件是从tf对象检测API生成的,我需要像xml etree一样解析它。我怎么能这样做?

.pbtxt是freeze_graph的结果

1 个答案:

答案 0 :(得分:0)

问题解决了。您可以使用:

import tensorflow as tf
from google.protobuf import text_format

with open('graph.pbtxt') as f:
    txt = f.read()

graph_def = text_format.Parse(txt, tf.GraphDef())

for node in graph_def.node:
    if node.name == "bla-bla":
        #TODO

有关详细信息:here