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

unorderable types: str() >= int() and unsupported operand type(s) for -: 'int' and 'str' #682

Open
NoxTheXelor opened this issue May 30, 2020 · 2 comments

Comments

@NoxTheXelor
Copy link

I'm using the 0.2.9 version (don't know why neither anaconda or pip don't upgrade the package to the 0.4.0 version)
and when I use some augmenters I nearly always fall on that kind of error. The only augmenters that are actually working for me are the Affine and Fliplr.

The augmenter that give me these errors are these one :

iaa.SaltAndPepper(0.1, per_channel=True),
iaa.Add((-40, 40), per_channel=0.5)
iaa.AdditiveGaussianNoise(scale=(0, 0.2*255)),
iaa.Multiply((0.5, 1.5), per_channel=0.5),
iaa.AverageBlur(k=((5, 11), (1, 3))),
iaa.WithColorspace(to_colorspace="HSV",from_colorspace="RGB",children=iaa.WithChannels(0,iaa.Add((0, 50)))),
iaa.AddToHueAndSaturation((-50, 50), per_channel=True)

The errors :

Traceback (most recent call last):
  File "e:/EPHEC/Bac_3/Q2/TFE/experiencor/dataAugmentation/echantillon/reddit_file.py", line 248, in <module>
    augmented_images_df = image_aug(labels_df, 'train_image_folder/', 'aug_images/', 'aug2_', aug)
  File "e:/EPHEC/Bac_3/Q2/TFE/experiencor/dataAugmentation/echantillon/reddit_file.py", line 110, in image_aug
    bbs_aug = bbs_aug.remove_out_of_image()
  File "C:\Users\Antoine\Anaconda3\envs\augmentData\lib\site-packages\imgaug\augmentables\bbs.py", line 1026, in remove_out_of_image
    bbs_clean = [bb for bb in self.bounding_boxes
  File "C:\Users\Antoine\Anaconda3\envs\augmentData\lib\site-packages\imgaug\augmentables\bbs.py", line 1027, in <listcomp>
    if not bb.is_out_of_image(self.shape, fully=fully, partly=partly)]
  File "C:\Users\Antoine\Anaconda3\envs\augmentData\lib\site-packages\imgaug\augmentables\bbs.py", line 420, in is_out_of_image
    if self.is_fully_within_image(image):
  File "C:\Users\Antoine\Anaconda3\envs\augmentData\lib\site-packages\imgaug\augmentables\bbs.py", line 370, in is_fully_within_image
    return self.x1 >= 0 and self.x2 < width and self.y1 >= 0 and self.y2 < height
TypeError: unorderable types: str() >= int()

or

Traceback (most recent call last):
  File "e:/EPHEC/Bac_3/Q2/TFE/experiencor/dataAugmentation/echantillon/reddit_file.py", line 236, in <module>
    augmented_images_df = image_aug(labels_df, 'train_image_folder/', 'aug_images/', 'aug2_', aug)
  File "e:/EPHEC/Bac_3/Q2/TFE/experiencor/dataAugmentation/echantillon/reddit_file.py", line 107, in image_aug
    image_aug, bbs_aug = augmentor(image=image, bounding_boxes=bbs)
  File "C:\Users\Antoine\Anaconda3\envs\augmentData\lib\site-packages\imgaug\augmenters\meta.py", line 1888, in __call__
    return self.augment(*args, **kwargs)
  File "C:\Users\Antoine\Anaconda3\envs\augmentData\lib\site-packages\imgaug\augmenters\meta.py", line 1859, in augment
    batch_aug = self.augment_batch(batch, hooks=hooks)
    attr, hooks=hooks)
  File "C:\Users\Antoine\Anaconda3\envs\augmentData\lib\site-packages\imgaug\augmenters\meta.py", line 1066, in augment_bounding_boxes
    kps_ois_aug = self.augment_keypoints(kps_ois, hooks=hooks)
  File "C:\Users\Antoine\Anaconda3\envs\augmentData\lib\site-packages\imgaug\augmenters\meta.py", line 951, in augment_keypoints
    hooks=hooks
  File "C:\Users\Antoine\Anaconda3\envs\augmentData\lib\site-packages\imgaug\augmenters\meta.py", line 3157, in _augment_keypoints
    parents, hooks, _augfunc)
  File "C:\Users\Antoine\Anaconda3\envs\augmentData\lib\site-packages\imgaug\augmenters\meta.py", line 3195, in _augment_non_images
    hooks
  File "C:\Users\Antoine\Anaconda3\envs\augmentData\lib\site-packages\imgaug\augmenters\meta.py", line 3155, in _augfunc
    return augmenter_.augment_keypoints(koi_to_aug_, parents_, hooks_)
  File "C:\Users\Antoine\Anaconda3\envs\augmentData\lib\site-packages\imgaug\augmenters\meta.py", line 951, in augment_keypoints
    hooks=hooks
  File "C:\Users\Antoine\Anaconda3\envs\augmentData\lib\site-packages\imgaug\augmenters\flip.py", line 120, in _augment_keypoints
    keypoint.x = (width - 1) - keypoint.x
TypeError: unsupported operand type(s) for -: 'int' and 'str'

Thanks in advance for the help !

@aleju
Copy link
Owner

aleju commented May 30, 2020

I'm using the 0.2.9 version (don't know why neither anaconda or pip don't upgrade the package to the 0.4.0 version)

Try adding --upgrade to pip or an explicit uninstall first, like pip uninstall -y imgaug; pip install imgaug. If it reports that the library was successfully installed and then when you run python it is still an old version, there are multiple python environments on your system and pip is installing to a different one than what you are actually using.

Regarding the problem, judging from the stacktrace it looks like the first error originates from

File "e:/EPHEC/Bac_3/Q2/TFE/experiencor/dataAugmentation/echantillon/reddit_file.py", line 110, in image_aug
bbs_aug = bbs_aug.remove_out_of_image()

i.e. from a step where you try to remove some bounding boxes.
The error is due to a bounding box coordinate being expected to be float or int, but it actually is a string. I.e. at some point you probably create a bounding box with something like BoundingBox(x1, y1, x2, y2) and one of x1, y1, x2 or y2 is a string. My guess would be that you read these values from a file and forgot to parse them via int(value) or float(value). Or you accidentally provide a (class) label instead of one of these coordinates.

@NoxTheXelor
Copy link
Author

Thanks for your help !!
You guess well, the augmented data are writed in a csv file and the bounding boxes coordinates in there are under float format. Anyway I updated the library (I messed with my virtuals env) and it solved almost all my problems.
Willing to improve my script I added more augmenters to it and this error occur an impressive amount of time.

Number of defect : 154
Traceback (most recent call last):
    _main_(args)
  File "e:/EPHEC/Bac_3/Q2/TFE/experiencor/dataAugmentation/echantillon/augment_data.py", line 300, in _main_
    augmented_images_df = image_aug(labels_df, 'train_image_folder/', 'aug_images/', prefix, aug)
  File "e:/EPHEC/Bac_3/Q2/TFE/experiencor/dataAugmentation/echantillon/augment_data.py", line 154, in image_aug
    image_aug, bbs_aug = augmentor(image=image, bounding_boxes=bbs)
  File "C:\Users\Antoine\Anaconda3\envs\augment_data_2.0\lib\site-packages\imgaug\augmenters\meta.py", line 2008, in __call__
    return self.augment(*args, **kwargs)
  File "C:\Users\Antoine\Anaconda3\envs\augment_data_2.0\lib\site-packages\imgaug\augmenters\meta.py", line 1979, in augment
    batch_aug = self.augment_batch_(batch, hooks=hooks)
  File "C:\Users\Antoine\Anaconda3\envs\augment_data_2.0\lib\site-packages\imgaug\augmenters\meta.py", line 645, in augment_batch_
    hooks=hooks)
  File "C:\Users\Antoine\Anaconda3\envs\augment_data_2.0\lib\site-packages\imgaug\augmenters\meta.py", line 3406, in _augment_batch_
    hooks=hooks
  File "C:\Users\Antoine\Anaconda3\envs\augment_data_2.0\lib\site-packages\imgaug\augmenters\meta.py", line 645, in augment_batch_
    hooks=hooks)
  File "C:\Users\Antoine\Anaconda3\envs\augment_data_2.0\lib\site-packages\imgaug\augmenters\blend.py", line 692, in _augment_batch_
    self._coord_modes[augm_attr_name]
  File "C:\Users\Antoine\Anaconda3\envs\augment_data_2.0\lib\site-packages\imgaug\augmenters\blend.py", line 738, in _blend_coordinates
    coords.shape, coords_fg.shape, coords_bg.shape))
AssertionError: Expected number of coordinates to not be changed by foreground or background branch in BlendAlphaMask. But input coordinates of shape (12, 2) were changed to (0, 2) (foreground) and (12, 2) (background). Make sure to 
not use any augmenters that affect the existence of coordinates.

I understand that the problem come from the BlendAlpha augmenters but I don't really understand the origin of the error.
I have already 13 augmenters working in my list so for the moment I will comment the BlendAlpha one. The script will still work without them. I only wanted to understand the problem.

Thanks in advance !!

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

2 participants