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
13.95k stars 1.63k forks source link

Infinite loop when using RandomFog #1359

Open elashchenov opened 1 year ago

elashchenov commented 1 year ago

🐛 Bug

In while loop in get_params_dependent_on_targets function midx or midy may not change in the loop.

To Reproduce

Steps to reproduce the behavior:

  1. Setting parameters fog_coef_lower=0.3, fog_coef_upper=0.3, alpha_coef=0.40, always_apply=True
  2. Take an image of shape (25, 10, 3)
  3. run augmentation

Environment

bekhzod-olimov commented 1 year ago

With Albumentations 1.3.0, python 3.9, and linux everything works properly.

import albumentations as A
import cv2
import matplotlib.pyplot as plt

im = cv2.resize(cv2.cvtColor(cv2.imread("test.jpg"), cv2.COLOR_BGR2RGB), (25, 10))
display(Image.fromarray(im))

plt.figure(figsize=(15,10))
display_ims = 20
var_limit = (0.0, 60.0)
p = 0.5

for i in range(display_ims):   
    tfs = A.Compose([A.RandomFog(fog_coef_lower=0.3, fog_coef_upper=0.3, alpha_coef=0.40, always_apply=True)])
    tfs_im = tfs(image=im)
    plt.subplot(4, display_ims // 4, i+1)
    plt.imshow(tfs_im["image"])
    plt.axis("off")
elashchenov commented 1 year ago

I ran your code and it really works.

However, print(im.shape) outputs (10, 25, 3) because the cv2.resize function has a different order of width and height.

Change the line containing cv2.resize function to the following: im = cv2.resize(cv2.cvtColor(cv2.imread("test.jpg"), cv2.COLOR_BGR2RGB), (10, 25))

and the program should hang