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


Python losses_pb2.HardExampleMiner方法代碼示例

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


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

示例1: build_hard_example_miner

# 需要導入模塊: from object_detection.protos import losses_pb2 [as 別名]
# 或者: from object_detection.protos.losses_pb2 import HardExampleMiner [as 別名]
def build_hard_example_miner(config,
                             classification_weight,
                             localization_weight):
  """Builds hard example miner based on the config.

  Args:
    config: A losses_pb2.HardExampleMiner object.
    classification_weight: Classification loss weight.
    localization_weight: Localization loss weight.

  Returns:
    Hard example miner.

  """
  loss_type = None
  if config.loss_type == losses_pb2.HardExampleMiner.BOTH:
    loss_type = 'both'
  if config.loss_type == losses_pb2.HardExampleMiner.CLASSIFICATION:
    loss_type = 'cls'
  if config.loss_type == losses_pb2.HardExampleMiner.LOCALIZATION:
    loss_type = 'loc'

  max_negatives_per_positive = None
  num_hard_examples = None
  if config.max_negatives_per_positive > 0:
    max_negatives_per_positive = config.max_negatives_per_positive
  if config.num_hard_examples > 0:
    num_hard_examples = config.num_hard_examples
  hard_example_miner = losses.HardExampleMiner(
      num_hard_examples=num_hard_examples,
      iou_threshold=config.iou_threshold,
      loss_type=loss_type,
      cls_loss_weight=classification_weight,
      loc_loss_weight=localization_weight,
      max_negatives_per_positive=max_negatives_per_positive,
      min_negatives_per_image=config.min_negatives_per_image)
  return hard_example_miner 
開發者ID:ringringyi,項目名稱:DOTA_models,代碼行數:39,代碼來源:losses_builder.py

示例2: build

# 需要導入模塊: from object_detection.protos import losses_pb2 [as 別名]
# 或者: from object_detection.protos.losses_pb2 import HardExampleMiner [as 別名]
def build(loss_config):
  """Build losses based on the config.

  Builds classification, localization losses and optionally a hard example miner
  based on the config.

  Args:
    loss_config: A losses_pb2.Loss object.

  Returns:
    classification_loss: Classification loss object.
    localization_loss: Localization loss object.
    classification_weight: Classification loss weight.
    localization_weight: Localization loss weight.
    hard_example_miner: Hard example miner object.

  Raises:
    ValueError: If hard_example_miner is used with sigmoid_focal_loss.
  """
  classification_loss = _build_classification_loss(
      loss_config.classification_loss)
  localization_loss = _build_localization_loss(
      loss_config.localization_loss)
  classification_weight = loss_config.classification_weight
  localization_weight = loss_config.localization_weight
  hard_example_miner = None
  if loss_config.HasField('hard_example_miner'):
    if (loss_config.classification_loss.WhichOneof('classification_loss') ==
        'weighted_sigmoid_focal'):
      raise ValueError('HardExampleMiner should not be used with sigmoid focal '
                       'loss')
    hard_example_miner = build_hard_example_miner(
        loss_config.hard_example_miner,
        classification_weight,
        localization_weight)
  return (classification_loss, localization_loss,
          classification_weight,
          localization_weight, hard_example_miner) 
開發者ID:cagbal,項目名稱:ros_people_object_detection_tensorflow,代碼行數:40,代碼來源:losses_builder.py


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