torchelie.data_learning

class torchelie.data_learning.CorrelateColors

Takes an learnable image and applies the inverse color decorrelation from ImageNet (ie, it correlates the color like ImageNet to ease optimization)

invert(t: torch.Tensor)torch.Tensor

Decorrelate the color of the image t and return the result

class torchelie.data_learning.ParameterizedImg(*shape: int, init_sd: float = 0.06, init_img: Optional[torch.Tensor] = None, space: typing_extensions.Literal[spectral, pixel] = 'spectral', colors: typing_extensions.Literal[uncorr, corr] = 'uncorr')

A convenient wrapper around PixelImage and SpectralImage and CorrelateColors to make a learnable image.

Parameters
  • *shape (int) – shape of the image: channel, height, width

  • init_sd (float) – standard deviation for initializing the image if init_img is None

  • init_img (tensor) – an image to use as initialization

  • space (str) – either “pixel” or “spectral” to have the underlying representation be a PixelImage or a SpectralImage

  • colors (str) – either “corr” or “uncorr”, to use a correlated or decorrelated color space

forward()

Return the tensor

render()

Return the tensor on cpu and detached, ready to be transformed to a PIL image

class torchelie.data_learning.PixelImage(shape: Tuple[int, ], sd: float = 0.01, init_img: Optional[torch.Tensor] = None)

A learnable image parameterized by its pixel values

Parameters
  • shape (tuple of int) – a tuple like (channels, height, width)

  • sd (float) – pixels are initialized with a random gaussian value of mean 0.5 and standard deviation sd

  • init_img (tensor, optional) – an image tensor to initialize the pixel values

forward()

Return the image

class torchelie.data_learning.SpectralImage(shape: Tuple[int, ], sd: float = 0.01, decay_power: int = 1, init_img: Optional[torch.Tensor] = None)

A learnable image parameterized by its Fourier representation.

See https://distill.pub/2018/differentiable-parameterizations/

Implementation ported from https://github.com/tensorflow/lucid/blob/master/lucid/optvis/param/spatial.py

Parameters
  • shape (tuple of int) – a tuple like (channels, height, width)

  • sd (float) – amplitudes are initialized with a random gaussian value of mean 0.5 and standard deviation sd

  • init_img (tensor, optional) – an image tensor to initialize the image

forward()torch.Tensor

Return the image