in challenge/2019_COCO_DensePose/densepose_cocoeval.py [0:0]
def computeOgpsDraft(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(g), len(d)))
# 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)
#print('== Ground truths:', len(g), g[0].keys(), g[0]['track_id'], g[0]['image_id'])
#print('== Detections:', len(d))
entry = {}
entry['trackidxGT'] = []
entry['trackidxPr'] = []
entry['dist'] = []
for j, gt in enumerate(g):
entry['trackidxGT'].append(gt['track_id'])
for i, dt in enumerate(d):
entry['trackidxPr'].append(dt['track'])
for j, gt in enumerate(g):
#entry['dist'].append([])
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.
#entry['dist'][-1].append([])
elif np.max(pts) == -1:
#entry['dist'][-1].append([])
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)
dist[~np.isfinite(dist)]=0
#entry['dist'][-1].append(dist)
## 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[j, i] = ogps
#print(len(g), len(d), entry['trackidxGT'], entry['trackidxPr'])
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, entry