aleju / imgaug

Image augmentation for machine learning experiments.
http://imgaug.readthedocs.io
MIT License
14.36k stars 2.43k forks source link

seq.to_deterministic() augments images and bounding boxes differently if an image has no corresponding bounding box #231

Open sun-yitao opened 5 years ago

sun-yitao commented 5 years ago

For example, if i augment a list of numpy images and a corresponding list of ia.BoundingBoxesOnImage:

seq = iaa.Sequential(
        [iaa.Fliplr(0.5), 
         iaa.Affine(
            rotate=(-30, 30),
            mode='edge')
        ],
        random_order=True
      )
seq_det = seq.to_deterministic()
image_aug = seq_det.augment_images(np_img_array)
bbs_aug = seq_det.augment_bounding_boxes(bbs_on_img_array)

If one of the images has no bounding box, bbs_on_img_array may look something like this after the annotation xmls was parsed:

[BoundingBoxesOnImage([BoundingBox(x1=266.0000, y1=633.0000, x2=299.0000, y2=692.0000, label=person)], shape=(720, 1280)),
 BoundingBoxesOnImage([BoundingBox(x1=283.0000, y1=637.0000, x2=312.0000, y2=701.0000, label=person)], shape=(720, 1280)),
 BoundingBoxesOnImage([BoundingBox(x1=279.0000, y1=656.0000, x2=308.0000, y2=720.0000, label=person)], shape=(720, 1280)),
 BoundingBoxesOnImage([], shape=(720, 1280)),
 BoundingBoxesOnImage([BoundingBox(x1=272.0000, y1=632.0000, x2=301.0000, y2=696.0000, label=person)], shape=(720, 1280)),
 BoundingBoxesOnImage([BoundingBox(x1=266.0000, y1=634.0000, x2=305.0000, y2=692.0000, label=person)], shape=(720, 1280)),
 BoundingBoxesOnImage([BoundingBox(x1=261.0000, y1=637.0000, x2=321.0000, y2=689.0000, label=person)], shape=(720, 1280))]

And this will cause the augmentations after the 4th bounding box to jumble up. Currently, I have added the images without bounding boxes to a separate queue to be augmented. But I believe this shouldn't be the intended behaviour as it can be quite difficult to figure out what is the underlying cause of the bounding boxes and images not being augmented correctly when the dataset contains images with no bounding boxes.

aysark commented 5 years ago

Yes, just ran into this issue and should be fixed.

aleju commented 5 years ago

The issue is fixed in master, but not yet in the pypi version.