當前位置: 首頁>>代碼示例>>Python>>正文


Python string_int_label_map_pb2.StringIntLabelMap方法代碼示例

本文整理匯總了Python中object_detection.protos.string_int_label_map_pb2.StringIntLabelMap方法的典型用法代碼示例。如果您正苦於以下問題:Python string_int_label_map_pb2.StringIntLabelMap方法的具體用法?Python string_int_label_map_pb2.StringIntLabelMap怎麽用?Python string_int_label_map_pb2.StringIntLabelMap使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在object_detection.protos.string_int_label_map_pb2的用法示例。


在下文中一共展示了string_int_label_map_pb2.StringIntLabelMap方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: load_labelmap

# 需要導入模塊: from object_detection.protos import string_int_label_map_pb2 [as 別名]
# 或者: from object_detection.protos.string_int_label_map_pb2 import StringIntLabelMap [as 別名]
def load_labelmap(path):
  """Loads label map proto.

  Args:
    path: path to StringIntLabelMap proto text file.
  Returns:
    a StringIntLabelMapProto
  """
  with tf.gfile.GFile(path, 'r') as fid:
    label_map_string = fid.read()
    label_map = string_int_label_map_pb2.StringIntLabelMap()
    try:
      text_format.Merge(label_map_string, label_map)
    except text_format.ParseError:
      label_map.ParseFromString(label_map_string)
  _validate_label_map(label_map)
  return label_map 
開發者ID:ringringyi,項目名稱:DOTA_models,代碼行數:19,代碼來源:label_map_util.py

示例2: load_labelmap

# 需要導入模塊: from object_detection.protos import string_int_label_map_pb2 [as 別名]
# 或者: from object_detection.protos.string_int_label_map_pb2 import StringIntLabelMap [as 別名]
def load_labelmap(path):
  """Loads label map proto.

  Args:
    path: path to StringIntLabelMap proto text file.
  Returns:
    a StringIntLabelMapProto
  """
  with tf.gfile.GFile(path, 'r') as fid:
    label_map_string = fid.read()
    label_map = string_int_label_map_pb2.StringIntLabelMap()
    try:
      text_format.Merge(label_map_string, label_map)
    except text_format.ParseError:
      label_map.ParseFromString(label_map_string)
  return label_map 
開發者ID:datitran,項目名稱:object_detector_app,代碼行數:18,代碼來源:label_map_util.py

示例3: _load_labelmap

# 需要導入模塊: from object_detection.protos import string_int_label_map_pb2 [as 別名]
# 或者: from object_detection.protos.string_int_label_map_pb2 import StringIntLabelMap [as 別名]
def _load_labelmap(labelmap_path):
  """Loads labelmap from the labelmap path.

  Args:
    labelmap_path: Path to the labelmap.

  Returns:
    A dictionary mapping class name to class numerical id.
  """

  label_map = string_int_label_map_pb2.StringIntLabelMap()
  with open(labelmap_path, 'r') as fid:
    label_map_string = fid.read()
    text_format.Merge(label_map_string, label_map)
  labelmap_dict = {}
  for item in label_map.item:
    labelmap_dict[item.name] = item.id
  return labelmap_dict 
開發者ID:ahmetozlu,項目名稱:vehicle_counting_tensorflow,代碼行數:20,代碼來源:oid_vrd_challenge_evaluation.py

示例4: _load_labelmap

# 需要導入模塊: from object_detection.protos import string_int_label_map_pb2 [as 別名]
# 或者: from object_detection.protos.string_int_label_map_pb2 import StringIntLabelMap [as 別名]
def _load_labelmap(labelmap_path):
  """Loads labelmap from the labelmap path.

  Args:
    labelmap_path: Path to the labelmap.

  Returns:
    A dictionary mapping class name to class numerical id
    A list with dictionaries, one dictionary per category.
  """

  label_map = string_int_label_map_pb2.StringIntLabelMap()
  with open(labelmap_path, 'r') as fid:
    label_map_string = fid.read()
    text_format.Merge(label_map_string, label_map)
  labelmap_dict = {}
  categories = []
  for item in label_map.item:
    labelmap_dict[item.name] = item.id
    categories.append({'id': item.id, 'name': item.name})
  return labelmap_dict, categories 
開發者ID:ahmetozlu,項目名稱:vehicle_counting_tensorflow,代碼行數:23,代碼來源:oid_od_challenge_evaluation.py

示例5: create_categories_from_labelmap

# 需要導入模塊: from object_detection.protos import string_int_label_map_pb2 [as 別名]
# 或者: from object_detection.protos.string_int_label_map_pb2 import StringIntLabelMap [as 別名]
def create_categories_from_labelmap(label_map_path, use_display_name=True):
  """Reads a label map and returns categories list compatible with eval.

  This function converts label map proto and returns a list of dicts, each of
  which  has the following keys:
    'id': an integer id uniquely identifying this category.
    'name': string representing category name e.g., 'cat', 'dog'.

  Args:
    label_map_path: Path to `StringIntLabelMap` proto text file.
    use_display_name: (boolean) choose whether to load 'display_name' field
      as category name.  If False or if the display_name field does not exist,
      uses 'name' field as category names instead.

  Returns:
    categories: a list of dictionaries representing all possible categories.
  """
  label_map = load_labelmap(label_map_path)
  max_num_classes = max(item.id for item in label_map.item)
  return convert_label_map_to_categories(label_map, max_num_classes,
                                         use_display_name) 
開發者ID:ahmetozlu,項目名稱:vehicle_counting_tensorflow,代碼行數:23,代碼來源:label_map_util.py

示例6: create_category_index_from_labelmap

# 需要導入模塊: from object_detection.protos import string_int_label_map_pb2 [as 別名]
# 或者: from object_detection.protos.string_int_label_map_pb2 import StringIntLabelMap [as 別名]
def create_category_index_from_labelmap(label_map_path, use_display_name=True):
  """Reads a label map and returns a category index.

  Args:
    label_map_path: Path to `StringIntLabelMap` proto text file.
    use_display_name: (boolean) choose whether to load 'display_name' field
      as category name.  If False or if the display_name field does not exist,
      uses 'name' field as category names instead.

  Returns:
    A category index, which is a dictionary that maps integer ids to dicts
    containing categories, e.g.
    {1: {'id': 1, 'name': 'dog'}, 2: {'id': 2, 'name': 'cat'}, ...}
  """
  categories = create_categories_from_labelmap(label_map_path, use_display_name)
  return create_category_index(categories) 
開發者ID:ahmetozlu,項目名稱:vehicle_counting_tensorflow,代碼行數:18,代碼來源:label_map_util.py

示例7: _generate_label_map

# 需要導入模塊: from object_detection.protos import string_int_label_map_pb2 [as 別名]
# 或者: from object_detection.protos.string_int_label_map_pb2 import StringIntLabelMap [as 別名]
def _generate_label_map(self, num_classes):
    label_map_proto = string_int_label_map_pb2.StringIntLabelMap()
    for i in range(1, num_classes + 1):
      item = label_map_proto.item.add()
      item.id = i
      item.name = 'label_' + str(i)
      item.display_name = str(i)
    return label_map_proto 
開發者ID:ringringyi,項目名稱:DOTA_models,代碼行數:10,代碼來源:label_map_util_test.py

示例8: _validate_label_map

# 需要導入模塊: from object_detection.protos import string_int_label_map_pb2 [as 別名]
# 或者: from object_detection.protos.string_int_label_map_pb2 import StringIntLabelMap [as 別名]
def _validate_label_map(label_map):
  """Checks if a label map is valid.

  Args:
    label_map: StringIntLabelMap to validate.

  Raises:
    ValueError: if label map is invalid.
  """
  for item in label_map.item:
    if item.id < 1:
      raise ValueError('Label map ids should be >= 1.') 
開發者ID:ringringyi,項目名稱:DOTA_models,代碼行數:14,代碼來源:label_map_util.py

示例9: test_keep_categories_with_unique_id

# 需要導入模塊: from object_detection.protos import string_int_label_map_pb2 [as 別名]
# 或者: from object_detection.protos.string_int_label_map_pb2 import StringIntLabelMap [as 別名]
def test_keep_categories_with_unique_id(self):
    label_map_proto = string_int_label_map_pb2.StringIntLabelMap()
    label_map_string = """
      item {
        id:2
        name:'cat'
      }
      item {
        id:1
        name:'child'
      }
      item {
        id:1
        name:'person'
      }
      item {
        id:1
        name:'n00007846'
      }
    """
    text_format.Merge(label_map_string, label_map_proto)
    categories = label_map_util.convert_label_map_to_categories(
        label_map_proto, max_num_classes=3)
    self.assertListEqual([{
        'id': 2,
        'name': u'cat'
    }, {
        'id': 1,
        'name': u'child'
    }], categories) 
開發者ID:datitran,項目名稱:object_detector_app,代碼行數:32,代碼來源:label_map_util_test.py


注:本文中的object_detection.protos.string_int_label_map_pb2.StringIntLabelMap方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。