bethgelab / imagecorruptions

Python package to corrupt arbitrary images.
https://pypi.org/project/imagecorruptions/
Apache License 2.0
409 stars 64 forks source link

glass_blur is very slow, it cost 46 seconds #7

Closed fanqie03 closed 3 years ago

fanqie03 commented 5 years ago

the demo code is

from imagecorruptions import corrupt, get_corruption_names
from PIL import Image
import numpy as np
import matplotlib.pyplot as plt
import time
# image = np.asarray(Image.open('demo.jpg'))
image = np.ones((427, 640, 3), dtype=np.uint8)

# corrupted_image = corrupt(img, corruption_name='gaussian_blur', severity=1)

for corruption in get_corruption_names('all'):
    tic = time.time()
    for severity in range(5):
        corrupted = corrupt(image, corruption_name=corruption, severity=severity+1)
        plt.imshow(corrupted)
        plt.show()
    print(corruption, time.time() - tic)

and the result is

gaussian_noise 1.0818257331848145
shot_noise 1.0653698444366455
impulse_noise 0.9121599197387695
defocus_blur 0.8352060317993164
glass_blur 46.11975622177124
motion_blur 1.0764939785003662
zoom_blur 3.1540017127990723
snow 0.6903097629547119
frost 0.4696829319000244
fog 0.6326844692230225
brightness 1.0597143173217773
contrast 0.44191575050354004
elastic_transform 0.877924919128418
pixelate 0.4538998603820801
jpeg_compression 0.47989392280578613
speckle_noise 0.6127912998199463
gaussian_blur 1.788027048110962
spatter 1.2991032600402832
saturate 1.558685064315796
Hvitgar commented 5 years ago

We already noticed that glass blur takes a lot of time. But as we wanted to make sure that the corruptions provided in this package function in the same way as the original imagenet-c corruptions provided by Dan Hendrycks, we kept the implementation as it was. However, we are open to ideas on how to speed glass blur up without changing the way the corruption works. I will leave this open for discussion, although this is not a bug.

xiangning-chen commented 4 years ago

Hi, thanks for your awesome work! Since the processing speed is quite slow, can you provide a public link for us to download the corrupted datasets?

michaelisc commented 3 years ago

Solved in #18