Skip to content

[Feature request] Random Number state or generator #1082

Open
@ternaus

Description

@ternaus

Context of the request

cv2.randnis materially faster than np.random to generate arrays of random numbers, would love to use in Albumentations library everywhere.

One limitation is reproducibility.

I prefer to fix seed for random number generator at the level of instance, and not global level.

I.e.

transform = A.Compose([A.HorizontalFlip(p=0.5)], seed=137)

=> get same sequence of random transforms every time I run the code.

To make it possible Compose has under the hood:

        self.random_generator = np.random.default_rng(seed)
        self.py_random = random.Random(seed)

and all random things are sampled using either of these generators.


Request:

I would like to do similar thing with cv2.randn. It would be great to have something like cv2.random.default_rng(seed) or cv2.random.Random(seed),

or at least to be able to pass seed like cv2.randn(dst=gaussian_sampled_arr, mean=mean_vector, stddev=std_dev_vector, seed=seed) to the functions.

Currently we can fix seed in opencv globally with cv2.setRNGSeed(cv2_seed), but it could mess things up if other parts of the pipeline depend on the seed as well.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions