About RandomSizedCrop implementation
See original GitHub issueWhen using RandomSizedCrop(), is it better to use padding if a suggested crop region is bigger than the original image size, rather than raise ValueError? For example, the augmentation method used for achieving cityscapes good result uses padding. https://github.com/PkuRainBow/OCNet/blob/8184d9d55ec474c7e22278256f1db8b3d7ebce88/dataset/cityscapes.py#L121
So I suggest changing this part; https://github.com/albu/albumentations/blob/8626026910d6b0236bccd09af276ca9432af5d22/albumentations/augmentations/functional.py#L207-L221
to
def random_crop(img, crop_height, crop_width, h_start, w_start, pad_value=(0.0,)):
height, width = img.shape[:2]
if height < crop_height or width < crop_width:
pad_h = max(crop_height - height, 0)
pad_w = max(crop_width - width, 0)
img = cv2.copyMakeBorder(img, 0, pad_h, 0,
pad_w, cv2.BORDER_CONSTANT,
value=pad_value) # if gt label, pad_value should be ignore index.
x1, y1, x2, y2 = get_random_crop_coords(height, width, crop_height, crop_width, h_start, w_start)
img = img[y1:y2, x1:x2]
return img
Issue Analytics
- State:
- Created 5 years ago
- Reactions:4
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Random Sized Crop - Hasty.ai
To define the term, Random Sized Crop is a data augmentation technique that helps researchers to crop an image to any size within...
Read more >How to use the albumentations.RandomSizedCrop function in ...
To help you get started, we've selected a few albumentations.RandomSizedCrop examples, based on popular ways it is used in public projects.
Read more >Why and How to Implement Random Crop Data Augmentation
A user may hold their phone at varying distances from the objects we seek to recognize, and those objects are not always completely...
Read more >RandomResizedCrop — Torchvision main documentation
Get parameters for crop for a random sized crop. Parameters: img (PIL Image or Tensor) – Input image. scale (list) – range of...
Read more >Crop transforms (augmentations.crops.transforms)
class albumentations.augmentations.crops.transforms.RandomSizedCrop (min_max_height, height, width, w2h_ratio=1.0, interpolation=1, always_apply=False, ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Any updates on this ?
Looks good, I will add it, thanks