(image, target)
| 57 | |
| 58 | |
| 59 | def hflip(image, target): |
| 60 | flipped_image = F.hflip(image) |
| 61 | |
| 62 | w, h = image.size |
| 63 | |
| 64 | target = target.copy() |
| 65 | if "boxes" in target: |
| 66 | boxes = target["boxes"] |
| 67 | boxes = boxes[:, [2, 1, 0, 3]] * torch.as_tensor([-1, 1, -1, 1]) + torch.as_tensor([w, 0, w, 0]) |
| 68 | target["boxes"] = boxes |
| 69 | |
| 70 | if "masks" in target: |
| 71 | target['masks'] = target['masks'].flip(-1) |
| 72 | |
| 73 | return flipped_image, target |
| 74 | |
| 75 | |
| 76 | def resize(image, target, size, max_size=None): |