aleju / imgaug

Image augmentation for machine learning experiments.

Home Page:http://imgaug.readthedocs.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

AddToBrightness not deterministic/reproducible

kriskorrel-cw opened this issue · comments

I have found that the result of AddToBrightness is not deterministic, even when a seed is provided. Given that other probabilistic augmentations such as Dropout do seem to be deterministic when a seed is provided, I assume this is unexpected behavior.

The behavior can be reproduced with the following snippet:

import hashlib

import imgaug
import numpy as np
from imgaug.augmenters import AddToBrightness, Dropout, Sequential
from numpy.random import default_rng

numpy_random_generator = default_rng(seed=42)
image = numpy_random_generator.integers(0, 255, (200, 200, 3), dtype=np.uint8)

imgaug_random_generator = imgaug.random.RNG(numpy_random_generator)
sequential = Sequential(
    children=[
        AddToBrightness(seed=imgaug_random_generator),
        Dropout(seed=imgaug_random_generator),
    ],
    seed=imgaug_random_generator,
)

image = sequential.augment_image(image)


def hash_image(image):
    md5_hash = hashlib.md5()
    md5_hash.update(image.data.tobytes())
    return int(md5_hash.hexdigest(), 16)


print(hash_image(image))

When running this code, the hash will be different each time. I expect the hash to be the same each time, as the seed is provided.
When commenting out AddToBrightness and only applying Dropout augmentation, the seed is the same on each run.