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:
- Created 2 years ago
- Comments:14
Top 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 >
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
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
and vice versa in the
from_albumentation
case.@veve90 https://github.com/albumentations-team/albumentations/pull/924/commits/bae5414239c50f04e50736768e027f02e61f053c#diff-78866cc64c23c9e242bdcb84933e35a5218dda5b971f3f3d9f8348d5af855cd0R233