pystiche_papers.gatys_et_al_2017

Title

Controlling Perceptual Factors in Neural Style Transfer

Authors

Leon A. Gatys, Alexander. S. Ecker, Matthias Bethge,

Aaron Hertzmann, and Eli Shechtman

Citation

[GEB+2017]

Reference implementation

Repository / Archive

Variant

Image optimization

Content loss

FeatureReconstructionLoss

Style loss

GramLoss

Behavioral changes

The following parts are affected:

Hyper parameters

content_loss()

Parameter

impl_params

True

False

layer

"relu4_2"

"conv4_2"

score_weight

1e0

style_loss()

Parameter

impl_params

True

False

layers

("relu1_1", "relu2_1", "relu3_1", "relu4_1", "relu5_1")

("conv1_1", "conv2_1", "conv3_1", "conv4_1", "conv5_1")

layer_weights

(2.4e-04, 6.1e-05, 1.5e-05, 3.8e-06, 3.8e-06) 1

score_weight

1e3 1

guided_style_loss()

Parameter

impl_params

True

False

layers

("relu1_1", "relu2_1", "relu3_1", "relu4_1", "relu5_1")

("conv1_1", "conv2_1", "conv3_1", "conv4_1", "conv5_1")

layer_weights

(2.4e-04, 6.1e-05, 1.5e-05, 3.8e-06, 3.8e-06) 1 2

region_weights

"sum"

score_weight

1e3 1

image_pyramid()

Parameter

impl_params

True

False

edge_sizes

(500, 1024) 3

(512, 1024)

num_steps

4

(500, 200)

1(1,2,3,4)

The values are reported in the supplementary material.

2

The layer_weights are computed by \(1 / n^2\) where \(n\) denotes the number of channels of a feature map from the corresponding layer in the multi_layer_encoder().

3

The paper only reports the edge_size for the low resolution.

4

The paper only reports the ratio. i.e. \(500 / 200 = 2.5\) of num_steps.

API

pystiche_papers.gatys_et_al_2017.images()
Return type

DownloadableImageCollection

pystiche_papers.gatys_et_al_2017.content_loss(multi_layer_encoder=None, hyper_parameters=None)

Content_loss from [GEB+2017].

Parameters
Return type

FeatureReconstructionLoss

class pystiche_papers.gatys_et_al_2017.MultiLayerEncodingLoss(multi_layer_encoder, layers, encoding_loss_fn, impl_params=True, **multi_layer_encoding_op_kwargs)

Multi-layer encoding Loss from [GEB+2017].

Parameters
  • multi_layer_encoder (MultiLayerEncoder) – Multi-layer encoder.

  • layers (Sequence[str]) – Layers of the multi_layer_encoder that the children losses operate on.

  • get_encoding_op – Callable that returns a children Loss given a pystiche.enc.SingleLayerEncoder extracted from the multi_layer_encoder and its corresponding layer weight.

  • impl_params (bool) – If False, use a score correction factor of 1/4.

  • **multi_layer_encoding_op_kwargs – Additional parameters of a pystiche.loss.MultiLayerEncodingLoss.

pystiche_papers.gatys_et_al_2017.style_loss(impl_params=True, multi_layer_encoder=None, hyper_parameters=None)

Style_loss from [GEB+2017].

Parameters
Return type

MultiLayerEncodingLoss

pystiche_papers.gatys_et_al_2017.guided_style_loss(regions, impl_params=True, multi_layer_encoder=None, hyper_parameters=None)

Guided style_loss from [GEB+2017].

Parameters
Return type

MultiRegionLoss

pystiche_papers.gatys_et_al_2017.perceptual_loss(impl_params=True, multi_layer_encoder=None, hyper_parameters=None)

Perceptual loss from [GEB+2017].

Parameters
Return type

PerceptualLoss

pystiche_papers.gatys_et_al_2017.guided_perceptual_loss(regions, impl_params=True, multi_layer_encoder=None, hyper_parameters=None)

Guided perceptual loss from [GEB+2017].

Parameters
Return type

PerceptualLoss

pystiche_papers.gatys_et_al_2017.nst(content_image, style_image, impl_params=True, hyper_parameters=None, quiet=False)

NST from [GEB+2017].

Parameters
  • content_image (Tensor) – Content image for the NST.

  • style_image (Tensor) – Style image for the NST.

  • impl_params (bool) – Switch the behavior and hyper-parameters between the reference implementation of the original authors and what is described in the paper. For details see here.

  • hyper_parameters (Optional[HyperParameters]) – If omitted, hyper_parameters() is used.

  • quiet (bool) – If True, not information is logged during the optimization. Defaults to False.

Return type

Tensor

pystiche_papers.gatys_et_al_2017.guided_nst(content_image, content_guides, style_images_and_guides, impl_params=True, hyper_parameters=None, quiet=False)

Guided NST from [GEB+2017].

Parameters
  • content_image (Tensor) – Content image for the guided NST.

  • content_guides (Dict[str, Tensor]) – Content image guides for the guided NST.

  • style_images_and_guides (Dict[str, Tuple[Tensor, Tensor]]) – Dictionary with the style images and the corresponding guides for each region.

  • impl_params (bool) – Switch the behavior and hyper-parameters between the reference implementation of the original authors and what is described in the paper. For details see here.

  • hyper_parameters (Optional[HyperParameters]) – If omitted, hyper_parameters() is used.

  • quiet (bool) – If True, not information is logged during the optimization. Defaults to False.

Return type

Tensor

pystiche_papers.gatys_et_al_2017.image_pyramid(hyper_parameters=None, **image_pyramid_kwargs)

Image pyramid from [GEB+2017].

Parameters
Return type

ImagePyramid

pystiche_papers.gatys_et_al_2017.preprocessor()
Return type

CaffePreprocessing

pystiche_papers.gatys_et_al_2017.postprocessor()
Return type

CaffePostprocessing

pystiche_papers.gatys_et_al_2017.multi_layer_encoder()

Multi-layer encoder from [GEB+2017].

Return type

MultiLayerEncoder

pystiche_papers.gatys_et_al_2017.optimizer(input_image)

Optimizer from [GEB+2017].

Parameters

input_image (Tensor) – Image to be optimized.

Return type

LBFGS

pystiche_papers.gatys_et_al_2017.compute_layer_weights(layers, multi_layer_encoder=None)
Return type

Tuple[float, ...]

pystiche_papers.gatys_et_al_2017.hyper_parameters(impl_params=True)

Hyper parameters from [GEB+2017].

Return type

HyperParameters