当前位置: 首页>>代码示例>>Python>>正文


Python label_map_util.convert_label_map_to_categories方法代码示例

本文整理汇总了Python中object_detection.utils.label_map_util.convert_label_map_to_categories方法的典型用法代码示例。如果您正苦于以下问题:Python label_map_util.convert_label_map_to_categories方法的具体用法?Python label_map_util.convert_label_map_to_categories怎么用?Python label_map_util.convert_label_map_to_categories使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在object_detection.utils.label_map_util的用法示例。


在下文中一共展示了label_map_util.convert_label_map_to_categories方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from object_detection.utils import label_map_util [as 别名]
# 或者: from object_detection.utils.label_map_util import convert_label_map_to_categories [as 别名]
def main(unused_argv):
  assert FLAGS.checkpoint_dir, '`checkpoint_dir` is missing.'
  assert FLAGS.eval_dir, '`eval_dir` is missing.'
  if FLAGS.pipeline_config_path:
    model_config, eval_config, input_config = get_configs_from_pipeline_file()
  else:
    model_config, eval_config, input_config = get_configs_from_multiple_files()

  model_fn = functools.partial(
      model_builder.build,
      model_config=model_config,
      is_training=False)

  create_input_dict_fn = functools.partial(
      input_reader_builder.build,
      input_config)

  label_map = label_map_util.load_labelmap(input_config.label_map_path)
  max_num_classes = max([item.id for item in label_map.item])
  categories = label_map_util.convert_label_map_to_categories(
      label_map, max_num_classes)

  evaluator.evaluate(create_input_dict_fn, model_fn, eval_config, categories,
                     FLAGS.checkpoint_dir, FLAGS.eval_dir) 
开发者ID:ringringyi,项目名称:DOTA_models,代码行数:26,代码来源:eval.py

示例2: load_model

# 需要导入模块: from object_detection.utils import label_map_util [as 别名]
# 或者: from object_detection.utils.label_map_util import convert_label_map_to_categories [as 别名]
def load_model(self):
        """
        Loads the detection model

        Args:

        Returns:

        """

        with self._detection_graph.as_default():
            od_graph_def = tf.GraphDef()
            with tf.gfile.GFile(self._path_to_ckpt, 'rb') as fid:
                serialized_graph = fid.read()
                od_graph_def.ParseFromString(serialized_graph)
                tf.import_graph_def(od_graph_def, name='')

        label_map = label_map_util.load_labelmap(self._path_to_labels)
        categories = label_map_util.convert_label_map_to_categories(\
            label_map, max_num_classes=self._num_classes, use_display_name=True)
        self.category_index = label_map_util.create_category_index(categories) 
开发者ID:cagbal,项目名称:ros_people_object_detection_tensorflow,代码行数:23,代码来源:detector.py

示例3: evaluate

# 需要导入模块: from object_detection.utils import label_map_util [as 别名]
# 或者: from object_detection.utils.label_map_util import convert_label_map_to_categories [as 别名]
def evaluate(self, eval_pipeline_file, model_dir, eval_dir):
        configs = self._get_configs_from_pipeline_file(eval_pipeline_file)
        model_config = configs['model']
        eval_config = configs['eval_config']
        input_config = configs['eval_input_config']
        model_fn = functools.partial(
            model_builder.build,
            model_config=model_config,
            is_training=True)
        create_input_dict_fn = functools.partial(self.get_next, input_config)
        label_map = label_map_util.load_labelmap(input_config.label_map_path)
        max_num_classes = max([item.id for item in label_map.item])
        categories = label_map_util.convert_label_map_to_categories(
                        label_map, max_num_classes)
        evaluator.evaluate(create_input_dict_fn, model_fn, eval_config, categories,
                        model_dir, eval_dir) 
开发者ID:autoai-org,项目名称:CVTron,代码行数:18,代码来源:object_detection_trainer.py

示例4: test_keep_categories_with_unique_id

# 需要导入模块: from object_detection.utils import label_map_util [as 别名]
# 或者: from object_detection.utils.label_map_util import convert_label_map_to_categories [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

示例5: test_convert_label_map_to_categories_no_label_map

# 需要导入模块: from object_detection.utils import label_map_util [as 别名]
# 或者: from object_detection.utils.label_map_util import convert_label_map_to_categories [as 别名]
def test_convert_label_map_to_categories_no_label_map(self):
    categories = label_map_util.convert_label_map_to_categories(
        None, max_num_classes=3)
    expected_categories_list = [{
        'name': u'category_1',
        'id': 1
    }, {
        'name': u'category_2',
        'id': 2
    }, {
        'name': u'category_3',
        'id': 3
    }]
    self.assertListEqual(expected_categories_list, categories) 
开发者ID:datitran,项目名称:object_detector_app,代码行数:16,代码来源:label_map_util_test.py

示例6: test_convert_label_map_to_coco_categories

# 需要导入模块: from object_detection.utils import label_map_util [as 别名]
# 或者: from object_detection.utils.label_map_util import convert_label_map_to_categories [as 别名]
def test_convert_label_map_to_coco_categories(self):
    label_map_proto = self._generate_label_map(num_classes=4)
    categories = label_map_util.convert_label_map_to_categories(
        label_map_proto, max_num_classes=3)
    expected_categories_list = [{
        'name': u'1',
        'id': 1
    }, {
        'name': u'2',
        'id': 2
    }, {
        'name': u'3',
        'id': 3
    }]
    self.assertListEqual(expected_categories_list, categories) 
开发者ID:datitran,项目名称:object_detector_app,代码行数:17,代码来源:label_map_util_test.py

示例7: test_convert_label_map_to_coco_categories_with_few_classes

# 需要导入模块: from object_detection.utils import label_map_util [as 别名]
# 或者: from object_detection.utils.label_map_util import convert_label_map_to_categories [as 别名]
def test_convert_label_map_to_coco_categories_with_few_classes(self):
    label_map_proto = self._generate_label_map(num_classes=4)
    cat_no_offset = label_map_util.convert_label_map_to_categories(
        label_map_proto, max_num_classes=2)
    expected_categories_list = [{
        'name': u'1',
        'id': 1
    }, {
        'name': u'2',
        'id': 2
    }]
    self.assertListEqual(expected_categories_list, cat_no_offset) 
开发者ID:datitran,项目名称:object_detector_app,代码行数:14,代码来源:label_map_util_test.py

示例8: test_convert_label_map_to_categories

# 需要导入模块: from object_detection.utils import label_map_util [as 别名]
# 或者: from object_detection.utils.label_map_util import convert_label_map_to_categories [as 别名]
def test_convert_label_map_to_categories(self):
    label_map_proto = self._generate_label_map(num_classes=4)
    categories = label_map_util.convert_label_map_to_categories(
        label_map_proto, max_num_classes=3)
    expected_categories_list = [{
        'name': u'1',
        'id': 1
    }, {
        'name': u'2',
        'id': 2
    }, {
        'name': u'3',
        'id': 3
    }]
    self.assertListEqual(expected_categories_list, categories) 
开发者ID:ahmetozlu,项目名称:vehicle_counting_tensorflow,代码行数:17,代码来源:label_map_util_test.py

示例9: test_convert_label_map_to_categories_with_few_classes

# 需要导入模块: from object_detection.utils import label_map_util [as 别名]
# 或者: from object_detection.utils.label_map_util import convert_label_map_to_categories [as 别名]
def test_convert_label_map_to_categories_with_few_classes(self):
    label_map_proto = self._generate_label_map(num_classes=4)
    cat_no_offset = label_map_util.convert_label_map_to_categories(
        label_map_proto, max_num_classes=2)
    expected_categories_list = [{
        'name': u'1',
        'id': 1
    }, {
        'name': u'2',
        'id': 2
    }]
    self.assertListEqual(expected_categories_list, cat_no_offset) 
开发者ID:ahmetozlu,项目名称:vehicle_counting_tensorflow,代码行数:14,代码来源:label_map_util_test.py

示例10: load

# 需要导入模块: from object_detection.utils import label_map_util [as 别名]
# 或者: from object_detection.utils.label_map_util import convert_label_map_to_categories [as 别名]
def load(self):
		with open(os.path.join(self.model_path, 'config.json')) as f:
			data = json.load(f)
		try:
			self.validate_json_configuration(data)
			self.set_model_configuration(data)
		except ApplicationError as e:
			raise e

		self.label_path = os.path.join(self.model_path, 'object-detection.pbtxt')
		self.label_map = label_map_util.load_labelmap(self.label_path)
		self.categories = label_map_util.convert_label_map_to_categories(self.label_map,
																		 max_num_classes=self.NUM_CLASSES,
																		 use_display_name=True)
		for dict in self.categories:
			self.labels.append(dict['name'])

		self.category_index = label_map_util.create_category_index(self.categories)
		self.detection_graph = tf.Graph()
		with self.detection_graph.as_default():
			od_graph_def = tf.GraphDef()
			with tf.gfile.GFile(os.path.join(self.model_path, 'frozen_inference_graph.pb'), 'rb') as fid:
				serialized_graph = fid.read()
				od_graph_def.ParseFromString(serialized_graph)
				tf.import_graph_def(od_graph_def, name='')
			self.image_tensor = self.detection_graph.get_tensor_by_name('image_tensor:0')
			self.d_boxes = self.detection_graph.get_tensor_by_name('detection_boxes:0')
			self.d_scores = self.detection_graph.get_tensor_by_name('detection_scores:0')
			self.d_classes = self.detection_graph.get_tensor_by_name('detection_classes:0')
			self.num_d = self.detection_graph.get_tensor_by_name('num_detections:0')
		self.sess = tf.Session(graph=self.detection_graph)
		img = Image.open("object_detection/image1.jpg")
		img_expanded = np.expand_dims(img, axis=0)
		self.sess.run(
			[self.d_boxes, self.d_scores, self.d_classes, self.num_d],
			feed_dict={self.image_tensor: img_expanded}) 
开发者ID:BMW-InnovationLab,项目名称:BMW-TensorFlow-Inference-API-CPU,代码行数:38,代码来源:tensorflow_detection.py

示例11: format_output

# 需要导入模块: from object_detection.utils import label_map_util [as 别名]
# 或者: from object_detection.utils.label_map_util import convert_label_map_to_categories [as 别名]
def format_output(self, results, im_width, im_height, threshold):
        label_map = label_map_util.load_labelmap(self.label_map)
        categories = label_map_util.convert_label_map_to_categories(label_map, max_num_classes=90, use_display_name=True)
        category_index = label_map_util.create_category_index(categories)
        vis_results = []
        for i in range(len(results)):
            output_dict = results[i]
            boxes = output_dict['detection_boxes']
            classes = output_dict['detection_classes']
            scores = output_dict['detection_scores']
            for j in range(boxes.shape[0]):
                if scores[i] > threshold:
                    result = {}
                    ymin, xmin, ymax, xmax = tuple(boxes[i].tolist())
                    result['x_min'] = xmin * im_width
                    result['x_max'] = xmax * im_width
                    result['y_min'] = ymin * im_height
                    result['y_max'] = ymax * im_height
                    result['score'] = float(scores[i])
                    if classes[i] in category_index.keys():
                        class_name = category_index[classes[i]]['name']
                    else:
                        class_name = 'N/A'
                    result['class_name'] = str(class_name)
                    if result not in vis_results:
                        vis_results.append(result)
        return vis_results 
开发者ID:autoai-org,项目名称:CVTron,代码行数:29,代码来源:slim_object_detector.py


注:本文中的object_detection.utils.label_map_util.convert_label_map_to_categories方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。