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

[Bug] mmpretrain.datasets.transforms.GaussianBlur doesn't work #1711

Closed
liyunlong10 opened this issue Jul 14, 2023 · 1 comment
Closed

[Bug] mmpretrain.datasets.transforms.GaussianBlur doesn't work #1711

liyunlong10 opened this issue Jul 14, 2023 · 1 comment

Comments

@liyunlong10
Copy link
Contributor

Branch

main branch (mmpretrain version)

Describe the bug

When I use the GaussianBlur to filter the input images, the outputs are always the same as the inputs.

Here is a snippet to reproduce the problem.

import numpy as np
from mmpretrain.datasets.transforms import GaussianBlur

# Create a simple image
img_ori = np.zeros((128, 128), dtype=np.uint8)
img_ori[32:96, 32:96] = 255
results = {'img': img_ori.copy()}

# Run the GaussianBlur
blur = GaussianBlur(radius=10, prob=1.0)
results = blur.transform(results)
img_blur = results['img']

# `img_blur` is expected to be different from `img_ori`
# but actually `img_blur` is exactly equal to `img_ori`
np.all(img_blur == img_ori) # False expected, but got True!

Environment

{'sys.platform': 'linux',
 'Python': '3.10.9 (main, Mar  1 2023, 18:23:06) [GCC 11.2.0]',
 'CUDA available': True,
 'numpy_random_seed': 2147483648,
 'GPU 0,1,2,3': 'Tesla K80',
 'CUDA_HOME': '/root/miniconda3/envs/py10env',
 'NVCC': 'Cuda compilation tools, release 11.7, V11.7.99',
 'GCC': 'gcc (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0',
 'PyTorch': '1.13.1',
 'TorchVision': '0.14.1',
 'OpenCV': '4.7.0',
 'MMEngine': '0.8.1',
 'MMCV': '2.0.1',
 'MMPreTrain': '1.0.0+'}

Other information

I think the image is blurred, but the result is not properly saved.

The GaussianBlur class is in "mmpretrain/mmpretrain/datasets/transforms/auto_augment.py".
In the GaussianBlur.transform method, the blurred image returned by the following code is not properly saved,

pil_img = Image.fromarray(img)
pil_img.filter(ImageFilter.GaussianBlur(radius=radius))  # This is not an in-place operation.
results['img'] = np.array(pil_img, dtype=img.dtype)

It should be

pil_img = Image.fromarray(img)
pil_img = pil_img.filter(ImageFilter.GaussianBlur(radius=radius))  # The result should be saved
results['img'] = np.array(pil_img, dtype=img.dtype)
@Ezra-Yu
Copy link
Collaborator

Ezra-Yu commented Jul 17, 2023

Yes, it is!

Thanks for reporting this BUG, Could you create a PR and fix this BUG?

fangyixiao18 pushed a commit that referenced this issue Jul 25, 2023
* Fix issue 1711. GaussianBlur.

* Fix UT

---------

Co-authored-by: mzr1996 <mzr1996@163.com>
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

3 participants