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

Improve performance of glass blur #683

Merged
merged 4 commits into from
May 31, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Relax numba requirement to 3.6+
  • Loading branch information
aleju committed May 30, 2020
commit db166e6919847e3d0bab8ede8013c02fc1b37bea
8 changes: 4 additions & 4 deletions changelogs/master/improved/20200530_glass_blur_perf.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

This patch improves the performance of
`imgaug.augmenters.imgcorruptplike.apply_glass_blur()`
and the corresponding augmenter. The improvement is
around 14x to 45x, depending on the image size
(larger images have more speedup).
and the corresponding augmenter in python 3.6+.
The improvement is around 14x to 45x, depending on
the image size (larger images have more speedup).

Added dependencies:
* `numba`
* `numba` (requires python 3.6+)
24 changes: 19 additions & 5 deletions imgaug/augmenters/imgcorruptlike.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,13 @@
import warnings

import numpy as np
import numba
import skimage.filters
import six.moves as sm
import skimage.filters
# numba cannot be installed in python <=3.5
try:
import numba
except ImportError:
numba = None

import imgaug as ia
from .. import dtypes as iadt
Expand Down Expand Up @@ -491,7 +495,9 @@ def _apply_glass_blur_imgaug(x, severity=1):
)
)

x = _apply_glass_blur_imgaug_loop(x, iterations, max_delta, dxxdyy)
x = _apply_glass_blur_imgaug_loop_dispatcher(
x, iterations, max_delta, dxxdyy
)

return np.clip(
skimage.filters.gaussian(x / 255., sigma=sigma, multichannel=True),
Expand All @@ -500,8 +506,16 @@ def _apply_glass_blur_imgaug(x, severity=1):


# Added in 0.5.0.
# fastmath seems to slow this down
@numba.jit(nopython=True, nogil=True)
def _apply_glass_blur_imgaug_loop_dispatcher(x, iterations, max_delta, dxxdyy):
func = _apply_glass_blur_imgaug_loop
# numba is None if it could not be imported
if numba is not None:
# fastmath seems to slow this down
func = numba.jit(func, nopython=True, nogil=True)
return func(x, iterations, max_delta, dxxdyy)


# Added in 0.5.0.
def _apply_glass_blur_imgaug_loop(
x, iterations, max_delta, dxxdyy
):
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ opencv-python-headless
imageio<=2.6.1; python_version<'3.5'
imageio; python_version>='3.5'
Shapely
numba
# numba is not available in <=3.5
numba; python_version>='3.6'