(image, target)
| 217 | |
| 218 | |
| 219 | def hflip(image, target): |
| 220 | flipped_image = F.hflip(image) |
| 221 | |
| 222 | w, h = image.size |
| 223 | |
| 224 | target = target.copy() |
| 225 | if "boxes" in target: |
| 226 | boxes = target["boxes"] |
| 227 | boxes = boxes[:, [2, 1, 0, 3]] * torch.as_tensor([-1, 1, -1, 1]) + torch.as_tensor([w, 0, w, 0]) |
| 228 | target["boxes"] = boxes |
| 229 | |
| 230 | if "masks" in target: |
| 231 | target['masks'] = target['masks'].flip(-1) |
| 232 | |
| 233 | return flipped_image, target |
| 234 | |
| 235 | |
| 236 | def resize(image, target, size, max_size=None): |