question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

About RandomSizedCrop implementation

See original GitHub issue

When 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:closed
  • Created 5 years ago
  • Reactions:4
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
vfdev-5commented, Mar 9, 2019

Any updates on this ?

1reaction
albucommented, Dec 7, 2018

Looks good, I will add it, thanks

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found