如何将labelmap.prototxt转换为集合?咖啡

时间:2018-07-29 11:45:34

标签: python dictionary caffe

我有 labelmap.prototxt ,我想将其转换为集合,因为我想将其与Intel Neural Compute Stick SDK一起使用。

输入

home / labelmap.prototxt

self

输出:

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"])

1 个答案:

答案 0 :(得分:1)

在caffe ssd中,获取有关原型缓冲区的信息,即持久性消息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]