peal.data.transformations.DiffusionAugmentation¶
- class peal.data.transformations.DiffusionAugmentation[source]¶
Bases:
objectAugment images by a stochastic encode/decode round trip through a generator.
The generator (built with
get_generatorand moved to CUDA if available) encodes the image up tosampling_time_fractionof the diffusion process withstochastic="fully"and decodes it again stochastically, yielding a plausible variation of the input. Value ranges are converted via the dataset’sproject_to_pytorch_default/project_from_pytorch_defaulton both sides.- Parameters:
generator (
strordictorGeneratorInterface) – Generator specification accepted byget_generator.sampling_time_fraction (
float) – Fraction of the diffusion time the image is noised to.num_discretization_steps (
int) – Number of sampler steps for encoding and decoding.dataset (
PealDataset, optional) – Dataset whose value range the input lives in. IfNonethe input is assumed to already be in the pytorch default range.
Methods
- __init__(generator, sampling_time_fraction, num_discretization_steps, dataset=None)[source]¶
Build the generator on the best available device and store the knobs.
- __call__(img)[source]¶
Return a diffusion-resampled variant of
img.- Parameters:
img (
torch.Tensor) – Image[C, H, W]or batch[B, C, H, W]in the value range ofdataset(or the pytorch default range if no dataset is set).- Returns:
Reconstructed image(s) with the same shape and value range. Note that the result stays on the generator’s device.
- Return type: