我正在为一组图像和bboxes使用albumentations。
我的边界框是"yolo“格式,即(x_mid,y_mid,width,height),全部归一化。
在为一组边界错误运行albumentations时,当边界框采用以下值时,上述错误就会出现(ValueError: x_max小于或等于bbox的x_min ):0.00017655367231635、0.0002155172413793、0.0003531073446327、0.0004310344827586。这里,x_min,y_min=0,0。
这个错误不会出现在其他边界框中-例如: 0.3060659468984962,0.4418239134174312,0.2412257095864662,0.5496854701834863。
当我稍微增加错误边界框的所有尺寸时,即:对于此错误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尺寸就能解决这个错误的方法?
我正在使用下面的代码来做albumentations:
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).发布于 2021-08-17 00:04:22
改编自评论:
在使用albumentations库中的边框时,在查看图像大小时,需要确保边框的宽度大于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)https://stackoverflow.com/questions/68796654
复制相似问题