DownsamplingGenerator#

class deepinv.physics.generator.DownsamplingGenerator(filters=['gaussian', 'bilinear', 'bicubic'], factors=[2, 4], psf_size=None, rng=None, device='cpu', dtype=torch.float32)[source]#

Bases: PhysicsGenerator

Random downsampling generator.

Generates random downsampling factors and filters. This can be used for generating parameters to be passed to the Downsampling class.

>>> from deepinv.physics.generator import DownsamplingGenerator
>>> list_filters = ["bilinear", "bicubic", "gaussian"]
>>> list_factors = [2, 4]
>>> generator = DownsamplingGenerator(filters=list_filters, factors=list_factors)
>>> ds = generator.step(batch_size=1)  # dict_keys(['filter', 'factor'])
>>> filter = ds['filter']
>>> factor = ds['factor']

Note

If batch size = 1, a random filter and factor is sampled in (filters, factors) at each step. If batch size > 1, a unique factor needs to be sampled for the whole batch, but filters can vary. In this case, it is recommended to set the psf_size argument to ensure that all filters in the batch have the same shape.

Parameters:
  • filters (list[str]) – list of filters to use for downsampling. Default is [“gaussian”, “bilinear”, “bicubic”].

  • factors (list[int]) – list of factors to use for downsampling. Default is [2, 4].

  • psf_size (tuple[int, int]) – size of the point spread function (PSF) to use for the filters, necessary to stack different filters. If None, the default size of the filter from the filter functions will be used. Default is None.

  • rng (Generator) – random number generator. Default is None.

  • device (str) – device to use. Default is “cpu”.

  • dtype (type) – data type to use. Default is torch.float32.

get_kernel(filter_str=None, factor=None)[source]#

Returns a batched tensor of filters associated to a given filter name and factor.

Parameters:
  • filter_str (str) – filter name. Default is None.

  • factor (int) – downsampling factor. Default is None.

step(batch_size=1, seed=None)[source]#

Generates a random downsampling factor and filter.

Parameters:
  • batch_size (int) – batch size. Default is 1.

  • seed (int) – seed for random number generator. Default is None.

str2filter(filter_name, factor)[source]#

Returns the filter associated to a given filter name and factor.