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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

when I used the ImageDataGenerator,I encountered a error #186

Closed
hnsywangxin opened this issue Dec 15, 2017 · 4 comments
Closed

when I used the ImageDataGenerator,I encountered a error #186

hnsywangxin opened this issue Dec 15, 2017 · 4 comments

Comments

@hnsywangxin
Copy link

hnsywangxin commented Dec 15, 2017

The parameter of ImageDataGenerator is :

       horizontal_flip=False,
       featurewise_center=True,
        featurewise_std_normalization=True,
        rotation_range=10,
        width_shift_range=0.1,
        height_shift_range=0.1

and the error is :min() arg is an empty sequence.
the error is from "keras_retinanet/utils/image.py", line 80, in random_transform
boxes[index, 0] = float(min(j))"
thank you

@ghost
Copy link

ghost commented Dec 15, 2017

Jup, this can happen lot's basically a bounding box is augmented out of the image, and it cannot find it anymore, either lower your augmentation, or do something nasty like this: (or both)

while not finished:
        boxes=boxes_in
        if initseed is None:
            seed = np.random.randint(10000)
        else:
            seed = initseed

        image = image_data_generator.random_transform(image_in, seed=seed)

        # set fill mode so that masks are not enlarged
        fill_mode = image_data_generator.fill_mode
        image_data_generator.fill_mode = 'constant'

        for index in range(boxes_in.shape[0]):
            # generate box mask and randomly transform it
            mask = np.zeros_like(image, dtype=np.uint8)
            b = boxes_in[index, :4].astype(int)

            assert(b[0] < b[2] and b[1] < b[3]), 'Annotations contain invalid box: {}'.format(b)
            assert(b[2] <= image.shape[1] and b[3] <= image.shape[0]), 'Annotation ({}) is outside of image shape ({}).'.format(b, image.shape)

            mask[b[1]:b[3], b[0]:b[2], :] = 255

            mask_after = image_data_generator.random_transform(mask, seed=seed)[..., 0]
            mask_after = mask_after.copy()  # to force contiguous arrays

            # find bounding box again in augmented image
            [i, j] = np.where(mask_after == 255)
            if len(i)==0 or len(j)==0:
                print('Invalid augementation')
                wrongBox = True
                assert False
                continue
            boxes[index, 0] = float(min(j))
            boxes[index, 1] = float(min(i))
            boxes[index, 2] = float(max(j)) + 1 # set box to an open interval [min, max)
            boxes[index, 3] = float(max(i)) + 1 # set box to an open interval [min, max)

        if wrongBox:
            print('==== found a wrongbox! ====')
            wrongBox = False
            continue
        finished = True

@hgaiser
Copy link
Contributor

hgaiser commented Dec 17, 2017

Does this solve your issue?

@hgaiser hgaiser closed this as completed Dec 17, 2017
@hgaiser hgaiser reopened this Dec 17, 2017
@hnsywangxin
Copy link
Author

I have solved it ,thank you @hgaiser @de-vri-es @LaurensHagendoorn

@de-vri-es
Copy link
Contributor

de-vri-es commented Dec 20, 2017

#190 may address this partially. There's still some open questions on how to deal with bounding boxes that get partially transformed out of the image canvas (see the inline comments). Any input there is welcome :)

Since the original issue is resolved, and a more general solution should be implemented in #190, I'm closing 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

No branches or pull requests

3 participants