Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix convert_bbox_to_albumentations when x_max > rows #770

Conversation

iMeleon
Copy link

@iMeleon iMeleon commented Nov 30, 2020

convert_bbox_to_albumentations([0.53125, 0.551471, 0.9375, 0.736928] , 'yolo, 608, 608, check_validity=True) == ValueError: Expected x_max for bbox (0.06414473684210527, 0.18421052631578946, 1.0016447368421053, 0.9210526315789473, 0) to be in the range [0.0, 1.0], got 1.0016447368421053.
Happens because in "convert_bbox_to_albumentations" after x_max = int(x_min + width), x_max == 609, but rows == 608.
x_max = int(x_min + width) - 1 fix it.

convert_bbox_to_albumentations([0.53125, 0.551471, 0.9375, 0.736928] , 'yolo, 608, 608, check_validity=True) == ValueError: Expected x_max for bbox (0.06414473684210527, 0.18421052631578946, 1.0016447368421053, 0.9210526315789473, 0) to be in the range [0.0, 1.0], got 1.0016447368421053.
Happens because in "convert_bbox_to_albumentations" after x_max = int(x_min + width), x_max == 609, but rows == 608.
 x_max = int(x_min + width) - 1 fix it.
@iMeleon iMeleon changed the title fix convert_bbox_to_albumentations whenx_max > rows fix convert_bbox_to_albumentations when x_max > rows Nov 30, 2020
@Dipet
Copy link
Collaborator

Dipet commented Dec 2, 2020

Thank you for example when our code fails.
I think, that problem that some libraries adds to x_min and y_min 1 pixel, but another libraries don't do this.
I do not know how resolve this problem beautifully.
In my opinion this code will fix this problem:

x, y, width, height = denormalize_bbox(bbox, rows, cols)

x_min = x - width / 2 + 1
x_max = x_min + width
y_min = y - height / 2 + 1
y_max = y_min + height

if x_max > rows:
    x_max -= 1
    x_min -= 1
    y_max -= 1
    y_min -= 1

Also would be great if you will add this case to test in tests/test_bbox.py

@Dipet
Copy link
Collaborator

Dipet commented Jul 7, 2021

This problem was fixed by #924

@Dipet Dipet closed this Jul 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants