Skip to content

Commit

Permalink
Moved more to inplace
Browse files Browse the repository at this point in the history
  • Loading branch information
ternaus committed Nov 1, 2024
1 parent 628aa57 commit 9b1f987
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
9 changes: 4 additions & 5 deletions albumentations/augmentations/functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import numpy as np
from albucore import (
MAX_VALUES_BY_DTYPE,
add,
add_array,
add_constant,
add_weighted,
Expand Down Expand Up @@ -117,10 +116,10 @@ def shift_hsv(img: np.ndarray, hue_shift: float, sat_shift: float, val_shift: fl
hue = sz_lut(hue, lut_hue, inplace=False)

if sat_shift != 0:
sat = add_constant(sat, sat_shift)
sat = add_constant(sat, sat_shift, inplace=True)

if val_shift != 0:
val = add_constant(val, val_shift)
val = add_constant(val, val_shift, inplace=True)

img = cv2.merge((hue, sat, val))
img = cv2.cvtColor(img, cv2.COLOR_HSV2RGB)
Expand Down Expand Up @@ -1589,7 +1588,7 @@ def unsharp_mask(

soft_mask = blur_fn(mask)

return add(multiply(sharp, soft_mask), multiply(image, 1 - soft_mask))
return add_array(multiply(sharp, soft_mask), multiply(image, 1 - soft_mask), inplace=True)


@preserve_channel_dim
Expand Down Expand Up @@ -1880,7 +1879,7 @@ def generate_approx_gaussian_noise(

@clipped
def add_noise(img: np.ndarray, noise: np.ndarray) -> np.ndarray:
return add_array(img, noise)
return add_array(img, noise, inplace=False)


def swap_tiles_on_keypoints(
Expand Down
4 changes: 2 additions & 2 deletions albumentations/augmentations/geometric/functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import cv2
import numpy as np
from albucore import get_num_channels, hflip, maybe_process_in_chunks, preserve_channel_dim, vflip
from albucore import get_num_channels, hflip, maybe_process_in_chunks, multiply_by_constant, preserve_channel_dim, vflip

from albumentations.augmentations.utils import angle_2pi_range, handle_empty_array
from albumentations.core.bbox_utils import bboxes_from_masks, denormalize_bboxes, masks_from_bboxes, normalize_bboxes
Expand Down Expand Up @@ -1512,7 +1512,7 @@ def generate_noise_field() -> np.ndarray:
elif noise_distribution == "uniform":
field = random_generator.uniform(low=-1, high=1, size=image_shape[:2]).astype(np.float32)
cv2.GaussianBlur(field, kernel_size, sigma, dst=field)
return field * alpha
return multiply_by_constant(field, alpha, inplace=True)

# Generate first displacement field
dx = generate_noise_field()
Expand Down

0 comments on commit 9b1f987

Please sign in to comment.