MCPcopy
hub / github.com/dbolya/yolact / __call__

Method __call__

utils/augmentations.py:305–405  ·  view source on GitHub ↗
(self, image, masks, boxes=None, labels=None)

Source from the content-addressed store, hash-verified

303 )
304
305 def __call__(self, image, masks, boxes=None, labels=None):
306 height, width, _ = image.shape
307 while True:
308 # randomly choose a mode
309 mode = random.choice(self.sample_options)
310 if mode is None:
311 return image, masks, boxes, labels
312
313 min_iou, max_iou = mode
314 if min_iou is None:
315 min_iou = float('-inf')
316 if max_iou is None:
317 max_iou = float('inf')
318
319 # max trails (50)
320 for _ in range(50):
321 current_image = image
322
323 w = random.uniform(0.3 * width, width)
324 h = random.uniform(0.3 * height, height)
325
326 # aspect ratio constraint b/t .5 & 2
327 if h / w < 0.5 or h / w > 2:
328 continue
329
330 left = random.uniform(width - w)
331 top = random.uniform(height - h)
332
333 # convert to integer rect x1,y1,x2,y2
334 rect = np.array([int(left), int(top), int(left+w), int(top+h)])
335
336 # calculate IoU (jaccard overlap) b/t the cropped and gt boxes
337 overlap = jaccard_numpy(boxes, rect)
338
339 # This piece of code is bugged and does nothing:
340 # https://github.com/amdegroot/ssd.pytorch/issues/68
341 #
342 # However, when I fixed it with overlap.max() < min_iou,
343 # it cut the mAP in half (after 8k iterations). So it stays.
344 #
345 # is min and max overlap constraint satisfied? if not try again
346 if overlap.min() < min_iou and max_iou < overlap.max():
347 continue
348
349 # cut the crop from the image
350 current_image = current_image[rect[1]:rect[3], rect[0]:rect[2],
351 :]
352
353 # keep overlap with gt box IF center in sampled patch
354 centers = (boxes[:, :2] + boxes[:, 2:]) / 2.0
355
356 # mask in all gt boxes that above and to the left of centers
357 m1 = (rect[0] < centers[:, 0]) * (rect[1] < centers[:, 1])
358
359 # mask in all gt boxes that under and to the right of centers
360 m2 = (rect[2] > centers[:, 0]) * (rect[3] > centers[:, 1])
361
362 # mask in that both m1 and m2 are true

Callers

nothing calls this directly

Calls 2

copyMethod · 0.80
jaccard_numpyFunction · 0.70

Tested by

no test coverage detected