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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

ValueError: Expected x_min for bbox (...) to be in the range [0.0, 1.0], got -0.0020000000000000018 #1497

Open
MarcosRodrigoT opened this issue Nov 10, 2023 · 0 comments 路 May be fixed by #1498

Comments

@MarcosRodrigoT
Copy link

馃悰 Bug

Albumentations is raising ValueError: Expected x_min for bbox (-0.002499499999999988, 0.3245773732394366, 0.5367755, 0.9829923732394366, 22.0) to be in the range [0.0, 1.0], got -0.002499499999999988.

To Reproduce

Steps to reproduce the behavior:

  1. Create an albumentations compose object.
  2. Pass some bounding boxes in the yolo format.

Expected behavior

Environment

  • Albumentations version: 1.3.1
  • Python version: 3.10.12
  • OS (e.g., Linux): Ubuntu 22.04
  • How you installed albumentations: pip

Additional context

Code to reproduce the error:

import albumentations as A
import cv2
import numpy as np
from PIL import Image


img_path = "COCO/images/COCO_train2014_000000394974.jpg"
label_path = "COCO/images/COCO_train2014_000000394974.txt"

image = np.array(Image.open(img_path).convert("RGB"))
bboxes = np.roll(
    np.loadtxt(fname=label_path, delimiter=" ", ndmin=2),
    shift=4,
    axis=1,
).tolist()

"""BEFORE AUGMENTATION"""
print(f"Image file: {img_path}")
print(f"Image shape: {image.shape}")
print(f"Label file: {label_path}")
print("Bboxes before augmentation:")
for bbox in bboxes:
    print(bbox)

augmentor = A.Compose(
    [
        A.LongestMaxSize(max_size=416),
        A.PadIfNeeded(
            min_height=416, min_width=416, border_mode=cv2.BORDER_CONSTANT
        ),
        A.Normalize(
            mean=[0, 0, 0],
            std=[1, 1, 1],
            max_pixel_value=255,
        ),
        ToTensorV2(),
    ],
    bbox_params=A.BboxParams(format="yolo", min_visibility=0.4, label_fields=[]),
)
augmentations = augmentor(image=image, bboxes=bboxes)

"""AFTER AUGMENTATION"""
image = augmentations["image"]
bboxes = augmentations["bboxes"]
print("Bboxes after augmentation:")
for bbox in bboxes:
    print(bbox)

Result obtained from the above code snippet:

Image file: COCO/images/COCO_train2014_000000394974.jpg
Image shape: (284, 400, 3)
Label file: /home/marcos/Datasets/COCO/labels/COCO_train2014_000000394974.txt

Bboxes before augmentation:
[0.4514250000000001, 0.4515318732394366, 0.3494, 0.541585, 22.0]
[0.267138, 0.6537848732394366, 0.539275, 0.658415, 22.0]
[0.285525, 0.7203518732394366, 0.38795, 0.406831, 22.0]

Traceback (most recent call last):
  File "/home/marcos/Projects/YOLOv3/PyTorch/dataset.py", line 155, in <module>
    test()
  File "/home/marcos/Projects/YOLOv3/PyTorch/dataset.py", line 137, in test
    for x, y in loader:
  File "/home/marcos/Projects/YOLOv3/venv/lib/python3.10/site-packages/torch/utils/data/dataloader.py", line 630, in __next__
    data = self._next_data()
  File "/home/marcos/Projects/YOLOv3/venv/lib/python3.10/site-packages/torch/utils/data/dataloader.py", line 674, in _next_data
    data = self._dataset_fetcher.fetch(index)  # may raise StopIteration
  File "/home/marcos/Projects/YOLOv3/venv/lib/python3.10/site-packages/torch/utils/data/_utils/fetch.py", line 51, in fetch
    data = [self.dataset[idx] for idx in possibly_batched_index]
  File "/home/marcos/Projects/YOLOv3/venv/lib/python3.10/site-packages/torch/utils/data/_utils/fetch.py", line 51, in <listcomp>
    data = [self.dataset[idx] for idx in possibly_batched_index]
  File "/home/marcos/Projects/YOLOv3/PyTorch/dataset.py", line 70, in __getitem__
    augmentations = self.transform(image=image, bboxes=bboxes)
  File "/home/marcos/Projects/YOLOv3/venv/lib/python3.10/site-packages/albumentations/core/composition.py", line 207, in __call__
    p.preprocess(data)
  File "/home/marcos/Projects/YOLOv3/venv/lib/python3.10/site-packages/albumentations/core/utils.py", line 83, in preprocess
    data[data_name] = self.check_and_convert(data[data_name], rows, cols, direction="to")
  File "/home/marcos/Projects/YOLOv3/venv/lib/python3.10/site-packages/albumentations/core/utils.py", line 91, in check_and_convert
    return self.convert_to_albumentations(data, rows, cols)
  File "/home/marcos/Projects/YOLOv3/venv/lib/python3.10/site-packages/albumentations/core/bbox_utils.py", line 142, in convert_to_albumentations
    return convert_bboxes_to_albumentations(data, self.params.format, rows, cols, check_validity=True)
  File "/home/marcos/Projects/YOLOv3/venv/lib/python3.10/site-packages/albumentations/core/bbox_utils.py", line 408, in convert_bboxes_to_albumentations
    return [convert_bbox_to_albumentations(bbox, source_format, rows, cols, check_validity) for bbox in bboxes]
  File "/home/marcos/Projects/YOLOv3/venv/lib/python3.10/site-packages/albumentations/core/bbox_utils.py", line 408, in <listcomp>
    return [convert_bbox_to_albumentations(bbox, source_format, rows, cols, check_validity) for bbox in bboxes]
  File "/home/marcos/Projects/YOLOv3/venv/lib/python3.10/site-packages/albumentations/core/bbox_utils.py", line 352, in convert_bbox_to_albumentations
    check_bbox(bbox)
  File "/home/marcos/Projects/YOLOv3/venv/lib/python3.10/site-packages/albumentations/core/bbox_utils.py", line 435, in check_bbox
    raise ValueError(f"Expected {name} for bbox {bbox} to be in the range [0.0, 1.0], got {value}.")
ValueError: Expected x_min for bbox (-0.002499499999999988, 0.3245773732394366, 0.5367755, 0.9829923732394366, 22.0) to be in the range [0.0, 1.0], got -0.002499499999999988.
@MarcosRodrigoT MarcosRodrigoT linked a pull request Nov 10, 2023 that will close this issue
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 a pull request may close this issue.

1 participant