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
          recall_list = []
          avg_num_list = []
          for exp_id, ctx in self.ctxdb[split].items():
              exp_id = int(exp_id)
              if len(ctx['ctx']) == 0:
                  continue
              # Get proposals
              if image_as_key:
                  image_id = self.refer.sentToRef[exp_id]['image_id']
                  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]
              hit_num, ctx_num = 0, 0
              for ctx_item in ctx['ctx']:
                  ctx_num += 1
                  ctx_box = ctx_item['box']
                  for proposal in ranked_proposals:
                      if calculate_iou(ctx_box, proposal['box']) > self.threshold:
                          hit_num += 1
                          break
              recall_list.append(hit_num / ctx_num)
              avg_num_list.append(len(ranked_proposals))
          return sum(avg_num_list) / len(avg_num_list), sum(recall_list) / len(recall_list)
code_tokens: def eval_hit_rate ( self , split , proposal_dict , image_as_key = False ) : recall_list = [ ] avg_num_list = [ ] for exp_id , ctx in self . ctxdb [ split ] . items ( ) : exp_id = int ( exp_id ) if len ( ctx [ 'ctx' ] ) == 0 : continue if image_as_key : image_id = self . refer . sentToRef [ exp_id ] [ 'image_id' ] 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 ] hit_num , ctx_num = 0 , 0 for ctx_item in ctx [ 'ctx' ] : ctx_num += 1 ctx_box = ctx_item [ 'box' ] for proposal in ranked_proposals : if calculate_iou ( ctx_box , proposal [ 'box' ] ) > self . threshold : hit_num += 1 break recall_list . append ( hit_num / ctx_num ) avg_num_list . append ( len ( ranked_proposals ) ) return sum ( avg_num_list ) / len ( avg_num_list ) , sum ( recall_list ) / len ( recall_list )
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$# Get proposals$SEP$# Rank and select proposals