albumentations-team / albumentations

Fast and flexible image augmentation library. Paper about the library: https://www.mdpi.com/2078-2489/11/2/125
https://albumentations.ai
MIT License
14k stars 1.63k forks source link

Unclear warning when using Perspective transform in ReplayMode #1083

Open EtagiBI opened 2 years ago

EtagiBI commented 2 years ago

Hi, I'm trying to use Perspective transform to generate a dataset of augumented images and corresponding transormation matrices.

Here's a code:

def albumentate(image):
    transform = A.ReplayCompose([
        A.Perspective(scale=(0.06, 0.06),
                      keep_size=True,
                      pad_mode=cv2.BORDER_REPLICATE,
                      pad_val=0,
                      mask_pad_val=0,
                      fit_output=True,
                      interpolation=1,
                      always_apply=True,
                      p=1.0)
    ])
    augmented = transform(image=image)
    matrix = augmented["replay"]["transforms"][0]["params"]["matrix"]
    augmented_image = augmented['image']
    print(matrix)
    return augmented_image, matrix

When I run the code, I get a warning:

C:\Python3\lib\site-packages\albumentations\core\transforms_interface.py:93: UserWarning: Perspective could work incorrectly in ReplayMode for other input data because its' params depend on targets.
  self.get_class_fullname() + " could work incorrectly in ReplayMode for other input data"

I have to use ReplayMode, because I need resulting transformation matrices. Should I worry about this warning? It would be nice to have this nuance covered in the docs.

Dipet commented 2 years ago

Everything will work correctly. This warning means that, for example, if you provide an image and targets with different shapes than original data for reproduction (only when you call transform.replay(**replay_args)), it may not work correctly.