pystiche.pyramid

Image pyramid

class pystiche.pyramid.ImagePyramid(edge_sizes, num_steps, edge='short', interpolation_mode='bilinear', resize_targets=())

Image pyramid for a coarse-to-fine optimization on different levels. If iterated on yields PyramidLevel s and handles the resizing of all set images and guides of resize_targets.

Parameters
  • edge_sizes (Sequence[int]) – Edge sizes for each level.

  • num_steps (Union[Sequence[int], int]) – Number of steps for each level. If sequence of int its length has to match the length of edge_sizes.

  • edge (Union[Sequence[str], str]) – Corresponding edge to the edge size for each level. Can be "short" or "long". If sequence of str its length has to match the length of edge_sizes. Defaults to "short".

  • interpolation_mode (str) –

    Interpolation mode used for the resizing of the images. Defaults to "bilinear".

    Note

    For the resizing of guides "nearest" is used regardless of the interpolation_mode.

  • resize_targets (Collection[Loss]) – Targets for resizing of set images and guides during iteration.

class pystiche.pyramid.OctaveImagePyramid(max_edge_size, num_steps, num_levels=None, min_edge_size=64, **image_pyramid_kwargs)

Bases: pystiche.pyramid.pyramid.ImagePyramid

Image pyramid that comprises levels spaced by a factor of two.

Parameters
  • max_edge_size (int) – Maximum edge size.

  • num_steps (Union[int, Sequence[int]]) –

    Number of steps for each level.

    Note

    If num_steps is specified as sequence of int``s, you should also specify ``num_levels to match the lengths

  • num_levels (Optional[int]) – Optional number of levels. If None, the number is determined by the number of steps of factor two between max_edge_size and min_edge_size.

  • min_edge_size (int) – Minimum edge size for the automatic calculation of num_levels.

  • image_pyramid_kwargs (Any) – Additional options. See ImagePyramid for details.

Pyramid level

class pystiche.pyramid.PyramidLevel(edge_size, num_steps, edge)

Level with an pystiche.pyramid.ImagePyramid. If iterated on, yields the step beginning at 1 and ending in num_steps.

Parameters
  • edge_size (int) – Edge size.

  • num_steps (int) – Number of steps.

  • edge (str) – Corresponding edge to the edge size. Can be "short" or "long".

resize_guide(guide, aspect_ratio=None, interpolation_mode='nearest')

Resize a guide to the edge_size on the corresponding edge of the PyramidLevel.

Parameters
  • guide (Tensor) – Guide to be resized.

  • aspect_ratio (Optional[float]) – Optional aspect ratio of the output. If None, the aspect ratio of guide is used. Defaults to None.

  • interpolation_mode (str) – Interpolation mode used to resize image. Defaults to "nearest".

Return type

Tensor

resize_image(image, aspect_ratio=None, interpolation_mode='bilinear')

Resize an image to the edge_size on the corresponding edge of the PyramidLevel.

Parameters
  • image (Tensor) – Image to be resized.

  • aspect_ratio (Optional[float]) – Optional aspect ratio of the output. If None, the aspect ratio of image is used. Defaults to None.

  • interpolation_mode (str) – Interpolation mode used to resize image. Defaults to "bilinear".

Warning

The resizing is performed without gradient calculation. Do not use this if the image needs a gradient.

Return type

Tensor