API#
Synthesis objects#
Synthesis objects generate novel stimuli which allow researchers to better understand how their computational models make sense of their inputs.
Synthesize metamers for image-computable differentiable models. |
|
Synthesize model metamers with coarse-to-fine synthesis. |
|
Synthesize eigendistortions induced by a model on a given input image. |
|
Synthesize a single maximally-differentiating image for two metrics. |
Models#
Models give a response to a single stimulus and are compatible with Metamer and Eigendistortion, and can be turned into Metrics by using the model_metric_factory function.
See Model requirements for more details.
Portila-Simoncelli texture statistics. |
LGN-inspired Models
These “front end” models are inspired by the lateral geniculate nucleus (LGN; the first non-retinal stage of the primate visual system), come from Berardino et al., 2017, and are nested, increasing in complexity as you move down the list.
Linear-Nonlinear model. |
|
Linear center-surround followed by luminance gain control and activation. |
|
Center-surround followed by luminance and contrast gain control, then activation. |
|
On-off and off-on center-surround with contrast and luminance gain control. |
The following models are used to construct the models above. They are probably most useful in the construction of other, more complex models, but they are compatible with our synthesis methods.
Simple class that just returns a copy of the image. |
|
Simplistic linear convolutional model. |
|
Isotropic Gaussian convolutional filter. |
|
Center-Surround, Difference of Gaussians (DoG) filter model. |
Metrics#
Metrics compare two stimuli and are compatible with MADCompetition.
See Metric requirements for more details.
Return the MSE between img1 and img2. |
|
Create a metric function which returns the root mean squared error in model space. |
|
Compute the structural similarity index. |
|
Multiscale structural similarity index (MS-SSIM). |
|
Compute the normalized Laplacian Pyramid Distance. |
Commonly-used helper functions#
The following helper functions are commonly-used when preparing data and models for use with plenoptic.
Detach all parameters and buffers of model (in place). |
|
Set the seed. |
|
Load in images. |
|
Cast tensor to numpy in the most conservative way possible. |
|
Convert numpy array from float to 8 or 16 bit integer. |
Plotting functions#
Synthesis objects
These functions all are intended to help visualize the status and outputs of synthesis objects. The following accept all synthesis classes:
Display image of synthesis object. |
|
Plot histogram of values of synthesis objects. |
|
Make a plot showing synthesis status. |
The following accept Metamer / MetamerCTF and MADCompetition objects:
Plot synthesis loss. |
|
Animate synthesis progress. |
The following accept only objects of a single class.
Metamer / MetamerCTF
Plot representation error showing how close we are to convergence. |
MADCompetition
Display all MAD Competition images. |
|
Plot loss for full set of MAD Competiton instances. |
Eigendistortion
Display base image, eigendistortions alone, and eigendistortions added to the image. |
Tensors
The following functions can be used to visualize torch.Tensor objects directly: images, videos, and model representations.
Show image(s), avoiding interpolation. |
|
Animate video(s), avoiding interpolation. |
|
Display steerable pyramid coefficients in orderly fashion. |
|
Plot model representation. |
|
Create a simple stem plot. |
|
Plot histogram of values from tensor. |
|
Update the information in some axes (for an animation). |
Image-processing methods#
These classes and functions all process images in some way, and thus may be helpful for constructing your own models or metrics. As is, they are not compatible with any of the synthesis methods.
Metric components
These functions are used by the Metrics. While they are not compatible with any of our synthesis methods, they may be useful to better understand the behavior of their respective metrics.
Structural similarity index map. |
|
Compute the normalized Laplacian Pyramid using pre-optimized parameters. |
Image pyramids
Image pyramids decompose images into bands corresponding to different spatial frequencies and orientations. As we often think of neurons in the early visual system as similarly only responding to a range of spatial frequencies and/or orientations, these pyramids can be used to construct a model of those early areas.
See pyrtools for more information, including links to resources for learning more.
Laplacian Pyramid in Torch. |
|
Steerable frequency pyramid in Torch. |
Filter construction functions
These convenience functions make it easier to construct some commonly-used filters.
Create normalized, centered circular 2D gaussian tensor with which to convolve. |
Coordinate transformations
This related set of functions convert between the rectangular and polar representations of a signal (or computing the norm and direction, which are the analogues for real-valued signals).
Rectangular to polar coordinate transform. |
|
Polar to rectangular coordinate transform. |
|
Spatially local gain control. |
|
Spatially local gain release. |
|
Return the complex amplitude and the phase of each complex tensor in a dictionary. |
|
Return the real and imaginary parts of tensor in a dictionary. |
|
Spatially local gain control, for each element in a dictionary. |
|
Spatially local gain release, for each element in a dictionary. |
The following table summarizes the relationship among these functions (where ➡ denotes from rectangular to polar and ⬅ is the inverse):
function |
dtype |
input object |
direction |
|---|---|---|---|
rectangular_to_polar |
|
|
➡ |
polar_to_rectangular |
|
|
⬅ |
local_gain_control |
|
|
➡ |
local_gain_release |
|
|
⬅ |
rectangular_to_polar_dict |
|
|
➡ |
polar_to_rectangular_dict |
|
|
⬅ |
local_gain_control_dict |
|
|
➡ |
local_gain_release_dict |
|
|
⬅ |
Image resizing
The following functions return a version of their input whose size has increased or decreased without further modifying its contents.
Correlate with a filter and downsample by a factor of 2. |
|
Correlate with a named filter and downsample by 2. |
|
Upsample by 2 and convolve with a filter. |
|
Upsample by 2 and convolve with named filter. |
|
Pad a tensor so that 2D convolution will result in output with same dims. |
|
Shrink a signal by a factor. |
|
Expand a signal by a factor. |
Image modification
The following functions return a modified version of their input.
Linearly rescale the dynamic range of the input to |
|
Add normally distributed noise to an image. |
|
Crop out the center of a signal. |
|
Modulate the phase of a complex signal. |
Image statistics
The following functions compute summary statistics of their inputs.
Compute the autocorrelation of |
|
Calculate sample variance. |
|
Calculate sample estimate of asymmetry about input's mean. |
|
Calculate sample estimate of tailedness (presence of outliers). |
Loading, creating, and accessing images#
Example images
Plenoptic includes a small number of example images, which are used throughout the documentation.
Return an example grayscale image of Albert Einstein. |
|
Return an example grayscale image of Marie Curie. |
|
Return an example grayscale image of a parrot. |
|
Return an example grayscale image of reptile skin. |
|
Return an example image of a color wheel. |
Plenoptic includes a helper function for downloading additional data, which includes example synthesis objects and additional images.
Download data, using pooch. |
|
Built-in mutable sequence. |
Synthetic images
The following functions create synthetic image tensors. See pyrtools.tools.synthetic_images for more synthetic images.
Create a circular mask with softened edges. |
|
Make distance-from-origin (r) matrix. |
|
Make polar angle matrix (in radians). |
Validation#
The following functions are used to validate that the user-supplied inputs are compatible with our synthesis objects.
Determine whether model can be used for synthesis. |
|
Determine whether |
|
Determine whether a metric can be used for MADCompetition synthesis. |
|
Determine whether a model can be used for coarse-to-fine synthesis. |
|
Determine if a model can properly convert between tensor and dict representations. |
|
Determine whether |
Optimization#
Loss functions
The following functions can be used as the loss_function argument for Metamer and MetamerCTF.
Calculate the MSE between |
|
Calculate the L2-norm of the difference between |
|
Calculate the relative sum of squared errors between two tensors. |
Loss function factories
The following functions return a function that can be used as a loss_function, as above.
Create the loss function required for |
|
Create loss function that computes groupwise relative L2 norm for synthesis. |
Penalty functions
The following functions operate as penalties.
Calculate quadratic penalty on values outside of |
Debugging#
Functions to help understand when things have gone wrong.
Examine saved synthesis object. |
|
Custom warning to raise if there's an issue with loading. |
External#
Functions for interacting with other code and packages.
Plot original MAD results, provided by Zhou Wang. |