lucent.optvis.param package
param.color module
- lucent.optvis.param.color.to_valid_rgb(image_f: Callable, decorrelate: Optional[bool] = False) Callable
Converts image function to one with valid rgb values in [0,1] via sigmoid and potentially decorrelates the color channels
- Parameters
image_f (Callable) – Original image function
decorrelate (Optional[bool], optional) – Whether to decorrelate colors, defaults to False
- Returns
New image function
- Return type
Callable
param.cppn module
- class lucent.optvis.param.cppn.CompositeActivation
Bases:
Module
- forward(x)
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- training: bool
- lucent.optvis.param.cppn.cppn(size: int, num_output_channels: ~typing.Optional[int] = 3, num_hidden_channels: ~typing.Optional[int] = 24, num_layers: ~typing.Optional[int] = 8, activation_fn: ~typing.Optional[~torch.nn.modules.module.Module] = <class 'lucent.optvis.param.cppn.CompositeActivation'>, normalize: ~typing.Optional[bool] = False) Tuple[Iterator, Callable]
Creates cppn parameterization.
- Parameters
size (int) – image size
num_output_channels (Optional[int], optional) – number of output channels, defaults to 3
num_hidden_channels (Optional[int], optional) – number of hidden channels, defaults to 24
num_layers (Optional[int], optional) – number of layers, defaults to 8
activation_fn (Optional[torch.nn.Module], optional) – activation function after hidden layers, defaults to CompositeActivation
normalize (Optional[bool], optional) – Whether to use instance normalization after each hidden layer, defaults to False
- Returns
Iterator over network parameters and a function that returns the network’s output on the grid [-sqrt(3), sqrt(3)] with step size
size
.- Return type
Tuple[Iterator, Callable]
param.gan module
Copyright 2020 Binxu Wang Use GAN as prior to do feature visualization. This method is inspired by the work
Nguyen, A., Dosovitskiy, A., Yosinski, J., Brox, T., & Clune, J. Synthesizing the preferred inputs for neurons in neural networks via deep generator networks.(2016) NIPS
- The GAN model is imported from
A. Dosovitskiy, T. Brox Generating Images with Perceptual Similarity Metrics based on Deep Networks (2016), NIPS. https://lmb.informatik.uni-freiburg.de/people/dosovits/code.html
the author translated the models (pool5-fc8) into pytorch and hosts the weights online.
Jun.4th 2020
- class lucent.optvis.param.gan.UpConvGAN(name='fc6', pretrained=True)
Bases:
Module
- forward(x)
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- training: bool
- visualize(x, scale=1.0)
- lucent.optvis.param.gan.load_statedict_from_online(name='fc6')
param.images module
High-level wrapper for paramaterizing images.
- lucent.optvis.param.images.image(w: int, h: Optional[int] = None, sd: Optional[float] = 0.01, batch: Optional[int] = 1, decorrelate: Optional[bool] = True, fft: Optional[bool] = True, channels: Optional[int] = None) Tuple[List[Tensor], Callable]
Creates image parameterization either via rgb or fft.
- Parameters
w (int) – image width
h (Optional[int], optional) – image height, if None will be the same as
w
, defaults to Nonesd (Optional[float], optional) – standard deviation of random init, defaults to 0.01
batch (Optional[int], optional, defaults to 1.) – [description], defaults to None
decorrelate (Optional[bool], optional) – [description], defaults to True
fft (Optional[bool], optional) – [description], defaults to True
channels (Optional[int], optional) – number of channels - if None will be set to 3, defaults to None
- Returns
[description]
- Return type
Tuple[List[torch.Tensor], Callable]
param.lowres module
Provides lowres_tensor().
- lucent.optvis.param.lowres.lowres_tensor(shape: Union[List, Tuple, Size], underlying_shape: Union[List, Tuple, Size], offset: Optional[Union[bool, int, List]] = None, sd: Optional[float] = 0.01) Tuple[List[Tensor], Callable]
Produces a tensor paramaterized by a interpolated lower resolution tensor. This is like what is done in a laplacian pyramid, but a bit more general. It can be a powerful way to describe images.
- Parameters
shape (Union[List, Tuple, torch.Size]) – desired shape of resulting tensor, should be of format (B, C, H, W) #TODO support more shapes
underlying_shape (Union[List, Tuple, torch.Size]) – shape of the tensor being resized into final tensor
offset (Optional[Union[bool, int, List]], optional) – Describes how to offset the interpolated vector (like phase in a Fourier transform). If None, apply no offset. If int, apply the same offset to each dimension; if a list use each entry for each dimension. If False, do not offset. If True, offset by half the ratio between shape and underlying shape (analogous to 90 degrees), defaults to None
sd (Optional[float], optional) – Standard deviation of initial tensor variable., defaults to 0.01
- Returns
One-element list containing the low resolution tensor and the corresponding image function returning the tensor on call.
- Return type
Tuple[List[torch.Tensor], Callable]
param.spatial module
- lucent.optvis.param.spatial.fft_image(shape: Union[List, Tuple, Size], sd: Optional[float] = 0.01, decay_power: Optional[int] = 1) Tuple[List[Tensor], Callable]
Image parameterization via fft spectrum
- Parameters
shape (Union[List, Tuple, torch.Size]) – Image shape
sd (Optional[float], optional) – Standard deviation for initializing distribution, defaults to 0.01
decay_power (Optional[int], optional) – Decay power to dampen scaling, defaults to 1
- Returns
One-element list containing image parameters and image function returning the image on call.
- Return type
Tuple[List[Tensor], Callable]
- lucent.optvis.param.spatial.pixel_image(shape: Union[List, Tuple, Size], sd: Optional[float] = 0.01) Tuple[List[Tensor], Callable]
Pixel parameterization of an image with given shape.
Init via zero-mean normal distribution with given standard deviation.
- Parameters
shape (Union[List, Tuple, torch.Size]) – Shape of image
sd (Optional[float], optional) – Standard deviation of initializing distribution, defaults to 0.01
- Returns
one-element list containing image parameters and image function returning the image on call.
- Return type
Tuple[List[torch.Tensor], Callable]
- lucent.optvis.param.spatial.rfft2d_freqs(h: int, w: int) ndarray
Computes 2D spectrum frequencies of an image with given dimensions.
From https://github.com/tensorflow/lucid/blob/master/lucid/optvis/param/spatial.py .
- Parameters
h (int) – image height
w (int) – image width
- Returns
2D spectrum frequencies
- Return type
np.ndarray