ValueError: x_max is less than or equal to x_min for bbox

ValueError: x_max is less than or equal to x_min for bbox

我正在为一组图像和 bbox 使用相册。

我的边界框是“yolo”格式,即(x_mid、y_mid、宽度、高度),全部标准化。

While 运行 albumentations for a set of bounding errors, above error comes (ValueError: x_max is less than or equal to x_min for bbox) 当边界框采用此值时: [0.00017655367231635, 0.0002155172413793, 0.0003531073446327, 0.0004310344827586]。这里,x_min, y_min=[0,0].

其他边界框不会出现此错误 - 例如:[0.3060659468984962、0.4418239134174312、0.2412257095864662、0.5496854701834863]。

当我稍微增加 ERROR 边界框的所有尺寸时,这个错误就解决了,即: 对于此错误 BB [0.00017655367231635、0.0002155172413793、0.0003531073446327、0.0004310344827586],将 x_mid、y_mid、x_width 和 y_width 增加 0.01。

导致错误免费 BB:[0.01017655367231635,0.0102155172413793,0.0103531073446327,0.010431034482758601]。

谁能告诉我解决这个错误而不改变 BB 尺寸的方法?

我正在使用以下代码进行相册处理:

import albumentations as A

    A.Compose(
    [
        A.LongestMaxSize(max_size=IMAGE_SIZE),
        A.PadIfNeeded(
            min_height=IMAGE_SIZE, min_width=IMAGE_SIZE, 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=[]),
)

详细错误:

---> 62                 augmentations_norm = self.transform_norm(image=image, bboxes=bboxes)
 63                 #print('Aug done')
 64                 image = augmentations_norm["image"]

/opt/conda/lib/python3.7/site-packages/albumentations/core/composition.py in __call__(self, force_apply, *args, **data)
    178             if dual_start_end is not None and idx == dual_start_end[0]:
    179                 for p in self.processors.values():
--> 180                     p.preprocess(data)
    181 
    182             data = t(force_apply=force_apply, **data)

/opt/conda/lib/python3.7/site-packages/albumentations/core/utils.py in preprocess(self, data)
     60         rows, cols = data["image"].shape[:2]
     61         for data_name in self.data_fields:
---> 62             data[data_name] = self.check_and_convert(data[data_name], rows, cols, direction="to")
     63 
     64     def check_and_convert(self, data, rows, cols, direction="to"):

/opt/conda/lib/python3.7/site-packages/albumentations/core/utils.py in check_and_convert(self, data, rows, cols, direction)
     68 
     69         if direction == "to":
---> 70             return self.convert_to_albumentations(data, rows, cols)
     71 
     72         return self.convert_from_albumentations(data, rows, cols)

/opt/conda/lib/python3.7/site-packages/albumentations/augmentations/bbox_utils.py in convert_to_albumentations(self, data, rows, cols)
     49 
     50     def convert_to_albumentations(self, data, rows, cols):
---> 51         return convert_bboxes_to_albumentations(data, self.params.format, rows, cols, check_validity=True)
     52 
     53 

/opt/conda/lib/python3.7/site-packages/albumentations/augmentations/bbox_utils.py in convert_bboxes_to_albumentations(bboxes, source_format, rows, cols, check_validity)
    300 def convert_bboxes_to_albumentations(bboxes, source_format, rows, cols, check_validity=False):
    301     """Convert a list bounding boxes from a format specified in `source_format` to the format used by albumentations"""
--> 302     return [convert_bbox_to_albumentations(bbox, source_format, rows, cols, check_validity) for bbox in bboxes]
    303 
    304 

/opt/conda/lib/python3.7/site-packages/albumentations/augmentations/bbox_utils.py in <listcomp>(.0)
    300 def convert_bboxes_to_albumentations(bboxes, source_format, rows, cols, check_validity=False):
    301     """Convert a list bounding boxes from a format specified in `source_format` to the format used by albumentations"""
--> 302     return [convert_bbox_to_albumentations(bbox, source_format, rows, cols, check_validity) for bbox in bboxes]
    303 
    304 

/opt/conda/lib/python3.7/site-packages/albumentations/augmentations/bbox_utils.py in convert_bbox_to_albumentations(bbox, source_format, rows, cols, check_validity)
    249     bbox = normalize_bbox(bbox, rows, cols)
    250     if check_validity:
--> 251         check_bbox(bbox)
    252     return bbox
    253 

/opt/conda/lib/python3.7/site-packages/albumentations/augmentations/bbox_utils.py in check_bbox(bbox)
    331     x_min, y_min, x_max, y_max = bbox[:4]
    332     if x_max <= x_min:
--> 333         raise ValueError("x_max is less than or equal to x_min for bbox {bbox}.".format(bbox=bbox))
    334     if y_max <= y_min:
    335         raise ValueError("y_max is less than or equal to y_min for bbox {bbox}.".format(bbox=bbox))

ValueError: x_max is less than or equal to x_min for bbox (0.00390625, 0.00390625, 0.00390625, 0.00390625, 0.0).

改编自评论:

当您在相册库中使用边界框时,您需要确保在查看图像大小时这些框的宽度大于 0。这在 yolo 边界框表示中可能并不明显,但如果您这样做,您可以快速检查一下:

pix_w = int(bb[2]*img_w)
pix_h = int(bb[3]*img_w)
np.testing.assert_equal(np.all([pix_w>0,pix_h>0]), True)