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.

ValueError: Requested crop size is larger than the image size in RandomResizedCrop

See original GitHub issue

🐛 Bug

ValueError: Requested crop size is larger than the image size when including RandomResizedCrop in my transforms pipeline:

ValueError: Caught ValueError in DataLoader worker process 1.
Original Traceback (most recent call last):
  File "/opt/conda/lib/python3.8/site-packages/torch/utils/data/_utils/worker.py", line 202, in _worker_loop
    data = fetcher.fetch(index)
  File "/opt/conda/lib/python3.8/site-packages/torch/utils/data/_utils/fetch.py", line 44, in fetch
    data = [self.dataset[idx] for idx in possibly_batched_index]
  File "/opt/conda/lib/python3.8/site-packages/torch/utils/data/_utils/fetch.py", line 44, in <listcomp>
    data = [self.dataset[idx] for idx in possibly_batched_index]
  File "/workspace/ai_damages/parts/src/data_loading.py", line 64, in __getitem__
    transformed = self.transforms(image=img, mask=mask)
  File "/opt/conda/lib/python3.8/site-packages/albumentations/core/composition.py", line 182, in __call__
    data = t(force_apply=force_apply, **data)
  File "/opt/conda/lib/python3.8/site-packages/albumentations/core/transforms_interface.py", line 89, in __call__
    return self.apply_with_params(params, **kwargs)
  File "/opt/conda/lib/python3.8/site-packages/albumentations/core/transforms_interface.py", line 102, in apply_with_params
    res[key] = target_function(arg, **dict(params, **target_dependencies))
  File "/opt/conda/lib/python3.8/site-packages/albumentations/core/transforms_interface.py", line 227, in apply_to_mask
    return self.apply(img, **{k: cv2.INTER_NEAREST if k == "interpolation" else v for k, v in params.items()})
  File "/opt/conda/lib/python3.8/site-packages/albumentations/augmentations/transforms.py", line 857, in apply
    crop = F.random_crop(img, crop_height, crop_width, h_start, w_start)
  File "/opt/conda/lib/python3.8/site-packages/albumentations/augmentations/functional.py", line 331, in random_crop
    raise ValueError(
ValueError: Requested crop size (2131, 1636) is larger than the image size (1836, 3264)

To Reproduce

I can’t reproduce it deterministically, it just happens sometimes.

Environment

  • Docker Image: pytorch/pytorch:1.8.1-cuda11.1-cudnn8-runtime
  • Albumentations version: 0.5.2 (by pip)

Additional Context

Instantiated as: A.RandomResizedCrop(img_size, img_size, scale=(0.20, 1.))

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:10

github_iconTop GitHub Comments

2reactions
Dipetcommented, Oct 18, 2022

Now we check that image and mask shapes are equal. More info in #1310

0reactions
lucmoscommented, Oct 17, 2022

@claverru Thanks! I hit almost exactly the same problem 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

ValueError: Requested crop size (64, 64) is larger than the ...
ValueError : Caught ValueError in DataLoader worker process 2. ... ValueError: Requested crop size (64, 64) is larger than the image size (48 ......
Read more >
Crop transforms (augmentations.crops.transforms)
Crop and pad images by pixel amounts or fractions of image sizes. Cropping removes pixels at the sides (i.e. extracts a subimage from...
Read more >
Torch vision cropping behavior when crop region larger than ...
If an image is smaller than the specified crop region, ... in get_params raise ValueError( ValueError: Required crop size (50, 50) is larger...
Read more >
Source code for torchvision.transforms - chsasank.com
Args: tensor (Tensor): Tensor image of size (C, H, W) to be normalized. mean ... h: raise ValueError("Requested crop size {} is bigger...
Read more >
Source code for mmaction.datasets.pipelines.augmentations
Fusion order: crop -> resize -> flip Required keys are "imgs", ... supports more than " '2 image scales') scale = random.choice(scales) return...
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