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

CropNonEmptyMaskIfExists not working correctly if ignore_values isn't assigned a value #1058

Open
TechpriestW opened this issue Nov 16, 2021 · 1 comment
Labels
bug Something isn't working

Comments

@TechpriestW
Copy link

🐛 Bug

I was experimenting with albumentations functions when I found this bug. If "ignore_values" parameter in "CropNonEmptyMaskIfExists" isn't explicitly assigned a value, the transformation may modify the masks passed to it.

To Reproduce

Steps to reproduce the behavior:

import albumentations as A
import numpy as np
a = numpy.array([[1,2],[3,4]])
b = numpy.array([[5,6],[7,8]])
img = numpy.array([[11,12],[13,14]])
transform = A.augmentations.crops.transforms.CropNonEmptyMaskIfExists(1,2)
out = transform(image = img, masks = [a,b])

Expected behavior

According to the documentation, I assumed the transformation will work as if ignore_values=[0] and simply give a randomly cropped image and masks. However, the values of variable "out" are:

{'image': array([[13, 14]]), 'masks': [array([[ 7, 12]]), array([[7, 8]])]}

Meanwhile, the values of "a" are now:

array([[ 5,  6],
       [ 7, 12]])

Setting "ignore_channels" parameter wouldn't change this behavior. However, if "mask" was passed instead of "masks", the transformation would work as it's supposed to.

Environment

  • Albumentations version (e.g., 0.1.8): 1.1.0
  • Python version (e.g., 3.7): python 3.9.6
  • OS (e.g., Linux): windows 10
  • How you installed albumentations (conda, pip, source): pip
@Dipet Dipet added the bug Something isn't working label Nov 16, 2021
@Dipet
Copy link
Collaborator

Dipet commented Nov 16, 2021

Thanks so much for finding this bug!
Looks like need to use an independent copy of the mask there https://github.com/albumentations-team/albumentations/blob/master/albumentations/augmentations/crops/transforms.py#L200

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants