COCOEval 解析

 

    def evaluateImg(self, imgId, catId, aRng, maxDet):
        '''
        perform evaluation for single category and image
        :return: dict (single image results)
        '''
        p = self.params
        if p.useCats:
            gt = self._gts[imgId,catId]
            dt = self._dts[imgId,catId]                                              #加在对应的imgId和catId对应的信息
        else:
            gt = [_ for cId in p.catIds for _ in self._gts[imgId,cId]]
            dt = [_ for cId in p.catIds for _ in self._dts[imgId,cId]]
        #if(len(gt)==0):
        #    print 'hello'
        #    print gt
        #    pdb.set_trace()
        if len(gt) == 0 and len(dt) ==0:                                             #如果对应的gt和dt都没有,返回None
            return None
 
        for g in gt:
            if g['ignore'] or (g['area']<aRng[0] or g['area']>aRng[1]):              #设置gt中的每个标注是不是要ignore
                g['_ignore'] = 1
            else:
                g['_ignore'] = 0
 
        # sort dt highest score first, sort gt ignore last
        gtind = np.argsort([g['_ignore'] for g in gt], kind='mergesort')            #把gt中不忽略的放在前面,dt中分数高的放前面,gtind对应的也是索引!!!          
        gt = [gt[i] for i in gtind]                                                   
        dtind = np.argsort([-d['score'] for d in dt], kind='mergesort')             #dtind对应的是索引!!!!!!!!!!
        dt = [dt[i] for i in dtind[0:maxDet]]                                       #如果dt人数过多,只取前maxDets个
        iscrowd = [int(o['iscrowd']) for o in gt]                                   #加在iscrowd信息
        # load computed ious
        ious = self.ious[imgId, catId][:, gtind] if len(self.ious[imgId, catId]) > 0 else self.ious[imgId, catId]
        #把不需要ignore的gt的计算好的拿出来,最后的ious应该是(i,j1)的矩阵,j1是gt中不需要ignore的gt的总的数量
        T = len(p.iouThrs)                                                          #设置最后的阈值卡关
        G = len(gt)                                                                 #总的gt数量,包括要忽略的
        D = len(dt)                                                                 #总的dt数量
        gtm  = np.zeros((T,G))                                                      #设置gtm的大小是TXG
        dtm  = np.zeros((T,D))                                                      #设置Dtm的大小是TXD

        gtIg = np.array([g['_ignore'] for g in gt]) #把ignore的样本拿出来,此时的gt已经按照gt的ignore拍好了顺序的 
        dtIg = np.zeros((T,D)) #dtIg的大小是TxD # 
        if not len(ious)==0: #此时的ious仅仅是不忽略的那些gt对应的样本 
            for tind, t in enumerate(p.iouThrs): 
                for dind, d in enumerate(dt): 
                    # information about best match so far (m=-1 -> unmatched) 
                    iou = min([t,1-1e-10]) 
                    m = -1 
                    for gind, g in enumerate(gt): #在gt和dt之间进行遍历 
                        # if this gt already matched, and not a crowd, continue 
                        if gtm[tind,gind]>0 and not iscrowd[gind]: #不是人群并且已经做好了匹配的忽略掉 
                            continue 
                        # if dt matched to reg gt, and on ignore gt, stop 
                        if m>-1 and gtIg[m]==0 and gtIg[gind]==1: #什么时候跳出本次循环呢??等待已经匹配成功,m此时一定是正数,并且匹配的这个不是ignore,并且下一个就是ignore,这样才跳出循环,这样保证会一直寻找最优的配置 
                            break 
                        # continue to next gt unless better match made #此时重叠小于阈值iou,所以忽略继续 
                        if ious[dind,gind] < iou: 
                            continue 
                        # if match successful and best so far, store appropriately 
                        iou=ious[dind,gind] #此时表示匹配成功了,m存储的是匹配成功的gtind,但是还是会继续,将iou赋予新值,是为了找到更好的匹配者 
                        m=gind 
                    # if match made store id of match for both dt and gt 
                    if m ==-1: 
                        continue 
                    dtIg[tind,dind] = gtIg[m] #dind对应的那个gt是不是ignore 
                    dtm[tind,dind] = gt[m]['id'] #dind对应的gt的id是多少 
                    gtm[tind,m] = d['id'] #本次搜索dind对应的那个gt,存储那个gt所对应的dt的id,也就是本次的dind对应的id 
        # set unmatched detections outside of area range to ignore 
        a = np.array([d['area']<aRng[0] or d['area']>aRng[1] for d in dt]).reshape((1, len(dt))) 
        dtIg = np.logical_or(dtIg, np.logical_and(dtm==0, np.repeat(a,T,0))) 
        # store results for given image and category 
        return { 
                'image_id': imgId, 
                'category_id': catId, 
                'aRng': aRng, 
                'maxDet': maxDet, 
                'dtIds': [d['id'] for d in dt], 
                'gtIds': [g['id'] for g in gt], 
                'dtMatches': dtm, 
                'gtMatches': gtm, 
                'dtScores': [d['score'] for d in dt], 
                'gtIgnore': gtIg, 
                'dtIgnore': dtIg, }

 

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值