MCPcopy Create free account
hub / github.com/OpenDriveLab/OpenLane / computeOks

Method computeOks

eval/CIPO_evaluation/pycocotools/cocoeval.py:188–229  ·  view source on GitHub ↗
(self, imgId, catId)

Source from the content-addressed store, hash-verified

186 return ious
187
188 def computeOks(self, imgId, catId):
189 p = self.params
190 # dimention here should be Nxm
191 gts = self._gts[imgId, catId]
192 dts = self._dts[imgId, catId]
193 inds = np.argsort([-d['score'] for d in dts], kind='mergesort')
194 dts = [dts[i] for i in inds]
195 if len(dts) > p.maxDets[-1]:
196 dts = dts[0:p.maxDets[-1]]
197 # if len(gts) == 0 and len(dts) == 0:
198 if len(gts) == 0 or len(dts) == 0:
199 return []
200 ious = np.zeros((len(dts), len(gts)))
201 sigmas = p.kpt_oks_sigmas
202 vars = (sigmas * 2)**2
203 k = len(sigmas)
204 # compute oks between each detection and ground truth object
205 for j, gt in enumerate(gts):
206 # create bounds for ignore regions(double the gt bbox)
207 g = np.array(gt['keypoints'])
208 xg = g[0::3]; yg = g[1::3]; vg = g[2::3]
209 k1 = np.count_nonzero(vg > 0)
210 bb = gt['bbox']
211 x0 = bb[0] - bb[2]; x1 = bb[0] + bb[2] * 2
212 y0 = bb[1] - bb[3]; y1 = bb[1] + bb[3] * 2
213 for i, dt in enumerate(dts):
214 d = np.array(dt['keypoints'])
215 xd = d[0::3]; yd = d[1::3]
216 if k1>0:
217 # measure the per-keypoint distance if keypoints visible
218 dx = xd - xg
219 dy = yd - yg
220 else:
221 # measure minimum distance to keypoints in (x0,y0) & (x1,y1)
222 z = np.zeros((k))
223 dx = np.max((z, x0-xd),axis=0)+np.max((z, xd-x1),axis=0)
224 dy = np.max((z, y0-yd),axis=0)+np.max((z, yd-y1),axis=0)
225 e = (dx**2 + dy**2) / vars / (gt['area']+np.spacing(1)) / 2
226 if k1 > 0:
227 e=e[vg > 0]
228 ious[i, j] = np.sum(np.exp(-e)) / e.shape[0]
229 return ious
230
231 def evaluateImg(self, imgId, aRng, maxDet):
232 '''

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected