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.

Random Crop yields incorrect value for bounding box

See original GitHub issue

🐛 Bug

The bbox_random_crop function does not produce a reasonable result. Consider the following snippet of code.

To Reproduce

from albumentations import functional as F
bbox = (0.129, 0.7846, 0.1626, 0.818)
cropped_bbox = F.bbox_random_crop(bbox=bbox, crop_height=100, crop_width=100, h_start=0.7846, w_start=0.12933, rows=1500, cols=1500)
cropped_bbox
(0.125, 0.788999, 0.629, 1.29)
#Notice y2 is outside of crop range.
#But the following assert passes
assert bbox[3] < (100/1500) + 0.7846
#Fails
assert all([(y >= 0) & (y<=1) for y in list(cropped_bbox)])

Expected behavior

A augmented bbox that is fully within the image crop. The crop_height plus the start of the crop is larger than the y2 of the bounding box, but 1.29 coordinate in the cropped box suggestion it is outside of the crop area.

Environment

  • Albumentations version (e.g., 0.1.8): 0.5.2
  • Python version (e.g., 3.7): 3.7
  • OS (e.g., Linux): OSX
  • How you installed albumentations (conda, pip, source): pip
  • Any other relevant information:

Additional context

I am making a custom augmentation to Zoom in on a given bounding box. CropSafe (but not all boxes). Is there syntax that i’m misunderstanding, it doesn’t feel like this could be the case. Dtype issue?

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
Dimfredcommented, May 27, 2021

So I fixed the errors for me by changing the conversion in bbox_utils for the yolo case. Since yolo comes in already relative a conversion to absolute format and then back to relative will yield errors.

So instead of convertig to absolute I removed it and now with the coordinates I get from yolo

x, y, w, h = yolo_bbox

w_half, h_half = w / 2, h / 2
x_min, x_max = x - w_half, x + w_half
y_min, y_max = y - h_half, y + h_half

and vice versa in the from_albumentation case.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Bounding Box Augmentation for Object Detection using ...
In this post, we explore bounding box augmentation for object detection task in deep learning using the Albumentations library.
Read more >
Why and How to Implement Random Crop Data Augmentation
If we're cropping images that contain bounding boxes, what area of a bounding box must be present in the resulting image for the...
Read more >
Bounding boxes augmentation for object detection
Coordinates of a bounding box are encoded with four values in pixels: [x_min, y_min, x_max, ... transform = A.Compose([ A.RandomCrop(width=450, height=450), ...
Read more >
Rethinking the Random Cropping Data Augmentation Method ...
In addition, random cropping can also greatly enhance the spatial robustness ... inaccurate target bounding box regression results and false alarm targets.
Read more >
Incorrect bounding boxes cropped - python - Stack Overflow
PIL's crop() function doesn't take the arguments you gave it. you should use it like (left, top, right, bottom) which in your case...
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