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: Expected x_min for bbox (-0.02666666666666667, 0.3022222222222222, 0.10666666666666667, 0.48444444444444446, tensor(1)) to be in the range [0.0, 1.0], got -0.02666666666666667.

See original GitHub issue

🐛 Bug

To Reproduce

Steps to reproduce the behavior:

Expected behavior

Environment

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

Additional context

I’m getting ValueError: Expected x_min for bbox (-0.02666666666666667, 0.3022222222222222, 0.10666666666666667, 0.48444444444444446, tensor(1)) to be in the range [0.0, 1.0], got -0.02666666666666667. message

my original box is

new_boxes->[[442. 79. 972. 564.]]

its x_min, y_min, x_max, y_max format then it only give this error message when


        if random.random() < 0.2:
            print('horizontalFlip')
            print(f'new_boxes->{new_boxes}')
            augment = albumentations.HorizontalFlip(p=0.5)
            aug = albumentations.Compose([augment],bbox_params={'format': 'pascal_voc', 'label_fields': ['labels']})
            aug_result = aug(image=np.array(new_image), bboxes=new_boxes, labels=labels)
            new_image = aug_result['image']
            new_boxes = aug_result['bboxes']
            new_image = FT.to_pil_image(new_image)

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

7reactions
marcocaccincommented, Aug 28, 2020

This unfortunately is regularly happening for me as well. Here’s my env along with a reproducible script.

It seems to me that all of these errors seem to deal with numerical errors when doing geometric operations on totally legit bounding boxes right at the image boundary. One way to deal with the issue would be to allow an “unsafe” transformation by letting the user control the check_validity flag from BBoxParams and deal with truncations manually afterwards: that’s still a better option than having a training job fail because of uncontrollable exceptions.

CC: @BeckerFelix

Environment

  • Albumentations version: 0.4.6, 0.3.3
  • Python version: 3.6.12
  • OS (e.g., Linux): ubuntu 20.04
  • How you installed albumentations (conda, pip, source): pip
import numpy as np
import albumentations as A

np.random.seed(123)
HEIGHT, WIDTH = 720, 1280

def random_bbox():
    x1 = np.random.randint(low=0, high=WIDTH)
    y1 = np.random.randint(low=0, high=HEIGHT)
    x2 = np.random.randint(low=x1 + 1, high=WIDTH + 1)
    y2 = np.random.randint(low=y1 + 1, high=HEIGHT + 1)
    bbox_albu = A.convert_bbox_to_albumentations([x1, y1, x2, y2], source_format='pascal_voc', rows=HEIGHT, cols=WIDTH)
    bbox_yolo = A.convert_bbox_from_albumentations(bbox_albu, target_format='yolo', rows=HEIGHT, cols=WIDTH, check_validity=True)
    # NOTE: at this point the bounding box has been checked to be valid.

    return bbox_yolo


transform = A.Compose(
    [A.HorizontalFlip(), A.RandomBrightnessContrast()],
    bbox_params=A.BboxParams(format='yolo', label_fields=["class_labels"])
)
img = np.zeros((HEIGHT, WIDTH, 3), dtype=np.uint8)

for i in range(1000):
    bboxes = [random_bbox()]
    try:
        transform(image=img, bboxes=bboxes, class_labels=[1])
    except:
        print(f"[{i}] Invalid transformation of box: {str(bboxes[0])}")

>>> [327] Invalid transformation of box: (0.755859375, 0.5944444444444444, 0.48671875, 0.3611111111111111)
>>> [363] Invalid transformation of box: (0.373046875, 0.9409722222222222, 0.68828125, 0.11527777777777778)
>>> [683] Invalid transformation of box: (0.465625, 0.9881944444444445, 0.5765625, 0.020833333333333332)

1reaction
Dipetcommented, Jul 7, 2021

Should be fixed by #924

Read more comments on GitHub >

github_iconTop Results From Across the Web

ValueError: Expected x_max for bbox (0.65, 0.51, 1.12, 0.64, 3 ...
I want to apply data augmentations from PyTorch's Albumentations to images with bounding boxes. When I apply the HorizontalFlip Transformation, ...
Read more >
ValueError: Expected x_max for bbox (tensor(0.9297, dtype ...
Hi, It looks like the issue is that you ask for boxes that are outside the image as one of the bounding box...
Read more >
Questions & Answers - Kaggle
hi guys could any one tell me why im getting this error an how to fixe it ??? ... tensor(0.5631), tensor(2)) to be...
Read more >
Source code for detectron2.structures.boxes
(x0, y0, w, h) in range [0, 1]. They are relative to the size of the image. """ XYWHA_ABS = 4 """ (xc,...
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