Skip to content

Commit

Permalink
Use request's random seed in NoiseAugment
Browse files Browse the repository at this point in the history
  • Loading branch information
funkey committed Sep 3, 2023
1 parent 93a7d8b commit 8f8b6aa
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions gunpowder/nodes/noise_augment.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,15 @@ class NoiseAugment(BatchFilter):
Type of noise to add, see scikit-image documentation.
seed (``int``):
Optionally set a random seed, see scikit-image documentation.
clip (``bool``):
Whether to preserve the image range (either [-1, 1] or [0, 1]) by clipping values in the end, see
scikit-image documentation
"""

def __init__(self, array, mode="gaussian", seed=None, clip=True, **kwargs):
def __init__(self, array, mode="gaussian", clip=True, **kwargs):
self.array = array
self.mode = mode
self.seed = seed
self.clip = clip
self.kwargs = kwargs

Expand All @@ -58,6 +53,18 @@ def process(self, batch, request):
assert (
raw.data.min() >= -1 and raw.data.max() <= 1
), "Noise augmentation expects raw values in [-1,1] or [0,1]. Consider using Normalize before."
raw.data = skimage.util.random_noise(
raw.data, mode=self.mode, rng=self.seed, clip=self.clip, **self.kwargs
).astype(raw.data.dtype)

seed = request.random_seed

try:

raw.data = skimage.util.random_noise(
raw.data, mode=self.mode, rng=seed, clip=self.clip, **self.kwargs
).astype(raw.data.dtype)

except ValueError:

# legacy version of skimage random_noise
raw.data = skimage.util.random_noise(
raw.data, mode=self.mode, seed=seed, clip=self.clip, **self.kwargs
).astype(raw.data.dtype)

0 comments on commit 8f8b6aa

Please sign in to comment.