question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Incorrect number of masks returned after augmentation

See original GitHub issue

🐛 Bug

Describe the bug Incorrect number of masks returned after augmentation. It happend when some boxes goes outside of image. Number of boxes changed but masks stays the same.

To Reproduce

from albumentations import *
from albumentations import __version__ as ver


transform_generator = Compose([
        ShiftScaleRotate(p=1.0, shift_limit=0.1, scale_limit=0.2, rotate_limit=45, border_mode=cv2.BORDER_REFLECT),
    ], bbox_params={'format': 'pascal_voc',
                    'min_area': 0,
                    'min_visibility': 0.0,
                    'label_fields': ['labels']}, p=1.0)


def albu_bug():
    print('Albu ver: {}'.format(ver))
    image = np.zeros((500, 500, 3), dtype=np.uint8)
    mask1 = np.zeros((500, 500, 3), dtype=np.uint8)
    mask2 = np.zeros((500, 500, 3), dtype=np.uint8)
    mask3 = np.zeros((500, 500, 3), dtype=np.uint8)
    mask1[0:10, 0:10] = 255
    mask2[-10:, -10:] = 255
    mask3[250:260, 250:260] = 255

    ann = dict()
    ann['image'] = image.copy()
    ann['masks'] = [mask1, mask2, mask3]
    ann['labels'] = np.array([0, 0, 0])
    ann['bboxes'] = np.array([[0, 0, 10, 10], [490, 490, 500, 500], [250, 250, 260, 260]])

    for i in range(10):
        augm = transform_generator(**ann)
        print(len(ann['masks']), len(ann['labels']), len(ann['bboxes']))
        print(len(augm['masks']), len(augm['labels']), len(augm['bboxes']))


if __name__ == '__main__':
    albu_bug()

Expected behavior Masks corrsponding to removed boxes must be also removed

Environment

  • Albumentations version (e.g., 0.1.8): 0.5.2
  • Python version (e.g., 3.7): 3.7
  • OS (e.g., Linux): Win10
  • How you installed albumentations (conda, pip, source): pip

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:1
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
ChrisDAT20commented, Jul 24, 2022

I face the same issue as @ZFTurbo: I have situations where the masks do not match the bboxes. The image has 25 annotations, bboxes and segmentations which are converted to masks using the COCO api (coco.annToMask(). Then the image and targets are passed through a few transforms, CenterCrop, Resize, Affine… The transformed dict only contains 9 boxes, but it still containes 25 masks. When I filter out masks which only contain zeros masks = [i for i in masks if i.any()], most of the time this works. But sometimes a bbox is still there where its mask is gone after I filtered “empty” masks.

…than create some strange code to augment both bboxes and mask and check them after each transformation.

I thought thats what DualTransforms for, applying the transforms to both image and target in the same way. But it seems that bbox and mask transforms might get inconsistent.

0reactions
Dipetcommented, Feb 4, 2021

So, if you have bbox like on example image it is will be incorrect after crop. For this reason I think better augment only masks, because they are much more correct. So if you will augment only mask and then create bboxes it is better than create some strange code to augment both bboxes and mask and check them after each transformation.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Incorrect Facemask-Wearing Detection Using Convolutional ...
On the one hand, it detected the use or non-use of a facial mask. After detecting a mask, it distinguished between its correct...
Read more >
A Computer Vision Model to Identify the Incorrect Use of Face ...
The dataset has. 3000 images in total. The numbers of faces that can be extracted from the dataset are 9161 without masks and...
Read more >
How to Correctly Detect Face-Masks for COVID-19 from Visual ...
By the end of November 2020, the global number of new coronavirus cases had already ... between masked faces with correctly and incorrectly...
Read more >
Conserving Supply of Personal Protective Equipment—A Call ...
Snorkel masks could serve as a reusable and waterproof protective gear ... many bacterial pathogens so the mask should go back to the...
Read more >
Mask Usage Recognition using Vision Transformer ... - arXiv
best classification is transfer learning and augmentation using ViT ... parts based on the number of patches that have been declared after.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found