(self, imgs: list, targets: list)
| 375 | self.padding = padding |
| 376 | |
| 377 | def __call__(self, imgs: list, targets: list): |
| 378 | ret_imgs = [] |
| 379 | ret_targets = [] |
| 380 | |
| 381 | n_frames = len(imgs) |
| 382 | w, h = imgs[0].size |
| 383 | xshift = (self.padding * torch.rand(self.bs)).int() + 1 |
| 384 | xshift *= (torch.randn(self.bs) > 0.0).int() * 2 - 1 |
| 385 | yshift = (self.padding * torch.rand(self.bs)).int() + 1 |
| 386 | yshift *= (torch.randn(self.bs) > 0.0).int() * 2 - 1 |
| 387 | ret_imgs.append(imgs[0]) |
| 388 | ret_targets.append(targets[0]) |
| 389 | for i in range(1, n_frames): |
| 390 | ymin = max(0, -yshift[0]) |
| 391 | ymax = min(h, h - yshift[0]) |
| 392 | xmin = max(0, -xshift[0]) |
| 393 | xmax = min(w, w - xshift[0]) |
| 394 | prev_img = ret_imgs[i-1].copy() |
| 395 | prev_target = copy.deepcopy(ret_targets[i-1]) |
| 396 | region = (int(ymin), int(xmin), int(ymax - ymin), int(xmax - xmin)) |
| 397 | img_i, target_i = random_shift(prev_img, prev_target, region, (h, w)) |
| 398 | ret_imgs.append(img_i) |
| 399 | ret_targets.append(target_i) |
| 400 | |
| 401 | return ret_imgs, ret_targets |
| 402 | |
| 403 | |
| 404 | class RandomSizeCrop(object): |
nothing calls this directly
no test coverage detected