| 524 | |
| 525 | |
| 526 | class CustomCrop: |
| 527 | def __init__(self, crop_size,top_ratio, left_ratio): |
| 528 | self.top_ratio = top_ratio |
| 529 | self.left_ratio = left_ratio |
| 530 | self.crop_size = crop_size |
| 531 | |
| 532 | def __call__(self, tensor): |
| 533 | _, h, w = tensor.shape |
| 534 | |
| 535 | top_ratio = random.uniform(0.2,self.top_ratio) |
| 536 | left_ratio = random.uniform(0.3,0.7) |
| 537 | |
| 538 | crop_size = random.randint(self.crop_size,h) |
| 539 | |
| 540 | top = int((h-crop_size) * top_ratio) |
| 541 | left = int((w-crop_size) * left_ratio) |
| 542 | |
| 543 | tensor_cropped = F.crop(tensor, top, left, self.crop_size, self.crop_size) |
| 544 | |
| 545 | return tensor_cropped |
| 546 | |
| 547 | class HorizontalFlip(object): |
| 548 | def __call__(self, img): |