我有一个labelmap.prototxt,我想把它转换成一个集合,因为我想将它与英特尔神经计算棒SDK一起使用。
输入
home/labelmap.prototxt
item {
name: "none_of_the_above"
label: 0
display_name: "background"
}
item {
name: "1"
label: 1
display_name: "person"
}
item {
name: "2"
label: 2
display_name: "bicycle"
}
item {
name: "3"
label: 3
display_name: "car"
}输出:
set(["background","person","bicycle","car"])我试过如下:
>>> with open('labelmap_coco.prototxt') as f:
... d = literal_eval(f)
...
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
File "/usr/lib/python2.7/ast.py", line 80, in literal_eval
return _convert(node_or_string)
File "/usr/lib/python2.7/ast.py", line 79, in _convert
raise ValueError('malformed string')
ValueError: malformed string发布于 2018-09-08 22:47:02
阅读proto缓冲区,在文件中持久化消息LabelMap,这样您就可以从prototxt读取对象数据。这是一件很好的事。查看代码:
from caffe.proto import caffe_pb2
from google.protobuf import text_format as tf
f = open('labelmap.prototxt', 'r')
lm = caffe_pb2.LabelMap()
lm = tf.Parse(f.read(), lm)
display_names = [x.display_name for x in lm.item]https://stackoverflow.com/questions/51580013
复制相似问题