asetkn / Tutorial-Image-and-Multiple-Bounding-Boxes-Augmentation-for-Deep-Learning-in-4-Steps

30 stars 16 forks source link

bbs_a AssertionError in [25] #1

Closed WellDL closed 4 years ago

WellDL commented 4 years ago

Hello, I experience an issue when running the almost last code in [25] of your notebook. I could not fix it yet. Still, very impressive Augmentation Code!

AssertionError                            Traceback (most recent call last)
<ipython-input-29-32529b912587> in <module>()
     16     bb_a_array = group_a_df.drop(['filename', 'width', 'height', 'class'], axis=1).values
     17     augmented_img = imageio.imread('aug_dataset/'+'aug1_'+filename)
---> 18     bbs_a = BoundingBoxesOnImage.from_xyxy_array(bb_a_array, shape=augmented_img.shape)
     19 
     20     ia.imshow(np.hstack([

3 frames
/usr/local/lib/python3.6/dist-packages/imgaug/augmentables/bbs.py in from_xyxy_array(cls, xyxy, shape)
    923         ia.do_assert(xyxy.shape[1] == 4, "Expected input array of shape (N, 4), got shape %s." % (xyxy.shape,))
    924 
--> 925         boxes = [BoundingBox(*row) for row in xyxy]
    926 
    927         return cls(boxes, shape)

/usr/local/lib/python3.6/dist-packages/imgaug/augmentables/bbs.py in <listcomp>(.0)
    923         ia.do_assert(xyxy.shape[1] == 4, "Expected input array of shape (N, 4), got shape %s." % (xyxy.shape,))
    924 
--> 925         boxes = [BoundingBox(*row) for row in xyxy]
    926 
    927         return cls(boxes, shape)

/usr/local/lib/python3.6/dist-packages/imgaug/augmentables/bbs.py in __init__(self, x1, y1, x2, y2, label)
     45         if x1 > x2:
     46             x2, x1 = x1, x2
---> 47         ia.do_assert(x2 >= x1)
     48         if y1 > y2:
     49             y2, y1 = y1, y2

/usr/local/lib/python3.6/dist-packages/imgaug/imgaug.py in do_assert(condition, message)
   1867     """
   1868     if not condition:
-> 1869         raise AssertionError(str(message))
   1870 
   1871 

AssertionError: Assertion failed.
asetkn commented 4 years ago

Hi! I'm glad you are finding this repo helpful :) This AssertionError most probably caused by xmin being greater than xmax (or same for ymin and ymax). I would check bounding boxes coordinates.

WellDL commented 4 years ago

Thank you for the fast response! I think that must be it, since your example in images folder works just fine for me, too. Actually, the augmentation for my dataset works - I can view some of the augmented pictures in the output of [25], however it interrupts with an image with AssertionError.

Since there is a problem with the bounding boxes in bbs_a and not bbs_r, I think there must be an issue after augmented f.e. rotation that causes the min value being greater than max value.

I think I will just resize my dataset to 600x450 px and relabel my images beforehand to solve the problem.

Thank you again!