coco pythonapi matlabapi评估代码部分解析

cocoEval = COCOeval(cocoGt,cocoDt,annType)
cocoEval.params.imgIds  = imgIds
cocoEval.evaluate()
cocoEval.accumulate()
cocoEval.summarize()

主要有evaluate(),accumulate(),summarize()三个函数,一个COCOeval类,需要传入真值、检测结果、标注类型(bbox,segm)
ref
https://blog.csdn.net/u013548568/article/details/79133151

    def evaluate(self):
        '''
        Run per image evaluation on given images and store results (a list of dict) in self.evalImgs
        :return: None
        '''
        tic = time.time()
        print('Running per image evaluation...')
        p = self.params

        # add backward compatibility if useSegm is specified in params
        if not p.useSegm is None:
            #pdb.set_trace()
            p.iouType = 'segm' if p.useSegm == 1 else 'bbox'
            print('useSegm (deprecated) is not None. Running {} evaluation'.format(p.iouType))
        print('Evaluate annotation type *{}*'.format(p.iouType))
        p.imgIds = list(np.unique(p.imgIds))

        if p.useCats:
            p.catIds = list(np.unique(p.catIds))
        p.maxDets = sorted(p.maxDets)
        self.params=p

        self._prepare()
        # loop through images, area range, max detection number
        catIds = p.catIds if p.useCats else [-1]

        if p.iouType == 'segm' or p.iouType == 'bbox':
            computeIoU = self.computeIoU
        elif p.iouType == 'keypoints':
            computeIoU = self.computeOks
        self.ious = {(imgId, catId): computeIoU(imgId, catId) \     #存储的是x张验证集的结果,每个ious是一个(i x j)的矩阵,i是dt的数量,j是gt的数量
                        for imgId in p.imgIds
                        for catId in catIds}

        evaluateImg = self.evaluateImg
        maxDet = p.maxDets[-1]

        self.evalImgs = [evaluateImg(imgId, catId, areaRng, maxDet) #存储的是15000个结果,在不同的尺度上的结果呢  
                 for catId in catIds                                #只有一个人的分类
                 for areaRng in p.areaRng                           #3中区域面积来进行衡量
                 for imgId in p.imgIds                              #5000张验证集图片
             ]

        pdb.set_trace()
        self._paramsEval = copy.deepcopy(self.params)
        toc = time.time()
        print('DONE (t={:0.2f}s).'.format(toc-tic))

对ious computeIoU结果

    def computeIoU(self, imgId, catId):
        p = self.params
        if p.useCats:
            gt = self._gts[imgId,catId]
            dt = self._dts[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 and len(dt) ==0:
            return []
        inds = np.argsort([-d['score'] for d in dt], kind='mergesort')
        dt = [dt[i] for i in inds]
        if len(dt) > p.maxDets[-1]:
            dt=dt[0:p.maxDets[-1]]

        if p.iouType == 'segm':
            g = [g['segmentation'] for g in gt]
            d = [d['segmentation'] for d in dt]
        elif p.iouType == 'bbox':
            g = [g['bbox'] for g in gt]
            d = [d['bbox'] for d in dt]
        else:
            raise Exception('unknown iouType for iou computation')

        # compute iou between each dt and gt region
        iscrowd = [int(o['iscrowd']) for o in gt]
        ious = maskUtils.iou(d,g,iscrowd)
        return ious

存储的是验证集的结果,
如此处是对应24张验证图片4类目标的结果矩阵。共(24 x 4)个矩阵
每个ious是一个(i x j)的矩阵,i是dt的数量,j是gt的数量

......
(5, 2): array([[0.99217781]]),
 (5, 3): array([[0.99356801]]), 
 (5, 4): [], 
 (6, 1): array([[0.99124279, 0.        , 0.        ],
       [0.        , 0.98668661, 0.        ],
       [0.        , 0.        , 0.99156911]]),
 (6, 2): array([[0.98359889]]),
 (6, 3): array([[0.99262209]]),
 ......
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值