Crop the given images to random size and aspect ratio. A crop of random size (default: of 0.08 to 1.0) of the original size and a random aspect ratio (default: of 3/4 to 4/3) of the original aspect ratio is made. This crop is finally resized to given size. This is popularly used to
(
images,
target_height,
target_width,
scale=(0.8, 1.0),
ratio=(3.0 / 4.0, 4.0 / 3.0),
)
| 575 | |
| 576 | |
| 577 | def random_resized_crop( |
| 578 | images, |
| 579 | target_height, |
| 580 | target_width, |
| 581 | scale=(0.8, 1.0), |
| 582 | ratio=(3.0 / 4.0, 4.0 / 3.0), |
| 583 | ): |
| 584 | """ |
| 585 | Crop the given images to random size and aspect ratio. A crop of random |
| 586 | size (default: of 0.08 to 1.0) of the original size and a random aspect |
| 587 | ratio (default: of 3/4 to 4/3) of the original aspect ratio is made. This |
| 588 | crop is finally resized to given size. This is popularly used to train the |
| 589 | Inception networks. |
| 590 | |
| 591 | Args: |
| 592 | images: Images to perform resizing and cropping. |
| 593 | target_height: Desired height after cropping. |
| 594 | target_width: Desired width after cropping. |
| 595 | scale: Scale range of Inception-style area based random resizing. |
| 596 | ratio: Aspect ratio range of Inception-style area based random resizing. |
| 597 | """ |
| 598 | |
| 599 | height = images.shape[2] |
| 600 | width = images.shape[3] |
| 601 | |
| 602 | i, j, h, w = _get_param_spatial_crop(scale, ratio, height, width) |
| 603 | cropped = images[:, :, i : i + h, j : j + w] |
| 604 | return torch.nn.functional.interpolate( |
| 605 | cropped, |
| 606 | size=(target_height, target_width), |
| 607 | mode="bilinear", |
| 608 | align_corners=False, |
| 609 | ) |
| 610 | |
| 611 | |
| 612 | def random_resized_crop_with_shift( |
nothing calls this directly
no test coverage detected