def analyze()

in easycv/core/evaluation/custom_cocotools/cocoeval.py [0:0]


    def analyze(self):
        '''
        Analyze errors
        '''
        prm = copy.deepcopy(self.params)
        self.params.maxDets = [100]
        catIds = sorted(self.cocoGt.getCatIds())
        self.params.catIds = catIds
        self.params.iouThrs = np.array([0.75, 0.5, 0.1])
        self.evaluate()
        self.accumulate()
        ps = self.eval['precision']

        class Type(object):
            C75 = 0
            C50 = 1
            Loc = 2
            Sim = 3
            Other = 4
            BG = 5
            FN = 6

        # 0 for C75
        # 1 for C50
        # 2 for Loc
        # 3 for Sim
        # 4 for Other
        # 5 for BG
        # 5 for FN
        ps = np.concatenate((ps, np.zeros([4] + list(ps.shape[1:]))))

        self.params.iouThrs = np.array([0.1])
        self.params.useCats = 0

        dt = self.cocoDt
        gt = self.cocoGt
        self.analyze_figures = {}
        for k, catId in enumerate(catIds):
            nm = self.cocoGt.loadCats(catId)[0]
            if 'supercategory' in nm:
                nm = nm['supercategory'] + '-' + nm['name']
            else:
                nm = nm['name']
            logging.info('Analyzing %s (%d):' % (nm, k))
            start_time = time.time()

            # select detections for single category only
            self.params.keepDtCatIds = [catId]

            # compute precision but ignore superclass confusion
            cur_cat = gt.loadCats(catId)[0]
            if 'supercategory' in cur_cat:
                similar_cat_ids = gt.getCatIds(supNms=cur_cat['supercategory'])
                self.params.keepGtCatIds = similar_cat_ids
                self.params.targetCatId = catId

                # computeIoU need real catIds, we need to recover it
                self.params.catIds = catIds
                self.evaluate()
                self.accumulate()
                ps[Type.Sim, :, k, :, :] = self.eval['precision'][0, :,
                                                                  0, :, :]
            else:
                # skip  superclass confusion evaluation
                ps[Type.Sim, :, k, :, :] = ps[2, :, k, :, :]

            # compute precision but ignore any class confusion
            self.params.targetCatId = catId
            self.params.keepGtCatIds = catIds
            self.params.catIds = catIds
            self.evaluate()
            self.accumulate()
            ps[Type.Other, :, k, :, :] = self.eval['precision'][0, :, 0, :, :]

            # fill in background and false negative errors and plot
            ps[ps == -1] = 0
            ps[Type.BG, :, k, :] = (ps[4, :, k, :] > 0).astype(np.float32)
            ps[Type.FN, :, k, :] = 1
            end_time = time.time()

            # test
            # dst_dir = 'py_precision'
            # if not os.path.exists(dst_dir):
            #     os.makedirs(dst_dir)
            # result_file = '%s/class_%d' % (dst_dir, k)
            # np.save(result_file, ps)

            figures = self.makeplot(
                self.params.recThrs,
                ps[:, :, k, :, :],
                nm,
                save_dir=self.params.outDir)
            self.analyze_figures.update(figures)
            logging.info('Analyzing DONE (t=%0.2fs).' %
                         (end_time - start_time))

        # reset Dt and Gt, params
        self.params = prm
        figures = self.makeplot(
            self.params.recThrs,
            np.mean(ps, axis=2),
            'overall-all',
            save_dir=self.params.outDir)
        self.analyze_figures.update(figures)
        if 'supercategory' in self.cocoGt.cats.values()[0]:
            sup = [
                cat['supercategory'] for cat in self.cocoGt.loadCats(catIds)
            ]
            logging.info('all sup cats: %s' % (set(sup)))
            for k in set(sup):
                ps1 = np.mean(ps[:, :, np.array(sup) == k, :, :], axis=2)
                figures = self.makeplot(
                    self.params.recThrs,
                    ps1,
                    'overall-%s' % k,
                    save_dir=self.params.outDir)
                self.analyze_figures.update(figures)