albumentations-team / albumentations

Fast and flexible image augmentation library. Paper about the library: https://www.mdpi.com/2078-2489/11/2/125
https://albumentations.ai
MIT License
14.13k stars 1.64k forks source link

Add non-uniform sampling option for parameters #1208

Open zakajd opened 2 years ago

zakajd commented 2 years ago

Problem Currently most augmentation use simple random.uniform(lower_bound, upper_bound) sampling rule to select the parameters to applied. This makes all value in [lower, upper] range equally likely to occur.

If someone, for example, uses RandomGamma(gamma_limit=[60, 140]) this will produce extremely damaged images (gamma=60 or gamma=140) roughly as often as slightly damaged images (gamma close to 100). In some domains real distribution of parameters is also non-uniform, so having a way to sample slightly damaged images more often will be beneficial.

Proposal Add option (flag?) to switch from uniform sampling to other types. Say, gaussian (skewed) sampling.

zakajd commented 2 years ago

@Dipet I'd like to work on this one. Any ideas how to better implement switching between different samplings?

Ideally, this option should be available for all transforms out of the box.

Dipet commented 2 years ago

Interesting question. We have wrapper functions for numpy random module. I think we need to create some base class that would represent sampling strategy. When we will create some random sampled value we will wrap this value into this wrapper and on call get_params we will just call sample method for this variable. Something like random logic in imgaug https://github.com/aleju/imgaug/blob/0101108d4fed06bc5056c4a03e2bcb0216dac326/imgaug/random.py

RieGo commented 1 week ago

I would love this feature. natural sampling seems the best choice for augmentation generally speaking. Is this still planned?

ternaus commented 1 week ago

I can look into this.