def computeOgps()

in detectron/datasets/densepose_cocoeval.py [0:0]


    def computeOgps(self, imgId, catId):
        p = self.params
        # dimention here should be Nxm
        g = self._gts[imgId, catId]
        d = self._dts[imgId, catId]
        inds = np.argsort([-d_['score'] for d_ in d], kind='mergesort')
        d = [d[i] for i in inds]
        if len(d) > p.maxDets[-1]:
            d = d[0:p.maxDets[-1]]
        # if len(gts) == 0 and len(dts) == 0:
        if len(g) == 0 or len(d) == 0:
            return []
        ious = np.zeros((len(d), len(g)))
        # compute opgs between each detection and ground truth object
        sigma = self.sigma #0.255 # dist = 0.3m corresponds to ogps = 0.5
        # 1 # dist = 0.3m corresponds to ogps = 0.96
        # 1.45 # dist = 1.7m (person height) corresponds to ogps = 0.5)
        for j, gt in enumerate(g):
            if not gt['ignore']:
                g_ = gt['bbox']
                for i, dt in enumerate(d):
                    #
                    dx = dt['bbox'][3]
                    dy = dt['bbox'][2]
                    dp_x = np.array( gt['dp_x'] )*g_[2]/255.
                    dp_y = np.array( gt['dp_y'] )*g_[3]/255.
                    px = ( dp_y + g_[1] - dt['bbox'][1]).astype(np.int)
                    py = ( dp_x + g_[0] - dt['bbox'][0]).astype(np.int)
                    #
                    pts = np.zeros(len(px))
                    pts[px>=dx] = -1; pts[py>=dy] = -1
                    pts[px<0] = -1; pts[py<0] = -1
                    #print(pts.shape)
                    if len(pts) < 1:
                        ogps = 0.
                    elif np.max(pts) == -1:
                        ogps = 0.
                    else:
                        px[pts==-1] = 0; py[pts==-1] = 0;
                        ipoints = dt['uv'][0, px, py]
                        upoints = dt['uv'][1, px, py]/255. # convert from uint8 by /255.
                        vpoints = dt['uv'][2, px, py]/255.
                        ipoints[pts==-1] = 0
                        ## Find closest vertices in subsampled mesh.
                        cVerts, cVertsGT = self.findAllClosestVerts(gt, upoints, vpoints, ipoints)
                        ## Get pairwise geodesic distances between gt and estimated mesh points.
                        dist = self.getDistances(cVertsGT, cVerts)
                        ## Compute the Ogps measure.
                        # Find the mean geodesic normalization distance for each GT point, based on which part it is on.
                        Current_Mean_Distances  = self.Mean_Distances[ self.CoarseParts[ self.Part_ids [ cVertsGT[cVertsGT>0].astype(int)-1] ]  ]
                        # Compute gps
                        ogps_values = np.exp(-(dist**2)/(2*(Current_Mean_Distances**2)))
                        #
                        if len(dist)>0:
                            ogps = np.sum(ogps_values)/ len(dist)
                    ious[i, j] = ogps

        gbb = [gt['bbox'] for gt in g]
        dbb = [dt['bbox'] for dt in d]

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