pystiche_papers.li_wand_2016
Title |
Combining Markov Random Fields and Convolutional Neural Networks for Image Synthesis |
Authors |
Chuan Li and Michael Wand |
Citation |
[LW2016] |
Reference implementation |
|
Variant |
Image optimization |
Content loss |
|
Style loss |
|
Regularization |
Behavioral changes
See also
The following parts are affected:
Hyper parameters
See also
content_loss()
Parameter |
|
|
---|---|---|
|
|
|
|
|
|
|
|
|
target_transforms()
Parameter |
|
|
---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
style_loss()
Parameter |
|
|
---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
regularization()
Parameter |
|
|
---|---|---|
|
|
|
|
|
image_pyramid()
Parameter |
|
|
---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- 1
num_levels=None
implies that the number of levels is automatically calculated depending onmax_edge_size
andmin_edge_size
. Seepystiche.pyramid.OctaveImagePyramid
for details.
API
- pystiche_papers.li_wand_2016.images()
- Return type
- class pystiche_papers.li_wand_2016.FeatureReconstructionLoss(encoder, impl_params=True, **feature_reconstruction_loss_kwargs)
Feature reconstruction loss from [LW2016].
- Parameters
encoder (
Encoder
) – Encoder used to encode the input.impl_params (
bool
) – IfFalse
, calculate the score with the squared error (SE) instead of the mean squared error (MSE).**feature_reconstruction_loss_kwargs – Additional parameters of a
pystiche.loss.FeatureReconstructionLoss
.
- pystiche_papers.li_wand_2016.content_loss(impl_params=True, multi_layer_encoder=None, hyper_parameters=None)
Content loss from [LW2016].
- Parameters
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.multi_layer_encoder (
Optional
[MultiLayerEncoder
]) – Pretrained multi-layer encoder. If omitted,multi_layer_encoder()
is used.hyper_parameters (
Optional
[HyperParameters
]) – Hyper parameters. If omitted,hyper_parameters()
is used.
- Return type
- class pystiche_papers.li_wand_2016.MRFLoss(encoder, patch_size, impl_params=True, **mrf_loss_kwargs)
MRF loss from [LW2016].
- Parameters
encoder (
Encoder
) – Encoder used to encode the input.patch_size (
Union
[int
,Tuple
[int
,int
]]) – Spatial size of the neural patches.impl_params (
bool
) – IfTrue
, normalize the gradient of the neural patches. IfFalse
, use a score correction factor of 1/2.**mrf_loss_kwargs – Additional parameters of a
pystiche.loss.MRFLoss
.
In contrast to
pystiche.loss.MRFLoss
, the score is calculated with the squared error (SE) instead of the mean squared error (MSE).
- pystiche_papers.li_wand_2016.style_loss(impl_params=True, multi_layer_encoder=None, hyper_parameters=None)
Style loss from [LW2016].
- Parameters
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.multi_layer_encoder (
Optional
[MultiLayerEncoder
]) – Pretrained multi-layer encoder. If omitted,multi_layer_encoder()
is used.hyper_parameters (
Optional
[HyperParameters
]) – Hyper parameters. If omitted,hyper_parameters()
is used.
See also
- Return type
- class pystiche_papers.li_wand_2016.TotalVariationLoss(impl_params=True, **total_variation_loss_kwargs)
Total variation loss from [LW2016].
- Parameters
impl_params (
bool
) – IfFalse
, use a score correction factor of 1/2.**total_variation_loss_kwargs – Additional parameters of a
pystiche.loss.TotalVariationLoss
.
In contrast to
pystiche.loss.TotalVariationLoss
, the the score is calculated with the squared error (SE) instead of the mean squared error (MSE).See also
- pystiche_papers.li_wand_2016.regularization(impl_params=True, hyper_parameters=None)
Regularization from [LW2016].
- Parameters
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
]) – Hyper parameters. If omitted,hyper_parameters()
is used.
- Return type
- pystiche_papers.li_wand_2016.perceptual_loss(impl_params=True, multi_layer_encoder=None, hyper_parameters=None)
Perceptual loss from [LW2016].
- Parameters
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.multi_layer_encoder (
Optional
[MultiLayerEncoder
]) – Pretrained multi-layer encoder. If omitted,multi_layer_encoder()
is used.hyper_parameters (
Optional
[HyperParameters
]) – Hyper parameters. If omitted,hyper_parameters()
is used.
See also
- Return type
- pystiche_papers.li_wand_2016.nst(content_image, style_image, impl_params=True, hyper_parameters=None, quiet=False)
NST from [LW2016].
- 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
) – IfTrue
, not information is logged during the optimization. Defaults toFalse
.
- Return type
- pystiche_papers.li_wand_2016.image_pyramid(impl_params=True, hyper_parameters=None, **image_pyramid_kwargs)
Image pyramid from [LW2016].
- Parameters
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.image_pyramid_kwargs (
Any
) – Additional options. SeeImagePyramid
for details.
See also
- Return type
- pystiche_papers.li_wand_2016.hyper_parameters(impl_params=True)
Hyper parameters from [LW2016].
- pystiche_papers.li_wand_2016.extract_normalized_patches2d(input, patch_size, stride)
Extract 2-dimensional patches from the input with normalized gradient.
If
stride >= patch_size
, this behaves just likepystiche.extract_patches2d()
. Otherwise, the gradient of the input is normalized such that every value is divided by the number of patches it appears in.Examples
>>> import torch >>> import pystiche >>> input = torch.ones(1, 1, 4, 4).requires_grad_(True) >>> target = torch.zeros(1, 1, 4, 4).detach() >>> # without normalized gradient >>> input_patches = pystiche.extract_patches2d( ... input, patch_size=2, stride=1 ... ) >>> target_patches = pystiche.extract_patches2d( ... target, patch_size=2, stride=1 ... ) >>> loss = 0.5 * torch.sum((input_patches - target_patches) ** 2.0) >>> loss.backward() >>> input.grad tensor([[[[1., 2., 2., 1.], [2., 4., 4., 2.], [2., 4., 4., 2.], [1., 2., 2., 1.]]]])
>>> import torch >>> import pystiche >>> import pystiche_papers.li_wand_2016 as paper >>> input = torch.ones(1, 1, 4, 4).requires_grad_(True) >>> target = torch.zeros(1, 1, 4, 4).detach() >>> # with normalized gradient >>> input_patches = paper.extract_normalized_patches2d( ... input, patch_size=2, stride=1 ... ) >>> target_patches = pystiche.extract_patches2d( ... target, patch_size=2, stride=1 ... ) >>> loss = 0.5 * torch.sum((input_patches - target_patches) ** 2.0) >>> loss.backward() >>> input.grad tensor([[[[1., 1., 1., 1.], [1., 1., 1., 1.], [1., 1., 1., 1.], [1., 1., 1., 1.]]]])
- pystiche_papers.li_wand_2016.target_transforms(impl_params=True, hyper_parameters=None)
MRF target transformations from [LW2016].
- Parameters
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. In addition, ifTrue
, every transformation comprises a valid crop after the rotation to avoid blank regions. Furthermore, the image is rescaled instead of the motif, resulting in multiple image sizes.hyper_parameters (
Optional
[HyperParameters
]) – Hyper parameters. If omitted,hyper_parameters()
is used.
- pystiche_papers.li_wand_2016.preprocessor()
Preprocessor from [LW2016].
- Return type
CaffePreprocessing
- pystiche_papers.li_wand_2016.postprocessor()
Postprocessor from [LW2016].
- Return type
CaffePostprocessing
- pystiche_papers.li_wand_2016.multi_layer_encoder()
Multi-layer encoder from [LW2016].
- Return type