original_docstring: Evaluate refexp-based hit rate.
  
          Args:
              proposal_dict: {exp_id or image_id: [{box: [4,], score: float}]}.
              image_as_key: Use image_id instead of exp_id as key, default `False`.
  
          Returns:
              proposal_per_ref: Number of proposals per refexp.
              hit_rate: Refexp-based hit rate of proposals.
  
          
docstring: Evaluate refexp-based hit rate.
docstring_tokens: Evaluate refexp - based hit rate .
code: def eval_hit_rate(self, split, proposal_dict, image_as_key=False):
          """Evaluate refexp-based hit rate.
  
          Args:
              proposal_dict: {exp_id or image_id: [{box: [4,], score: float}]}.
              image_as_key: Use image_id instead of exp_id as key, default `False`.
  
          Returns:
              proposal_per_ref: Number of proposals per refexp.
              hit_rate: Refexp-based hit rate of proposals.
  
          """
          # Initialize counters
          num_hit = 0
          num_proposal = 0
          num_ref = 0  # NOTE: this is the number of refexp, not ref
          for ref_id in self.refer.getRefIds(split=split):
              ref = self.refer.Refs[ref_id]
              image_id = ref['image_id']
              ann_id = ref['ann_id']
              ann = self.refer.Anns[ann_id]
              gt_box = xywh_to_xyxy(ann['bbox'])
              for exp_id in ref['sent_ids']:
                  # Get proposals
                  if image_as_key:
                      proposals = proposal_dict[image_id]
                  else:
                      proposals = proposal_dict[exp_id]
                  # Rank and select proposals
                  ranked_proposals = sorted(proposals, key=lambda p: p['score'], reverse=True)[:self.top_N]
                  for proposal in ranked_proposals:
                      if calculate_iou(gt_box, proposal['box']) > self.threshold:
                          num_hit += 1
                          break
                  num_proposal += len(ranked_proposals)
                  num_ref += 1
          proposal_per_ref = num_proposal / num_ref
          hit_rate = num_hit / num_ref
          return proposal_per_ref, hit_rate
code_tokens: def eval_hit_rate ( self , split , proposal_dict , image_as_key = False ) : num_hit = 0 num_proposal = 0 num_ref = 0 for ref_id in self . refer . getRefIds ( split = split ) : ref = self . refer . Refs [ ref_id ] image_id = ref [ 'image_id' ] ann_id = ref [ 'ann_id' ] ann = self . refer . Anns [ ann_id ] gt_box = xywh_to_xyxy ( ann [ 'bbox' ] ) for exp_id in ref [ 'sent_ids' ] : if image_as_key : proposals = proposal_dict [ image_id ] else : proposals = proposal_dict [ exp_id ] ranked_proposals = sorted ( proposals , key = lambda p : p [ 'score' ] , reverse = True ) [ : self . top_N ] for proposal in ranked_proposals : if calculate_iou ( gt_box , proposal [ 'box' ] ) > self . threshold : num_hit += 1 break num_proposal += len ( ranked_proposals ) num_ref += 1 proposal_per_ref = num_proposal / num_ref hit_rate = num_hit / num_ref return proposal_per_ref , hit_rate
short_docstring: Evaluate refexp-based hit rate.
short_docstring_tokens: Evaluate refexp - based hit rate .
comment: """Evaluate refexp-based hit rate.
  
          Args:
              proposal_dict: {exp_id or image_id: [{box: [4,], score: float}]}.
              image_as_key: Use image_id instead of exp_id as key, default `False`.
  
          Returns:
              proposal_per_ref: Number of proposals per refexp.
              hit_rate: Refexp-based hit rate of proposals.
  
          """$SEP$# Initialize counters$SEP$# NOTE: this is the number of refexp, not ref$SEP$# Get proposals$SEP$# Rank and select proposals