Welcome to pystiche
‘s documentation!¶
pystiche
(pronounced
/ˈpaɪˈstiʃ/ ) is a
framework for
Neural Style Transfer (NST)
built upon PyTorch. The name of the project is a pun on
pastiche meaning:
A pastiche is a work of visual art […] that imitates the style or character of the work of one or more other artists. Unlike parody, pastiche celebrates, rather than mocks, the work it imitates.
pystiche
has similar goals as Deep Learning (DL) frameworks such as PyTorch:
- Accessibility
Starting off with NST can be quite overwhelming due to the sheer amount of techniques one has to know and be able to deploy.
pystiche
aims to provide an easy-to-use interface that reduces the necessary prior knowledge about NST and DL to a minimum.
- Reproducibility
Implementing NST from scratch is not only inconvenient but also error-prone.
pystiche
aims to provide reusable tools that let developers focus on their ideas rather than worrying about bugs in everything around it.
Getting started¶
Installation¶
The latest stable version can be installed with
pip install pystiche
The latest potentially unstable version can be installed with
pip install git+https://github.com/pmeier/pystiche@master
Installation of PyTorch¶
pystiche
is built upon PyTorch and depends on
torch
and torchvision
. By default, a pip install
of pystiche
tries to
install the PyTorch distributions precompiled for the latest CUDA release. If you use
another version or don’t have a CUDA-capable GPU, we encourage you to try
light-the-torch for a convenient
installation:
pip install light-the-torch
ltt install pystiche
Otherwise, please follow the
official installation instructions of PyTorch for
your setup before you install pystiche
.
Note
While pystiche
is designed to be fully functional without a GPU, most tasks
require significantly more time to perform on a CPU.
Contributing¶
First and foremost: Thank you for your interest in pystiche
s development! We
appreciate all contributions be it code or something else.
Guide lines¶
pystiche
uses the GitHub workflow
. Below is small guide how to make your first contribution.
Note
The following guide assumes that git, python, and pip , are available on your system. If that is not the case, follow the official installation instructions.
Note
pystiche
officially supports Python 3.6
, 3.7
, and 3.8
. To ensure
backwards compatibility, the development should happen on the minimum Python
version, i. e. 3.6
.
Fork
pystiche
on GitHub
Navigate to pmeier/pystiche on GitHub and click the Fork button in the top right corner.
Clone your fork to your local file system
Use
git clone
to get a local copy ofpystiche
s repository that you can work on:$ PYSTICHE_ROOT="pystiche" $ git clone "https://github.com/pmeier/pystiche.git" $PYSTICHE_ROOT
Setup your development environment
$ cd $PYSTICHE_ROOT $ virtualenv .venv --prompt="(pystiche) " $ source .venv/bin/activate $ pip install -r requirements-dev.txt $ pre-commit installNote
While
pystiche
s development requirements are fairly lightweight, it is still recommended to install them in a virtual environment rather than system wide. If you do not havevirtualenv
installed, you can do so by runningpip install --user virtualenv
.
Create a branch for local development
Use
git checkout
to create local branch with a descriptive name:$ PYSTICHE_BRANCH="my-awesome-feature-or-bug-fix" $ git checkout -b $PYSTICHE_BRANCHNow make your changes. Happy Coding!
Use
tox
to run various checks
$ toxNote
Running
tox
is equivalent to running$ tox -e lint-style $ tox -e lint-typing $ tox -e tests-integration $ tox -e tests-galleries $ tox -e tests-docsYou can find details what the individual commands do below of this guide.
Commit and push your changes
If all checks are passing you can commit your changes an push them to your fork:
$ git add . $ git commit -m "Descriptive message of the changes made" $ git push -u origin $PYSTICHE_BRANCHNote
For larger changes, it is good practice to split them in multiple small commits rather than one large one. If you do that, make sure to run the test suite before every commit. Furthermore, use
git push
without any parameters for consecutive commits.
Open a Pull request (PR)
Navigate to pmeier/pystiche/pulls on GitHub and click on the green button “New pull request”.
Click on “compare across forks” below the “Compare changes” headline.
Select your fork for “head repository” and your branch for “compare” in the drop-down menus.
Click the the green button “Create pull request”.
Note
If the time between the branch being pushed and the PR being opened is not too long, GitHub will offer you a yellow box after step 1. If you click the button, you can skip steps 2. and 3.
Note
Steps 1. to 3. only have to performed once. If you want to continue contributing,
make sure to branch from the current master
branch. You can use git pull
$ git checkout master
$ git pull origin
$ git checkout -b "my-second-awesome-feature-or-bug-fix"
If you forgot to do that or if since the creation of your branch many commits have
been made to the master
branch, simply rebase your branch on top of it.
$ git checkout master
$ git pull origin
$ git checkout "my-second-awesome-feature-or-bug-fix"
$ git rebase master
If you are contributing bug-fixes or documentation improvements, you can open a pull request (PR) without further discussion. If on the other hand you are planning to contribute new features, please open an issue and discuss the feature with us first.
Every PR is subjected to multiple automatic checks (continuous integration, CI) as well as a manual code review that it has to pass before it can be merged. The automatic checks are performed by tox. You can find details and instructions how to run the checks locally below.
Code format and linting¶
pystiche
uses isort to sort the
imports, black to format the code, and
flake8 to enforce
PEP8 compliance. To format and check the
code style, run
cd $PYSTICHE_ROOT
source .venv/bin/activate
tox -e lint-style
Note
Amongst others, isort
, black
, and flake8
are run by
pre-commit before every commit.
Furthermore, pystiche_papers
is
PEP561 compliant and checks the type
annotations with mypy. To check the static typing, run
cd $PYSTICHE_ROOT
source .venv/bin/activate
tox -e lint-typing
For convenience, you can run all lint checks with
cd $PYSTICHE_ROOT
source .venv/bin/activate
tox -f lint
Test suite¶
pystiche
uses pytest to run the test suite.
You can run it locally with
cd $PYSTICHE_ROOT
source .venv/bin/activate
tox
Note
pystiche_papers
adds the following custom options with the
corresponding @pytest.mark.*
decorators:
- --skip-large-download
: @pytest.mark.large_download
- --skip-slow
: @pytest.mark.slow
- --run-flaky
: @pytest.mark.flaky
Options prefixed with --skip
are run by default and skipped if the option is
given. Options prefixed with --run
are skipped by default and run if the option
is given.
These options are passed through tox
if given after a --
flag. For example,
the CI invokes the test suite with
cd $PYSTICHE_ROOT
source .venv/bin/activate
tox -- --skip-large-download
Documentation¶
To build the html documentation locally, run
cd $PYSTICHE_ROOT
source .venv/bin/activate
tox -e docs-html
To build the latex (PDF) documentation locally, run
cd $PYSTICHE_ROOT
source .venv/bin/activate
tox -e docs-latex
To build both, run
cd $PYSTICHE_ROOT
source .venv/bin/activate
tox -f docs
Note
Building the documentation triggers a
sphinx gallery build by
default for the example galleries. This which will take some time to complete. To get
around this, pystiche
offers two environment variables:
PYSTICHE_PLOT_GALLERY
: IfFalse
, the code inside the galleries is not executed. See the official sphinx-gallery documentation for details. Defaults toTrue
.PYSTICHE_DOWNLOAD_GALLERY
: IfTrue
, downloads pre-built galleries and uses them instead of rebuilding. For themaster
the galleries are at most six hours old. Defaults toFalse
.
Both environment variables are evaluated with strtobool()
.
Gist¶
From a high viewpoint, Neural Style Transfer (NST) can be described with only three images and two symbols:

Not only the quality of the results but also the underlying steps are comparable to the work of human artisans or craftsmen. Such a manual style transfer can be roughly divided into three steps:
The content or motif of an image needs to be identified. That means one has to identify which parts of the image are essential and on the other hand which details can be discarded.
The style of an image, such as color, shapes, brush strokes, needs to be identified. Usually that means one has to intensively study of the works of the original artist.
The identified content and style have to be merged together. This can be the most difficult step, since it usually requires a lot of skill to match the style of another artist.
In principle an NST performs the same steps, albeit fully automatically. This is nothing new in the field of computational style transfers. What makes NST stand out is its generality: NST only needs a single arbitrary content and style image as input and thus “makes – for the first time – a generalized style transfer practicable.” [SID17].
The following sections provide the gist of how these three steps are performed with
pystiche
as part of an NST . Afterwards head over to the
usage examples to see pystiche
in action.
Perceptual loss¶
The identification of content and style are core elements of a Neural Style Transfer
(NST). The agreement of the content and style of two images is measured with the
content_loss
and style_loss
, respectively.
Operators¶
In pystiche
these losses are implemented Loss
s.
Loss
s are differentiated between two types:
RegularizationLoss
and
ComparisonLoss
. A
RegularizationLoss
works without any context while a
ComparisonLoss
compares two images. Furthermore,
pystiche
differentiates between two different domains an
Loss
can work on: PixelOperator
and EncodingOperator
. A PixelOperator
operates directly on the input_image
while an
EncodingOperator
encodes it first.
In total pystiche
supports four archetypes:
Builtin examples |
|
---|---|
|
|
|
|
|
|
|
Multi-layer encoder¶
One of the main improvements of NST compared to traditional approaches is that the
agreement is not measured in the pixel or a handcrafted feature space, but rather in
the learned feature space of a Convolutional Neural Network called encoder
.
Especially variants of the style_loss
depend upon encodings, i. e. feature maps,
from various layers of the encoder.
pystiche
offers a
MultiLayerEncoder
that enables to extract all required encodings
after a single forward pass. If the same operator should be applied to different layers
of a MultiLayerEncoder
, a
MultiLayerEncodingLoss
can be used.
Perceptual loss¶
The PerceptualLoss
combines all Operator
s in a single measure acting as joint optimization criterion. How the optimization is
performed will be detailed in the next section.
Optimization¶
The merging of the identified content and style with a Neural Style Transfer (NST) is
posed as an optimization problem. The optimization is performed on the basis of a
PerceptualLoss
. A distinction is made between two different
approaches.
Image optimization¶
In its basic form, an NST optimizes the pixels of the input_image
directly. That
means they are iteratively adapted to reduce the perceptual loss. This
process is called image optimization and can be performed in pystiche
with a
image_optimization()
.
Model optimization¶
While the image optimization approach yields the highest quality results, the
computation is quite expensive and usually takes multiple minutes to complete for a
single image. Model optimization on the other hand trains a model called
transformer
to perform the stylization. The training is performed with the same
perceptual loss as before, but now the transformer
weights are used as optimization
parameters. The training is even more time consuming but afterwards the stylization is
performed in a single forward pass of the input_image
through the transformer
.
The quality however, while still high, is lower than for image optimisation approaches
since the transformer
cannot finetune the output_image
. In pystiche
a model
optimization can be performed with a
model_optimization()
.
Note
Due to the differences in execution time image and model optimization approaches are often dubbed slow and fast respectively.
pystiche
usage examples¶
Note
Although a GPU is not a requirement, it is strongly advised to run these examples with one. If you don’t have access to a GPU, the execution time of the examples might increase by multiple orders of magnitude. The total running time provided at the end of each example is measured using a GPU.
Beginner¶
Note
Click here to download the full example code
Neural Style Transfer without pystiche
¶
This example showcases how a basic Neural Style Transfer (NST), i.e. image-based
optimization, could be performed without pystiche
.
Note
This is an example how to implement an NST and not a tutorial on how NST works. As such, it will not explain why a specific choice was made or how a component works. If you have never worked with NST before, we strongly suggest you to read the Gist first.
Setup¶
We start this example by importing everything we need and setting the device we will
be working on. torch
and torchvision
will be used for the actual NST.
Furthermore, we use PIL.Image
for the file input, and matplotlib.pyplot
to show the images.
26 import itertools
27 import os.path
28 from collections import OrderedDict
29 from urllib.request import urlopen
30
31 import matplotlib.pyplot as plt
32 from PIL import Image
33 from tqdm.auto import tqdm
34
35 import torch
36 import torchvision
37 from torch import nn, optim
38 from torch.nn.functional import mse_loss
39 from torchvision import transforms
40 from torchvision.models import vgg19
41 from torchvision.transforms.functional import resize
42
43 print(f"I'm working with torch=={torch.__version__}")
44 print(f"I'm working with torchvision=={torchvision.__version__}")
45
46 device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
47 print(f"I'm working with {device}")
Out:
I'm working with torch==1.9.1+cu111
I'm working with torchvision==0.10.1+cu111
I'm working with cuda
The core component of different NSTs is the perceptual loss, which is used as optimization criterion. The perceptual loss is usually, and also for this example, calculated on features maps also called encodings. These encodings are generated from different layers of a Convolutional Neural Net (CNN) also called encoder.
A common implementation strategy for the perceptual loss is to weave in transparent loss layers into the encoder. These loss layers are called transparent since from an outside view they simply pass the input through without alteration. Internally though, they calculate the loss with the encodings of the previous layer and store them in themselves. After the forward pass is completed the stored losses are aggregated and propagated backwards to the image. While this is simple to implement, this practice has two downsides:
The calculated score is part of the current state but has to be stored inside the layer. This is generally not recommended.
While the encoder is a part of the perceptual loss, it itself does not generate it. One should be able to use the same encoder with a different perceptual loss without modification.
Thus, this example (and pystiche
) follows a different approach and separates the
encoder and the perceptual loss into individual entities.
Multi-layer Encoder¶
In a first step we define a MultiLayerEncoder
that should have the following
properties:
Given an image and a set of layers, the
MultiLayerEncoder
should return the encodings of every given layer.Since the encodings have to be generated in every optimization step they should be calculated in a single forward pass to keep the processing costs low.
To reduce the static memory requirement, the
MultiLayerEncoder
should betrim
mable in order to remove unused layers.
We achieve the main functionality by subclassing torch.nn.Sequential
and
define a custom forward
method, i.e. different behavior if called. Besides the
image it also takes an iterable layer_cfgs
containing multiple sequences of
layers
. In the method body we first find the deepest_layer
that was
requested. Subsequently, we calculate and store all encodings of the image
up to
that layer. Finally we can return all requested encodings without processing the same
layer twice.
97 class MultiLayerEncoder(nn.Sequential):
98 def forward(self, image, *layer_cfgs):
99 storage = {}
100 deepest_layer = self._find_deepest_layer(*layer_cfgs)
101 for layer, module in self.named_children():
102 image = storage[layer] = module(image)
103 if layer == deepest_layer:
104 break
105
106 return [[storage[layer] for layer in layers] for layers in layer_cfgs]
107
108 def children_names(self):
109 for name, module in self.named_children():
110 yield name
111
112 def _find_deepest_layer(self, *layer_cfgs):
113 # find all unique requested layers
114 req_layers = set(itertools.chain(*layer_cfgs))
115 try:
116 # find the deepest requested layer by indexing the layers within
117 # the multi layer encoder
118 children_names = list(self.children_names())
119 return sorted(req_layers, key=children_names.index)[-1]
120 except ValueError as error:
121 layer = str(error).split()[0]
122 raise ValueError(f"Layer {layer} is not part of the multi-layer encoder.")
123
124 def trim(self, *layer_cfgs):
125 deepest_layer = self._find_deepest_layer(*layer_cfgs)
126 children_names = list(self.children_names())
127 del self[children_names.index(deepest_layer) + 1 :]
The pretrained models the MultiLayerEncoder
is based on are usually trained on
preprocessed images. In PyTorch all models expect images are
normalized by a
per-channel mean = (0.485, 0.456, 0.406)
and standard deviation
(std = (0.229, 0.224, 0.225)
). To include this into a, MultiLayerEncoder
, we
implement this as torch.nn.Module
.
139 class Normalize(nn.Module):
140 def __init__(self, mean, std):
141 super().__init__()
142 self.register_buffer("mean", torch.tensor(mean).view(1, -1, 1, 1))
143 self.register_buffer("std", torch.tensor(std).view(1, -1, 1, 1))
144
145 def forward(self, image):
146 return (image - self.mean) / self.std
147
148
149 class TorchNormalize(Normalize):
150 def __init__(self):
151 super().__init__((0.485, 0.456, 0.406), (0.229, 0.224, 0.225))
In a last step we need to specify the structure of the MultiLayerEncoder
. In this
example we use a VGGMultiLayerEncoder
based on the VGG19
CNN introduced by
Simonyan and Zisserman [SZ14].
We only include the feature extraction stage (vgg_net.features
), i.e. the
convolutional stage, since the classifier stage (vgg_net.classifier
) only accepts
feature maps of a single size.
For our convenience we rename the layers in the same scheme the authors used instead
of keeping the consecutive index of a default torch.nn.Sequential
. The first
layer however is the TorchNormalize
as defined above.
168 class VGGMultiLayerEncoder(MultiLayerEncoder):
169 def __init__(self, vgg_net):
170 modules = OrderedDict((("preprocessing", TorchNormalize()),))
171
172 block = depth = 1
173 for module in vgg_net.features.children():
174 if isinstance(module, nn.Conv2d):
175 layer = f"conv{block}_{depth}"
176 elif isinstance(module, nn.BatchNorm2d):
177 layer = f"bn{block}_{depth}"
178 elif isinstance(module, nn.ReLU):
179 # without inplace=False the encodings of the previous layer would no
180 # longer be accessible after the ReLU layer is executed
181 module = nn.ReLU(inplace=False)
182 layer = f"relu{block}_{depth}"
183 # each ReLU layer increases the depth of the current block by one
184 depth += 1
185 elif isinstance(module, nn.MaxPool2d):
186 layer = f"pool{block}"
187 # each max pooling layer marks the end of the current block
188 block += 1
189 depth = 1
190 else:
191 msg = f"Type {type(module)} is not part of the VGG architecture."
192 raise RuntimeError(msg)
193
194 modules[layer] = module
195
196 super().__init__(modules)
197
198
199 def vgg19_multi_layer_encoder():
200 return VGGMultiLayerEncoder(vgg19(pretrained=True))
201
202
203 multi_layer_encoder = vgg19_multi_layer_encoder().to(device)
204 print(multi_layer_encoder)
Out:
Downloading: "https://download.pytorch.org/models/vgg19-dcbb9e9d.pth" to /home/runnerx/.cache/torch/hub/checkpoints/vgg19-dcbb9e9d.pth
0%| | 0.00/548M [00:00<?, ?B/s]
4%|4 | 23.1M/548M [00:00<00:02, 243MB/s]
9%|8 | 48.3M/548M [00:00<00:02, 255MB/s]
13%|#3 | 73.9M/548M [00:00<00:01, 261MB/s]
18%|#8 | 99.3M/548M [00:00<00:01, 263MB/s]
23%|##2 | 125M/548M [00:00<00:01, 265MB/s]
27%|##7 | 150M/548M [00:00<00:01, 265MB/s]
32%|###2 | 175M/548M [00:00<00:01, 264MB/s]
37%|###6 | 201M/548M [00:00<00:01, 261MB/s]
41%|####1 | 225M/548M [00:00<00:01, 259MB/s]
46%|####5 | 250M/548M [00:01<00:01, 260MB/s]
50%|##### | 275M/548M [00:01<00:01, 260MB/s]
55%|#####4 | 300M/548M [00:01<00:00, 260MB/s]
59%|#####9 | 325M/548M [00:01<00:00, 261MB/s]
64%|######3 | 350M/548M [00:01<00:00, 260MB/s]
68%|######8 | 375M/548M [00:01<00:00, 262MB/s]
73%|#######3 | 401M/548M [00:01<00:00, 263MB/s]
78%|#######7 | 426M/548M [00:01<00:00, 264MB/s]
82%|########2 | 452M/548M [00:01<00:00, 265MB/s]
87%|########7 | 477M/548M [00:01<00:00, 265MB/s]
92%|#########1| 503M/548M [00:02<00:00, 266MB/s]
96%|#########6| 528M/548M [00:02<00:00, 267MB/s]
100%|##########| 548M/548M [00:02<00:00, 263MB/s]
VGGMultiLayerEncoder(
(preprocessing): TorchNormalize()
(conv1_1): Conv2d(3, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
(relu1_1): ReLU()
(conv1_2): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
(relu1_2): ReLU()
(pool1): MaxPool2d(kernel_size=2, stride=2, padding=0, dilation=1, ceil_mode=False)
(conv2_1): Conv2d(64, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
(relu2_1): ReLU()
(conv2_2): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
(relu2_2): ReLU()
(pool2): MaxPool2d(kernel_size=2, stride=2, padding=0, dilation=1, ceil_mode=False)
(conv3_1): Conv2d(128, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
(relu3_1): ReLU()
(conv3_2): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
(relu3_2): ReLU()
(conv3_3): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
(relu3_3): ReLU()
(conv3_4): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
(relu3_4): ReLU()
(pool3): MaxPool2d(kernel_size=2, stride=2, padding=0, dilation=1, ceil_mode=False)
(conv4_1): Conv2d(256, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
(relu4_1): ReLU()
(conv4_2): Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
(relu4_2): ReLU()
(conv4_3): Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
(relu4_3): ReLU()
(conv4_4): Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
(relu4_4): ReLU()
(pool4): MaxPool2d(kernel_size=2, stride=2, padding=0, dilation=1, ceil_mode=False)
(conv5_1): Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
(relu5_1): ReLU()
(conv5_2): Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
(relu5_2): ReLU()
(conv5_3): Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
(relu5_3): ReLU()
(conv5_4): Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
(relu5_4): ReLU()
(pool5): MaxPool2d(kernel_size=2, stride=2, padding=0, dilation=1, ceil_mode=False)
)
Perceptual Loss¶
In order to calculate the perceptual loss, i.e. the optimization criterion, we define
a MultiLayerLoss
to have a convenient interface. This will be subclassed later by
the ContentLoss
and StyleLoss
.
If called with a sequence of ìnput_encs
the MultiLayerLoss
should calculate
layerwise scores together with the corresponding target_encs
. For that a
MultiLayerLoss
needs the ability to store the target_encs
so that they can be
reused for every call. The individual layer scores should be averaged by the number
of encodings and finally weighted by a score_weight
.
To achieve this we subclass torch.nn.Module
. The target_encs
are stored
as buffers, since they are not trainable parameters. The actual functionality has to
be defined in calculate_score
by a subclass.
226 def mean(sized):
227 return sum(sized) / len(sized)
228
229
230 class MultiLayerLoss(nn.Module):
231 def __init__(self, score_weight=1e0):
232 super().__init__()
233 self.score_weight = score_weight
234 self._numel_target_encs = 0
235
236 def _target_enc_name(self, idx):
237 return f"_target_encs_{idx}"
238
239 def set_target_encs(self, target_encs):
240 self._numel_target_encs = len(target_encs)
241 for idx, enc in enumerate(target_encs):
242 self.register_buffer(self._target_enc_name(idx), enc.detach())
243
244 @property
245 def target_encs(self):
246 return tuple(
247 getattr(self, self._target_enc_name(idx))
248 for idx in range(self._numel_target_encs)
249 )
250
251 def forward(self, input_encs):
252 if len(input_encs) != self._numel_target_encs:
253 msg = (
254 f"The number of given input encodings and stored target encodings "
255 f"does not match: {len(input_encs)} != {self._numel_target_encs}"
256 )
257 raise RuntimeError(msg)
258
259 layer_losses = [
260 self.calculate_score(input, target)
261 for input, target in zip(input_encs, self.target_encs)
262 ]
263 return mean(layer_losses) * self.score_weight
264
265 def calculate_score(self, input, target):
266 raise NotImplementedError
In this example we use the feature_reconstruction_loss
introduced by Mahendran
and Vedaldi [MV15] as ContentLoss
as well as the gram_loss
introduced
by Gatys, Ecker, and Bethge [GEB16] as StyleLoss
.
275 def feature_reconstruction_loss(input, target):
276 return mse_loss(input, target)
277
278
279 class ContentLoss(MultiLayerLoss):
280 def calculate_score(self, input, target):
281 return feature_reconstruction_loss(input, target)
282
283
284 def channelwise_gram_matrix(x, normalize=True):
285 x = torch.flatten(x, 2)
286 G = torch.bmm(x, x.transpose(1, 2))
287 if normalize:
288 return G / x.size()[-1]
289 else:
290 return G
291
292
293 def gram_loss(input, target):
294 return mse_loss(channelwise_gram_matrix(input), channelwise_gram_matrix(target))
295
296
297 class StyleLoss(MultiLayerLoss):
298 def calculate_score(self, input, target):
299 return gram_loss(input, target)
Images¶
Before we can load the content and style image, we need to define some basic I/O utilities.
At import a fake batch dimension is added to the images to be able to pass it through
the MultiLayerEncoder
without further modification. This dimension is removed
again upon export. Furthermore, all images will be resized to size=500
pixels.
313 import_from_pil = transforms.Compose(
314 (
315 transforms.ToTensor(),
316 transforms.Lambda(lambda x: x.unsqueeze(0)),
317 transforms.Lambda(lambda x: x.to(device)),
318 )
319 )
320
321 export_to_pil = transforms.Compose(
322 (
323 transforms.Lambda(lambda x: x.cpu()),
324 transforms.Lambda(lambda x: x.squeeze(0)),
325 transforms.Lambda(lambda x: x.clamp(0.0, 1.0)),
326 transforms.ToPILImage(),
327 )
328 )
329
330
331 def download_image(url):
332 file = os.path.abspath(os.path.basename(url))
333 with open(file, "wb") as fh, urlopen(url) as response:
334 fh.write(response.read())
335
336 return file
337
338
339 def read_image(file, size=500):
340 image = Image.open(file)
341 image = resize(image, size)
342 return import_from_pil(image)
343
344
345 def show_image(image, title=None):
346 _, ax = plt.subplots()
347 ax.axis("off")
348 if title is not None:
349 ax.set_title(title)
350
351 image = export_to_pil(image)
352 ax.imshow(image)
With the I/O utilities set up, we now download, read, and show the images that will be used in the NST.
Note
The images used in this example are licensed under the permissive Pixabay License .
367 content_url = "https://download.pystiche.org/images/bird1.jpg"
368 content_file = download_image(content_url)
369 content_image = read_image(content_file)
370 show_image(content_image, title="Content image")
375 style_url = "https://download.pystiche.org/images/paint.jpg"
376 style_file = download_image(style_url)
377 style_image = read_image(style_file)
378 show_image(style_image, title="Style image")
Neural Style Transfer¶
At first we chose the content_layers
and style_layers
on which the encodings
are compared. With them we trim
the multi_layer_encoder
to remove
unused layers that otherwise occupy memory.
Afterwards we calculate the target content and style encodings. The calculation is performed without a gradient since the gradient of the target encodings is not needed for the optimization.
393 content_layers = ("relu4_2",)
394 style_layers = ("relu1_1", "relu2_1", "relu3_1", "relu4_1", "relu5_1")
395
396 multi_layer_encoder.trim(content_layers, style_layers)
397
398 with torch.no_grad():
399 target_content_encs = multi_layer_encoder(content_image, content_layers)[0]
400 target_style_encs = multi_layer_encoder(style_image, style_layers)[0]
Next up, we instantiate the ContentLoss
and StyleLoss
with a corresponding
weight. Afterwards we store the previously calculated target encodings.
407 content_weight = 1e0
408 content_loss = ContentLoss(score_weight=content_weight)
409 content_loss.set_target_encs(target_content_encs)
410
411 style_weight = 1e3
412 style_loss = StyleLoss(score_weight=style_weight)
413 style_loss.set_target_encs(target_style_encs)
We start NST from the content_image
since this way it converges quickly.
419 input_image = content_image.clone()
420 show_image(input_image, "Input image")
Note
If you want to start from a white noise image instead use
input_image = torch.rand_like(content_image)
In a last preliminary step we create the optimizer that will be performing the NST.
Since we want to adapt the pixels of the input_image
directly, we pass it as
optimization parameters.
438 optimizer = optim.LBFGS([input_image.requires_grad_(True)], max_iter=1)
Finally we run the NST. The loss calculation has to happen inside a closure
since the LBFGS
optimizer could need to
reevaluate it multiple times per optimization step
. This structure is also valid for all other optimizers.
447 num_steps = 500
448
449 with tqdm(desc="Image optimization", total=num_steps) as progress_bar:
450 for _ in range(num_steps):
451
452 def closure():
453 optimizer.zero_grad()
454
455 input_encs = multi_layer_encoder(input_image, content_layers, style_layers)
456 input_content_encs, input_style_encs = input_encs
457
458 content_score = content_loss(input_content_encs)
459 style_score = style_loss(input_style_encs)
460
461 perceptual_loss = content_score + style_score
462 perceptual_loss.backward()
463
464 progress_bar.set_postfix(
465 loss=f"{float(perceptual_loss):.3e}", refresh=False
466 )
467 progress_bar.update()
468
469 return perceptual_loss
470
471 optimizer.step(closure)
472
473 output_image = input_image.detach()
Out:
Image optimization: 0%| | 0/500 [00:00<?, ?it/s]
Image optimization: 0%| | 1/500 [00:00<01:50, 4.52it/s, loss=4.284e+03]
Image optimization: 0%| | 2/500 [00:00<01:37, 5.10it/s, loss=4.283e+03]
Image optimization: 1%| | 3/500 [00:00<01:32, 5.37it/s, loss=2.127e+05]
Image optimization: 1%| | 4/500 [00:00<01:30, 5.50it/s, loss=2.689e+03]
Image optimization: 1%|1 | 5/500 [00:00<01:28, 5.57it/s, loss=2.275e+03]
Image optimization: 1%|1 | 6/500 [00:01<01:28, 5.60it/s, loss=1.623e+03]
Image optimization: 1%|1 | 7/500 [00:01<01:28, 5.58it/s, loss=1.325e+03]
Image optimization: 2%|1 | 8/500 [00:01<01:28, 5.58it/s, loss=1.153e+03]
Image optimization: 2%|1 | 9/500 [00:01<01:27, 5.59it/s, loss=9.456e+02]
Image optimization: 2%|2 | 10/500 [00:01<01:27, 5.62it/s, loss=7.672e+02]
Image optimization: 2%|2 | 11/500 [00:01<01:27, 5.62it/s, loss=6.631e+02]
Image optimization: 2%|2 | 12/500 [00:02<01:27, 5.60it/s, loss=5.888e+02]
Image optimization: 3%|2 | 13/500 [00:02<01:27, 5.59it/s, loss=5.440e+02]
Image optimization: 3%|2 | 14/500 [00:02<01:27, 5.58it/s, loss=4.730e+02]
Image optimization: 3%|3 | 15/500 [00:02<01:26, 5.59it/s, loss=4.275e+02]
Image optimization: 3%|3 | 16/500 [00:02<01:26, 5.57it/s, loss=3.903e+02]
Image optimization: 3%|3 | 17/500 [00:03<01:26, 5.58it/s, loss=3.681e+02]
Image optimization: 4%|3 | 18/500 [00:03<01:26, 5.57it/s, loss=3.377e+02]
Image optimization: 4%|3 | 19/500 [00:03<01:26, 5.56it/s, loss=3.146e+02]
Image optimization: 4%|4 | 20/500 [00:03<01:26, 5.56it/s, loss=2.983e+02]
Image optimization: 4%|4 | 21/500 [00:03<01:26, 5.56it/s, loss=2.820e+02]
Image optimization: 4%|4 | 22/500 [00:03<01:26, 5.54it/s, loss=2.701e+02]
Image optimization: 5%|4 | 23/500 [00:04<01:26, 5.53it/s, loss=2.547e+02]
Image optimization: 5%|4 | 24/500 [00:04<01:26, 5.51it/s, loss=2.481e+02]
Image optimization: 5%|5 | 25/500 [00:04<01:26, 5.50it/s, loss=2.354e+02]
Image optimization: 5%|5 | 26/500 [00:04<01:26, 5.50it/s, loss=2.215e+02]
Image optimization: 5%|5 | 27/500 [00:04<01:26, 5.49it/s, loss=2.152e+02]
Image optimization: 6%|5 | 28/500 [00:05<01:26, 5.48it/s, loss=2.088e+02]
Image optimization: 6%|5 | 29/500 [00:05<01:26, 5.46it/s, loss=2.022e+02]
Image optimization: 6%|6 | 30/500 [00:05<01:26, 5.46it/s, loss=1.981e+02]
Image optimization: 6%|6 | 31/500 [00:05<01:25, 5.46it/s, loss=1.919e+02]
Image optimization: 6%|6 | 32/500 [00:05<01:25, 5.47it/s, loss=1.856e+02]
Image optimization: 7%|6 | 33/500 [00:05<01:25, 5.47it/s, loss=1.784e+02]
Image optimization: 7%|6 | 34/500 [00:06<01:25, 5.47it/s, loss=1.690e+02]
Image optimization: 7%|7 | 35/500 [00:06<01:25, 5.46it/s, loss=1.652e+02]
Image optimization: 7%|7 | 36/500 [00:06<01:25, 5.45it/s, loss=1.590e+02]
Image optimization: 7%|7 | 37/500 [00:06<01:24, 5.45it/s, loss=1.524e+02]
Image optimization: 8%|7 | 38/500 [00:06<01:24, 5.45it/s, loss=1.489e+02]
Image optimization: 8%|7 | 39/500 [00:07<01:24, 5.44it/s, loss=1.462e+02]
Image optimization: 8%|8 | 40/500 [00:07<01:24, 5.42it/s, loss=1.412e+02]
Image optimization: 8%|8 | 41/500 [00:07<01:24, 5.41it/s, loss=1.378e+02]
Image optimization: 8%|8 | 42/500 [00:07<01:25, 5.38it/s, loss=1.310e+02]
Image optimization: 9%|8 | 43/500 [00:07<01:24, 5.38it/s, loss=1.260e+02]
Image optimization: 9%|8 | 44/500 [00:08<01:24, 5.39it/s, loss=1.210e+02]
Image optimization: 9%|9 | 45/500 [00:08<01:24, 5.37it/s, loss=1.167e+02]
Image optimization: 9%|9 | 46/500 [00:08<01:24, 5.37it/s, loss=1.105e+02]
Image optimization: 9%|9 | 47/500 [00:08<01:24, 5.35it/s, loss=1.212e+02]
Image optimization: 10%|9 | 48/500 [00:08<01:24, 5.35it/s, loss=1.083e+02]
Image optimization: 10%|9 | 49/500 [00:08<01:24, 5.34it/s, loss=1.089e+02]
Image optimization: 10%|# | 50/500 [00:09<01:24, 5.34it/s, loss=1.036e+02]
Image optimization: 10%|# | 51/500 [00:09<01:24, 5.33it/s, loss=1.021e+02]
Image optimization: 10%|# | 52/500 [00:09<01:24, 5.33it/s, loss=9.871e+01]
Image optimization: 11%|# | 53/500 [00:09<01:24, 5.31it/s, loss=9.470e+01]
Image optimization: 11%|# | 54/500 [00:09<01:24, 5.30it/s, loss=9.070e+01]
Image optimization: 11%|#1 | 55/500 [00:10<01:23, 5.30it/s, loss=8.912e+01]
Image optimization: 11%|#1 | 56/500 [00:10<01:24, 5.29it/s, loss=8.691e+01]
Image optimization: 11%|#1 | 57/500 [00:10<01:23, 5.28it/s, loss=8.525e+01]
Image optimization: 12%|#1 | 58/500 [00:10<01:23, 5.29it/s, loss=8.225e+01]
Image optimization: 12%|#1 | 59/500 [00:10<01:23, 5.28it/s, loss=8.017e+01]
Image optimization: 12%|#2 | 60/500 [00:11<01:22, 5.32it/s, loss=7.826e+01]
Image optimization: 12%|#2 | 61/500 [00:11<01:23, 5.29it/s, loss=7.695e+01]
Image optimization: 12%|#2 | 62/500 [00:11<01:22, 5.28it/s, loss=7.499e+01]
Image optimization: 13%|#2 | 63/500 [00:11<01:22, 5.27it/s, loss=7.303e+01]
Image optimization: 13%|#2 | 64/500 [00:11<01:22, 5.26it/s, loss=7.145e+01]
Image optimization: 13%|#3 | 65/500 [00:11<01:22, 5.25it/s, loss=6.924e+01]
Image optimization: 13%|#3 | 66/500 [00:12<01:22, 5.24it/s, loss=6.728e+01]
Image optimization: 13%|#3 | 67/500 [00:12<01:22, 5.24it/s, loss=6.574e+01]
Image optimization: 14%|#3 | 68/500 [00:12<01:22, 5.23it/s, loss=6.423e+01]
Image optimization: 14%|#3 | 69/500 [00:12<01:22, 5.23it/s, loss=6.280e+01]
Image optimization: 14%|#4 | 70/500 [00:12<01:22, 5.21it/s, loss=6.169e+01]
Image optimization: 14%|#4 | 71/500 [00:13<01:22, 5.20it/s, loss=6.064e+01]
Image optimization: 14%|#4 | 72/500 [00:13<01:22, 5.20it/s, loss=5.909e+01]
Image optimization: 15%|#4 | 73/500 [00:13<01:22, 5.20it/s, loss=5.886e+01]
Image optimization: 15%|#4 | 74/500 [00:13<01:22, 5.18it/s, loss=5.731e+01]
Image optimization: 15%|#5 | 75/500 [00:13<01:22, 5.16it/s, loss=5.656e+01]
Image optimization: 15%|#5 | 76/500 [00:14<01:22, 5.15it/s, loss=5.568e+01]
Image optimization: 15%|#5 | 77/500 [00:14<01:21, 5.16it/s, loss=5.435e+01]
Image optimization: 16%|#5 | 78/500 [00:14<01:21, 5.17it/s, loss=5.310e+01]
Image optimization: 16%|#5 | 79/500 [00:14<01:21, 5.15it/s, loss=5.242e+01]
Image optimization: 16%|#6 | 80/500 [00:14<01:21, 5.14it/s, loss=5.164e+01]
Image optimization: 16%|#6 | 81/500 [00:15<01:21, 5.12it/s, loss=5.087e+01]
Image optimization: 16%|#6 | 82/500 [00:15<01:21, 5.12it/s, loss=4.971e+01]
Image optimization: 17%|#6 | 83/500 [00:15<01:21, 5.11it/s, loss=4.895e+01]
Image optimization: 17%|#6 | 84/500 [00:15<01:21, 5.11it/s, loss=4.842e+01]
Image optimization: 17%|#7 | 85/500 [00:15<01:21, 5.10it/s, loss=4.752e+01]
Image optimization: 17%|#7 | 86/500 [00:16<01:21, 5.09it/s, loss=4.688e+01]
Image optimization: 17%|#7 | 87/500 [00:16<01:21, 5.08it/s, loss=4.600e+01]
Image optimization: 18%|#7 | 88/500 [00:16<01:21, 5.08it/s, loss=4.602e+01]
Image optimization: 18%|#7 | 89/500 [00:16<01:20, 5.08it/s, loss=4.509e+01]
Image optimization: 18%|#8 | 90/500 [00:16<01:20, 5.06it/s, loss=4.471e+01]
Image optimization: 18%|#8 | 91/500 [00:17<01:20, 5.08it/s, loss=4.424e+01]
Image optimization: 18%|#8 | 92/500 [00:17<01:20, 5.07it/s, loss=4.332e+01]
Image optimization: 19%|#8 | 93/500 [00:17<01:20, 5.06it/s, loss=4.267e+01]
Image optimization: 19%|#8 | 94/500 [00:17<01:20, 5.05it/s, loss=4.210e+01]
Image optimization: 19%|#9 | 95/500 [00:17<01:20, 5.05it/s, loss=4.167e+01]
Image optimization: 19%|#9 | 96/500 [00:18<01:20, 5.05it/s, loss=4.109e+01]
Image optimization: 19%|#9 | 97/500 [00:18<01:20, 5.03it/s, loss=4.066e+01]
Image optimization: 20%|#9 | 98/500 [00:18<01:19, 5.03it/s, loss=4.024e+01]
Image optimization: 20%|#9 | 99/500 [00:18<01:20, 5.01it/s, loss=3.966e+01]
Image optimization: 20%|## | 100/500 [00:18<01:20, 5.00it/s, loss=3.941e+01]
Image optimization: 20%|## | 101/500 [00:19<01:19, 5.00it/s, loss=3.886e+01]
Image optimization: 20%|## | 102/500 [00:19<01:19, 4.99it/s, loss=3.867e+01]
Image optimization: 21%|## | 103/500 [00:19<01:19, 5.00it/s, loss=3.839e+01]
Image optimization: 21%|## | 104/500 [00:19<01:19, 4.99it/s, loss=3.790e+01]
Image optimization: 21%|##1 | 105/500 [00:19<01:19, 4.98it/s, loss=3.757e+01]
Image optimization: 21%|##1 | 106/500 [00:20<01:19, 4.98it/s, loss=3.728e+01]
Image optimization: 21%|##1 | 107/500 [00:20<01:18, 4.98it/s, loss=3.689e+01]
Image optimization: 22%|##1 | 108/500 [00:20<01:18, 4.97it/s, loss=3.658e+01]
Image optimization: 22%|##1 | 109/500 [00:20<01:18, 4.96it/s, loss=3.621e+01]
Image optimization: 22%|##2 | 110/500 [00:20<01:18, 4.96it/s, loss=3.576e+01]
Image optimization: 22%|##2 | 111/500 [00:21<01:18, 4.96it/s, loss=3.541e+01]
Image optimization: 22%|##2 | 112/500 [00:21<01:18, 4.95it/s, loss=3.514e+01]
Image optimization: 23%|##2 | 113/500 [00:21<01:18, 4.95it/s, loss=3.481e+01]
Image optimization: 23%|##2 | 114/500 [00:21<01:17, 4.95it/s, loss=3.449e+01]
Image optimization: 23%|##3 | 115/500 [00:21<01:17, 4.96it/s, loss=3.415e+01]
Image optimization: 23%|##3 | 116/500 [00:22<01:17, 4.97it/s, loss=3.390e+01]
Image optimization: 23%|##3 | 117/500 [00:22<01:17, 4.97it/s, loss=3.363e+01]
Image optimization: 24%|##3 | 118/500 [00:22<01:16, 4.96it/s, loss=3.332e+01]
Image optimization: 24%|##3 | 119/500 [00:22<01:16, 4.96it/s, loss=3.305e+01]
Image optimization: 24%|##4 | 120/500 [00:22<01:16, 4.96it/s, loss=3.279e+01]
Image optimization: 24%|##4 | 121/500 [00:23<01:16, 4.96it/s, loss=3.252e+01]
Image optimization: 24%|##4 | 122/500 [00:23<01:16, 4.95it/s, loss=3.230e+01]
Image optimization: 25%|##4 | 123/500 [00:23<01:15, 4.96it/s, loss=3.198e+01]
Image optimization: 25%|##4 | 124/500 [00:23<01:15, 4.97it/s, loss=3.176e+01]
Image optimization: 25%|##5 | 125/500 [00:23<01:15, 4.96it/s, loss=3.156e+01]
Image optimization: 25%|##5 | 126/500 [00:24<01:15, 4.96it/s, loss=3.133e+01]
Image optimization: 25%|##5 | 127/500 [00:24<01:15, 4.97it/s, loss=3.111e+01]
Image optimization: 26%|##5 | 128/500 [00:24<01:15, 4.95it/s, loss=3.088e+01]
Image optimization: 26%|##5 | 129/500 [00:24<01:15, 4.95it/s, loss=3.062e+01]
Image optimization: 26%|##6 | 130/500 [00:24<01:14, 4.94it/s, loss=3.049e+01]
Image optimization: 26%|##6 | 131/500 [00:25<01:14, 4.94it/s, loss=3.027e+01]
Image optimization: 26%|##6 | 132/500 [00:25<01:14, 4.93it/s, loss=3.009e+01]
Image optimization: 27%|##6 | 133/500 [00:25<01:14, 4.93it/s, loss=2.987e+01]
Image optimization: 27%|##6 | 134/500 [00:25<01:14, 4.92it/s, loss=2.962e+01]
Image optimization: 27%|##7 | 135/500 [00:25<01:14, 4.92it/s, loss=2.938e+01]
Image optimization: 27%|##7 | 136/500 [00:26<01:13, 4.92it/s, loss=2.920e+01]
Image optimization: 27%|##7 | 137/500 [00:26<01:13, 4.92it/s, loss=2.900e+01]
Image optimization: 28%|##7 | 138/500 [00:26<01:13, 4.92it/s, loss=2.881e+01]
Image optimization: 28%|##7 | 139/500 [00:26<01:13, 4.91it/s, loss=2.864e+01]
Image optimization: 28%|##8 | 140/500 [00:26<01:13, 4.91it/s, loss=2.844e+01]
Image optimization: 28%|##8 | 141/500 [00:27<01:13, 4.91it/s, loss=2.829e+01]
Image optimization: 28%|##8 | 142/500 [00:27<01:12, 4.91it/s, loss=2.812e+01]
Image optimization: 29%|##8 | 143/500 [00:27<01:12, 4.91it/s, loss=2.791e+01]
Image optimization: 29%|##8 | 144/500 [00:27<01:12, 4.91it/s, loss=2.769e+01]
Image optimization: 29%|##9 | 145/500 [00:27<01:12, 4.91it/s, loss=2.751e+01]
Image optimization: 29%|##9 | 146/500 [00:28<01:12, 4.90it/s, loss=2.732e+01]
Image optimization: 29%|##9 | 147/500 [00:28<01:11, 4.91it/s, loss=2.718e+01]
Image optimization: 30%|##9 | 148/500 [00:28<01:11, 4.91it/s, loss=2.707e+01]
Image optimization: 30%|##9 | 149/500 [00:28<01:11, 4.91it/s, loss=2.692e+01]
Image optimization: 30%|### | 150/500 [00:28<01:11, 4.91it/s, loss=2.678e+01]
Image optimization: 30%|### | 151/500 [00:29<01:11, 4.91it/s, loss=2.656e+01]
Image optimization: 30%|### | 152/500 [00:29<01:10, 4.91it/s, loss=2.642e+01]
Image optimization: 31%|### | 153/500 [00:29<01:10, 4.91it/s, loss=2.625e+01]
Image optimization: 31%|### | 154/500 [00:29<01:10, 4.91it/s, loss=2.613e+01]
Image optimization: 31%|###1 | 155/500 [00:29<01:10, 4.91it/s, loss=2.601e+01]
Image optimization: 31%|###1 | 156/500 [00:30<01:10, 4.90it/s, loss=2.586e+01]
Image optimization: 31%|###1 | 157/500 [00:30<01:09, 4.90it/s, loss=2.566e+01]
Image optimization: 32%|###1 | 158/500 [00:30<01:09, 4.91it/s, loss=2.556e+01]
Image optimization: 32%|###1 | 159/500 [00:30<01:09, 4.91it/s, loss=2.543e+01]
Image optimization: 32%|###2 | 160/500 [00:30<01:09, 4.91it/s, loss=2.530e+01]
Image optimization: 32%|###2 | 161/500 [00:31<01:09, 4.90it/s, loss=2.516e+01]
Image optimization: 32%|###2 | 162/500 [00:31<01:08, 4.91it/s, loss=2.502e+01]
Image optimization: 33%|###2 | 163/500 [00:31<01:08, 4.90it/s, loss=2.490e+01]
Image optimization: 33%|###2 | 164/500 [00:31<01:08, 4.91it/s, loss=2.471e+01]
Image optimization: 33%|###3 | 165/500 [00:32<01:08, 4.91it/s, loss=2.460e+01]
Image optimization: 33%|###3 | 166/500 [00:32<01:08, 4.90it/s, loss=2.452e+01]
Image optimization: 33%|###3 | 167/500 [00:32<01:07, 4.90it/s, loss=2.439e+01]
Image optimization: 34%|###3 | 168/500 [00:32<01:07, 4.90it/s, loss=2.432e+01]
Image optimization: 34%|###3 | 169/500 [00:32<01:07, 4.89it/s, loss=2.418e+01]
Image optimization: 34%|###4 | 170/500 [00:33<01:07, 4.90it/s, loss=2.401e+01]
Image optimization: 34%|###4 | 171/500 [00:33<01:07, 4.90it/s, loss=2.386e+01]
Image optimization: 34%|###4 | 172/500 [00:33<01:06, 4.91it/s, loss=2.371e+01]
Image optimization: 35%|###4 | 173/500 [00:33<01:06, 4.90it/s, loss=2.363e+01]
Image optimization: 35%|###4 | 174/500 [00:33<01:06, 4.89it/s, loss=2.346e+01]
Image optimization: 35%|###5 | 175/500 [00:34<01:06, 4.89it/s, loss=2.334e+01]
Image optimization: 35%|###5 | 176/500 [00:34<01:06, 4.90it/s, loss=2.321e+01]
Image optimization: 35%|###5 | 177/500 [00:34<01:05, 4.90it/s, loss=2.311e+01]
Image optimization: 36%|###5 | 178/500 [00:34<01:05, 4.90it/s, loss=2.303e+01]
Image optimization: 36%|###5 | 179/500 [00:34<01:05, 4.90it/s, loss=2.293e+01]
Image optimization: 36%|###6 | 180/500 [00:35<01:05, 4.90it/s, loss=2.278e+01]
Image optimization: 36%|###6 | 181/500 [00:35<01:05, 4.89it/s, loss=2.268e+01]
Image optimization: 36%|###6 | 182/500 [00:35<01:04, 4.89it/s, loss=2.257e+01]
Image optimization: 37%|###6 | 183/500 [00:35<01:04, 4.90it/s, loss=2.245e+01]
Image optimization: 37%|###6 | 184/500 [00:35<01:04, 4.90it/s, loss=2.235e+01]
Image optimization: 37%|###7 | 185/500 [00:36<01:04, 4.90it/s, loss=2.227e+01]
Image optimization: 37%|###7 | 186/500 [00:36<01:04, 4.90it/s, loss=2.216e+01]
Image optimization: 37%|###7 | 187/500 [00:36<01:03, 4.90it/s, loss=2.206e+01]
Image optimization: 38%|###7 | 188/500 [00:36<01:03, 4.90it/s, loss=2.206e+01]
Image optimization: 38%|###7 | 189/500 [00:36<01:03, 4.90it/s, loss=2.188e+01]
Image optimization: 38%|###8 | 190/500 [00:37<01:03, 4.90it/s, loss=2.182e+01]
Image optimization: 38%|###8 | 191/500 [00:37<01:03, 4.90it/s, loss=2.172e+01]
Image optimization: 38%|###8 | 192/500 [00:37<01:03, 4.88it/s, loss=2.158e+01]
Image optimization: 39%|###8 | 193/500 [00:37<01:02, 4.88it/s, loss=2.148e+01]
Image optimization: 39%|###8 | 194/500 [00:37<01:02, 4.89it/s, loss=2.140e+01]
Image optimization: 39%|###9 | 195/500 [00:38<01:02, 4.90it/s, loss=2.131e+01]
Image optimization: 39%|###9 | 196/500 [00:38<01:01, 4.90it/s, loss=2.122e+01]
Image optimization: 39%|###9 | 197/500 [00:38<01:01, 4.91it/s, loss=2.112e+01]
Image optimization: 40%|###9 | 198/500 [00:38<01:01, 4.90it/s, loss=2.102e+01]
Image optimization: 40%|###9 | 199/500 [00:38<01:01, 4.90it/s, loss=2.094e+01]
Image optimization: 40%|#### | 200/500 [00:39<01:01, 4.90it/s, loss=2.084e+01]
Image optimization: 40%|#### | 201/500 [00:39<01:01, 4.90it/s, loss=2.075e+01]
Image optimization: 40%|#### | 202/500 [00:39<01:00, 4.90it/s, loss=2.063e+01]
Image optimization: 41%|#### | 203/500 [00:39<01:00, 4.89it/s, loss=2.054e+01]
Image optimization: 41%|#### | 204/500 [00:39<01:00, 4.89it/s, loss=2.046e+01]
Image optimization: 41%|####1 | 205/500 [00:40<01:00, 4.88it/s, loss=2.038e+01]
Image optimization: 41%|####1 | 206/500 [00:40<01:00, 4.88it/s, loss=2.032e+01]
Image optimization: 41%|####1 | 207/500 [00:40<01:00, 4.88it/s, loss=2.025e+01]
Image optimization: 42%|####1 | 208/500 [00:40<00:59, 4.87it/s, loss=2.017e+01]
Image optimization: 42%|####1 | 209/500 [00:41<00:59, 4.87it/s, loss=2.010e+01]
Image optimization: 42%|####2 | 210/500 [00:41<00:59, 4.87it/s, loss=2.002e+01]
Image optimization: 42%|####2 | 211/500 [00:41<00:59, 4.87it/s, loss=1.992e+01]
Image optimization: 42%|####2 | 212/500 [00:41<00:59, 4.87it/s, loss=1.982e+01]
Image optimization: 43%|####2 | 213/500 [00:41<00:58, 4.88it/s, loss=1.975e+01]
Image optimization: 43%|####2 | 214/500 [00:42<00:58, 4.87it/s, loss=1.969e+01]
Image optimization: 43%|####3 | 215/500 [00:42<00:58, 4.87it/s, loss=1.960e+01]
Image optimization: 43%|####3 | 216/500 [00:42<00:58, 4.86it/s, loss=1.954e+01]
Image optimization: 43%|####3 | 217/500 [00:42<00:58, 4.86it/s, loss=1.945e+01]
Image optimization: 44%|####3 | 218/500 [00:42<00:58, 4.86it/s, loss=1.938e+01]
Image optimization: 44%|####3 | 219/500 [00:43<00:57, 4.86it/s, loss=1.929e+01]
Image optimization: 44%|####4 | 220/500 [00:43<00:57, 4.86it/s, loss=1.919e+01]
Image optimization: 44%|####4 | 221/500 [00:43<00:57, 4.85it/s, loss=1.912e+01]
Image optimization: 44%|####4 | 222/500 [00:43<00:57, 4.86it/s, loss=1.907e+01]
Image optimization: 45%|####4 | 223/500 [00:43<00:56, 4.86it/s, loss=1.898e+01]
Image optimization: 45%|####4 | 224/500 [00:44<00:56, 4.85it/s, loss=1.892e+01]
Image optimization: 45%|####5 | 225/500 [00:44<00:56, 4.85it/s, loss=1.887e+01]
Image optimization: 45%|####5 | 226/500 [00:44<00:56, 4.86it/s, loss=1.879e+01]
Image optimization: 45%|####5 | 227/500 [00:44<00:56, 4.86it/s, loss=1.874e+01]
Image optimization: 46%|####5 | 228/500 [00:44<00:55, 4.86it/s, loss=1.868e+01]
Image optimization: 46%|####5 | 229/500 [00:45<00:55, 4.85it/s, loss=1.862e+01]
Image optimization: 46%|####6 | 230/500 [00:45<00:55, 4.85it/s, loss=1.854e+01]
Image optimization: 46%|####6 | 231/500 [00:45<00:55, 4.85it/s, loss=1.846e+01]
Image optimization: 46%|####6 | 232/500 [00:45<00:55, 4.85it/s, loss=1.843e+01]
Image optimization: 47%|####6 | 233/500 [00:45<00:55, 4.85it/s, loss=1.837e+01]
Image optimization: 47%|####6 | 234/500 [00:46<00:54, 4.85it/s, loss=1.832e+01]
Image optimization: 47%|####6 | 235/500 [00:46<00:54, 4.86it/s, loss=1.825e+01]
Image optimization: 47%|####7 | 236/500 [00:46<00:54, 4.85it/s, loss=1.819e+01]
Image optimization: 47%|####7 | 237/500 [00:46<00:54, 4.84it/s, loss=1.813e+01]
Image optimization: 48%|####7 | 238/500 [00:46<00:54, 4.84it/s, loss=1.807e+01]
Image optimization: 48%|####7 | 239/500 [00:47<00:53, 4.85it/s, loss=1.801e+01]
Image optimization: 48%|####8 | 240/500 [00:47<00:53, 4.84it/s, loss=1.796e+01]
Image optimization: 48%|####8 | 241/500 [00:47<00:53, 4.86it/s, loss=1.794e+01]
Image optimization: 48%|####8 | 242/500 [00:47<00:53, 4.85it/s, loss=1.785e+01]
Image optimization: 49%|####8 | 243/500 [00:48<00:52, 4.85it/s, loss=1.781e+01]
Image optimization: 49%|####8 | 244/500 [00:48<00:52, 4.84it/s, loss=1.774e+01]
Image optimization: 49%|####9 | 245/500 [00:48<00:52, 4.84it/s, loss=1.768e+01]
Image optimization: 49%|####9 | 246/500 [00:48<00:52, 4.84it/s, loss=1.761e+01]
Image optimization: 49%|####9 | 247/500 [00:48<00:52, 4.85it/s, loss=1.756e+01]
Image optimization: 50%|####9 | 248/500 [00:49<00:51, 4.85it/s, loss=1.751e+01]
Image optimization: 50%|####9 | 249/500 [00:49<00:51, 4.84it/s, loss=1.746e+01]
Image optimization: 50%|##### | 250/500 [00:49<00:51, 4.84it/s, loss=1.739e+01]
Image optimization: 50%|##### | 251/500 [00:49<00:51, 4.84it/s, loss=1.737e+01]
Image optimization: 50%|##### | 252/500 [00:49<00:51, 4.84it/s, loss=1.733e+01]
Image optimization: 51%|##### | 253/500 [00:50<00:50, 4.85it/s, loss=1.729e+01]
Image optimization: 51%|##### | 254/500 [00:50<00:50, 4.84it/s, loss=1.725e+01]
Image optimization: 51%|#####1 | 255/500 [00:50<00:50, 4.82it/s, loss=1.715e+01]
Image optimization: 51%|#####1 | 256/500 [00:50<00:50, 4.82it/s, loss=1.713e+01]
Image optimization: 51%|#####1 | 257/500 [00:50<00:50, 4.81it/s, loss=1.704e+01]
Image optimization: 52%|#####1 | 258/500 [00:51<00:50, 4.82it/s, loss=1.701e+01]
Image optimization: 52%|#####1 | 259/500 [00:51<00:50, 4.82it/s, loss=1.697e+01]
Image optimization: 52%|#####2 | 260/500 [00:51<00:49, 4.81it/s, loss=1.693e+01]
Image optimization: 52%|#####2 | 261/500 [00:51<00:49, 4.82it/s, loss=1.687e+01]
Image optimization: 52%|#####2 | 262/500 [00:51<00:49, 4.80it/s, loss=1.683e+01]
Image optimization: 53%|#####2 | 263/500 [00:52<00:49, 4.81it/s, loss=1.678e+01]
Image optimization: 53%|#####2 | 264/500 [00:52<00:49, 4.81it/s, loss=1.672e+01]
Image optimization: 53%|#####3 | 265/500 [00:52<00:48, 4.83it/s, loss=1.667e+01]
Image optimization: 53%|#####3 | 266/500 [00:52<00:48, 4.83it/s, loss=1.664e+01]
Image optimization: 53%|#####3 | 267/500 [00:52<00:48, 4.82it/s, loss=1.659e+01]
Image optimization: 54%|#####3 | 268/500 [00:53<00:48, 4.81it/s, loss=1.657e+01]
Image optimization: 54%|#####3 | 269/500 [00:53<00:48, 4.81it/s, loss=1.651e+01]
Image optimization: 54%|#####4 | 270/500 [00:53<00:47, 4.82it/s, loss=1.647e+01]
Image optimization: 54%|#####4 | 271/500 [00:53<00:47, 4.82it/s, loss=1.641e+01]
Image optimization: 54%|#####4 | 272/500 [00:54<00:47, 4.82it/s, loss=1.637e+01]
Image optimization: 55%|#####4 | 273/500 [00:54<00:47, 4.81it/s, loss=1.633e+01]
Image optimization: 55%|#####4 | 274/500 [00:54<00:47, 4.80it/s, loss=1.629e+01]
Image optimization: 55%|#####5 | 275/500 [00:54<00:46, 4.82it/s, loss=1.626e+01]
Image optimization: 55%|#####5 | 276/500 [00:54<00:46, 4.83it/s, loss=1.622e+01]
Image optimization: 55%|#####5 | 277/500 [00:55<00:46, 4.81it/s, loss=1.617e+01]
Image optimization: 56%|#####5 | 278/500 [00:55<00:46, 4.81it/s, loss=1.613e+01]
Image optimization: 56%|#####5 | 279/500 [00:55<00:45, 4.81it/s, loss=1.605e+01]
Image optimization: 56%|#####6 | 280/500 [00:55<00:45, 4.82it/s, loss=1.602e+01]
Image optimization: 56%|#####6 | 281/500 [00:55<00:45, 4.82it/s, loss=1.598e+01]
Image optimization: 56%|#####6 | 282/500 [00:56<00:45, 4.81it/s, loss=1.596e+01]
Image optimization: 57%|#####6 | 283/500 [00:56<00:45, 4.80it/s, loss=1.594e+01]
Image optimization: 57%|#####6 | 284/500 [00:56<00:44, 4.80it/s, loss=1.590e+01]
Image optimization: 57%|#####6 | 285/500 [00:56<00:44, 4.81it/s, loss=1.584e+01]
Image optimization: 57%|#####7 | 286/500 [00:56<00:44, 4.82it/s, loss=1.580e+01]
Image optimization: 57%|#####7 | 287/500 [00:57<00:44, 4.81it/s, loss=1.576e+01]
Image optimization: 58%|#####7 | 288/500 [00:57<00:43, 4.82it/s, loss=1.571e+01]
Image optimization: 58%|#####7 | 289/500 [00:57<00:43, 4.82it/s, loss=1.567e+01]
Image optimization: 58%|#####8 | 290/500 [00:57<00:43, 4.81it/s, loss=1.564e+01]
Image optimization: 58%|#####8 | 291/500 [00:57<00:43, 4.81it/s, loss=1.561e+01]
Image optimization: 58%|#####8 | 292/500 [00:58<00:43, 4.81it/s, loss=1.558e+01]
Image optimization: 59%|#####8 | 293/500 [00:58<00:43, 4.81it/s, loss=1.553e+01]
Image optimization: 59%|#####8 | 294/500 [00:58<00:42, 4.80it/s, loss=1.556e+01]
Image optimization: 59%|#####8 | 295/500 [00:58<00:42, 4.80it/s, loss=1.546e+01]
Image optimization: 59%|#####9 | 296/500 [00:59<00:42, 4.80it/s, loss=1.544e+01]
Image optimization: 59%|#####9 | 297/500 [00:59<00:42, 4.81it/s, loss=1.538e+01]
Image optimization: 60%|#####9 | 298/500 [00:59<00:42, 4.80it/s, loss=1.536e+01]
Image optimization: 60%|#####9 | 299/500 [00:59<00:41, 4.80it/s, loss=1.531e+01]
Image optimization: 60%|###### | 300/500 [00:59<00:41, 4.80it/s, loss=1.527e+01]
Image optimization: 60%|###### | 301/500 [01:00<00:41, 4.79it/s, loss=1.525e+01]
Image optimization: 60%|###### | 302/500 [01:00<00:41, 4.79it/s, loss=1.521e+01]
Image optimization: 61%|###### | 303/500 [01:00<00:41, 4.79it/s, loss=1.516e+01]
Image optimization: 61%|###### | 304/500 [01:00<00:40, 4.80it/s, loss=1.513e+01]
Image optimization: 61%|######1 | 305/500 [01:00<00:40, 4.80it/s, loss=1.509e+01]
Image optimization: 61%|######1 | 306/500 [01:01<00:40, 4.78it/s, loss=1.505e+01]
Image optimization: 61%|######1 | 307/500 [01:01<00:40, 4.78it/s, loss=1.500e+01]
Image optimization: 62%|######1 | 308/500 [01:01<00:40, 4.78it/s, loss=1.496e+01]
Image optimization: 62%|######1 | 309/500 [01:01<00:39, 4.79it/s, loss=1.492e+01]
Image optimization: 62%|######2 | 310/500 [01:01<00:39, 4.79it/s, loss=1.489e+01]
Image optimization: 62%|######2 | 311/500 [01:02<00:39, 4.79it/s, loss=1.486e+01]
Image optimization: 62%|######2 | 312/500 [01:02<00:39, 4.79it/s, loss=1.482e+01]
Image optimization: 63%|######2 | 313/500 [01:02<00:39, 4.79it/s, loss=1.478e+01]
Image optimization: 63%|######2 | 314/500 [01:02<00:38, 4.79it/s, loss=1.475e+01]
Image optimization: 63%|######3 | 315/500 [01:02<00:38, 4.78it/s, loss=1.472e+01]
Image optimization: 63%|######3 | 316/500 [01:03<00:38, 4.78it/s, loss=1.469e+01]
Image optimization: 63%|######3 | 317/500 [01:03<00:38, 4.79it/s, loss=1.466e+01]
Image optimization: 64%|######3 | 318/500 [01:03<00:38, 4.78it/s, loss=1.461e+01]
Image optimization: 64%|######3 | 319/500 [01:03<00:37, 4.79it/s, loss=1.457e+01]
Image optimization: 64%|######4 | 320/500 [01:04<00:37, 4.78it/s, loss=1.454e+01]
Image optimization: 64%|######4 | 321/500 [01:04<00:37, 4.77it/s, loss=1.451e+01]
Image optimization: 64%|######4 | 322/500 [01:04<00:37, 4.77it/s, loss=1.447e+01]
Image optimization: 65%|######4 | 323/500 [01:04<00:37, 4.77it/s, loss=1.444e+01]
Image optimization: 65%|######4 | 324/500 [01:04<00:36, 4.77it/s, loss=1.441e+01]
Image optimization: 65%|######5 | 325/500 [01:05<00:36, 4.77it/s, loss=1.438e+01]
Image optimization: 65%|######5 | 326/500 [01:05<00:36, 4.78it/s, loss=1.435e+01]
Image optimization: 65%|######5 | 327/500 [01:05<00:36, 4.77it/s, loss=1.432e+01]
Image optimization: 66%|######5 | 328/500 [01:05<00:36, 4.78it/s, loss=1.428e+01]
Image optimization: 66%|######5 | 329/500 [01:05<00:35, 4.77it/s, loss=1.425e+01]
Image optimization: 66%|######6 | 330/500 [01:06<00:35, 4.77it/s, loss=1.422e+01]
Image optimization: 66%|######6 | 331/500 [01:06<00:35, 4.76it/s, loss=1.418e+01]
Image optimization: 66%|######6 | 332/500 [01:06<00:35, 4.76it/s, loss=1.415e+01]
Image optimization: 67%|######6 | 333/500 [01:06<00:35, 4.77it/s, loss=1.412e+01]
Image optimization: 67%|######6 | 334/500 [01:06<00:34, 4.77it/s, loss=1.409e+01]
Image optimization: 67%|######7 | 335/500 [01:07<00:34, 4.77it/s, loss=1.406e+01]
Image optimization: 67%|######7 | 336/500 [01:07<00:34, 4.77it/s, loss=1.402e+01]
Image optimization: 67%|######7 | 337/500 [01:07<00:34, 4.77it/s, loss=1.398e+01]
Image optimization: 68%|######7 | 338/500 [01:07<00:33, 4.77it/s, loss=1.395e+01]
Image optimization: 68%|######7 | 339/500 [01:08<00:33, 4.76it/s, loss=1.392e+01]
Image optimization: 68%|######8 | 340/500 [01:08<00:33, 4.75it/s, loss=1.389e+01]
Image optimization: 68%|######8 | 341/500 [01:08<00:33, 4.76it/s, loss=1.386e+01]
Image optimization: 68%|######8 | 342/500 [01:08<00:33, 4.76it/s, loss=1.382e+01]
Image optimization: 69%|######8 | 343/500 [01:08<00:33, 4.76it/s, loss=1.378e+01]
Image optimization: 69%|######8 | 344/500 [01:09<00:32, 4.76it/s, loss=1.374e+01]
Image optimization: 69%|######9 | 345/500 [01:09<00:32, 4.75it/s, loss=1.371e+01]
Image optimization: 69%|######9 | 346/500 [01:09<00:32, 4.75it/s, loss=1.369e+01]
Image optimization: 69%|######9 | 347/500 [01:09<00:32, 4.76it/s, loss=1.366e+01]
Image optimization: 70%|######9 | 348/500 [01:09<00:31, 4.76it/s, loss=1.362e+01]
Image optimization: 70%|######9 | 349/500 [01:10<00:31, 4.76it/s, loss=1.359e+01]
Image optimization: 70%|####### | 350/500 [01:10<00:31, 4.75it/s, loss=1.356e+01]
Image optimization: 70%|####### | 351/500 [01:10<00:31, 4.73it/s, loss=1.351e+01]
Image optimization: 70%|####### | 352/500 [01:10<00:31, 4.74it/s, loss=1.348e+01]
Image optimization: 71%|####### | 353/500 [01:10<00:30, 4.74it/s, loss=1.346e+01]
Image optimization: 71%|####### | 354/500 [01:11<00:30, 4.74it/s, loss=1.343e+01]
Image optimization: 71%|#######1 | 355/500 [01:11<00:30, 4.75it/s, loss=1.340e+01]
Image optimization: 71%|#######1 | 356/500 [01:11<00:30, 4.73it/s, loss=1.337e+01]
Image optimization: 71%|#######1 | 357/500 [01:11<00:30, 4.73it/s, loss=1.334e+01]
Image optimization: 72%|#######1 | 358/500 [01:12<00:30, 4.73it/s, loss=1.331e+01]
Image optimization: 72%|#######1 | 359/500 [01:12<00:29, 4.73it/s, loss=1.328e+01]
Image optimization: 72%|#######2 | 360/500 [01:12<00:29, 4.74it/s, loss=1.325e+01]
Image optimization: 72%|#######2 | 361/500 [01:12<00:29, 4.74it/s, loss=1.322e+01]
Image optimization: 72%|#######2 | 362/500 [01:12<00:29, 4.74it/s, loss=1.319e+01]
Image optimization: 73%|#######2 | 363/500 [01:13<00:28, 4.74it/s, loss=1.317e+01]
Image optimization: 73%|#######2 | 364/500 [01:13<00:28, 4.73it/s, loss=1.314e+01]
Image optimization: 73%|#######3 | 365/500 [01:13<00:28, 4.73it/s, loss=1.311e+01]
Image optimization: 73%|#######3 | 366/500 [01:13<00:28, 4.71it/s, loss=1.307e+01]
Image optimization: 73%|#######3 | 367/500 [01:13<00:28, 4.70it/s, loss=1.304e+01]
Image optimization: 74%|#######3 | 368/500 [01:14<00:28, 4.71it/s, loss=1.301e+01]
Image optimization: 74%|#######3 | 369/500 [01:14<00:27, 4.73it/s, loss=1.298e+01]
Image optimization: 74%|#######4 | 370/500 [01:14<00:27, 4.73it/s, loss=1.295e+01]
Image optimization: 74%|#######4 | 371/500 [01:14<00:27, 4.72it/s, loss=1.292e+01]
Image optimization: 74%|#######4 | 372/500 [01:14<00:27, 4.71it/s, loss=1.290e+01]
Image optimization: 75%|#######4 | 373/500 [01:15<00:26, 4.71it/s, loss=1.286e+01]
Image optimization: 75%|#######4 | 374/500 [01:15<00:26, 4.72it/s, loss=1.283e+01]
Image optimization: 75%|#######5 | 375/500 [01:15<00:26, 4.72it/s, loss=1.280e+01]
Image optimization: 75%|#######5 | 376/500 [01:15<00:26, 4.71it/s, loss=1.277e+01]
Image optimization: 75%|#######5 | 377/500 [01:16<00:26, 4.73it/s, loss=1.274e+01]
Image optimization: 76%|#######5 | 378/500 [01:16<00:25, 4.72it/s, loss=1.271e+01]
Image optimization: 76%|#######5 | 379/500 [01:16<00:25, 4.72it/s, loss=1.268e+01]
Image optimization: 76%|#######6 | 380/500 [01:16<00:25, 4.71it/s, loss=1.266e+01]
Image optimization: 76%|#######6 | 381/500 [01:16<00:25, 4.71it/s, loss=1.263e+01]
Image optimization: 76%|#######6 | 382/500 [01:17<00:25, 4.72it/s, loss=1.260e+01]
Image optimization: 77%|#######6 | 383/500 [01:17<00:24, 4.71it/s, loss=1.257e+01]
Image optimization: 77%|#######6 | 384/500 [01:17<00:24, 4.72it/s, loss=1.254e+01]
Image optimization: 77%|#######7 | 385/500 [01:17<00:24, 4.71it/s, loss=1.252e+01]
Image optimization: 77%|#######7 | 386/500 [01:17<00:24, 4.71it/s, loss=1.248e+01]
Image optimization: 77%|#######7 | 387/500 [01:18<00:23, 4.71it/s, loss=1.245e+01]
Image optimization: 78%|#######7 | 388/500 [01:18<00:23, 4.72it/s, loss=1.242e+01]
Image optimization: 78%|#######7 | 389/500 [01:18<00:23, 4.70it/s, loss=1.240e+01]
Image optimization: 78%|#######8 | 390/500 [01:18<00:23, 4.70it/s, loss=1.237e+01]
Image optimization: 78%|#######8 | 391/500 [01:19<00:23, 4.70it/s, loss=1.236e+01]
Image optimization: 78%|#######8 | 392/500 [01:19<00:22, 4.70it/s, loss=1.232e+01]
Image optimization: 79%|#######8 | 393/500 [01:19<00:22, 4.70it/s, loss=1.229e+01]
Image optimization: 79%|#######8 | 394/500 [01:19<00:22, 4.70it/s, loss=1.225e+01]
Image optimization: 79%|#######9 | 395/500 [01:19<00:22, 4.70it/s, loss=1.222e+01]
Image optimization: 79%|#######9 | 396/500 [01:20<00:22, 4.70it/s, loss=1.219e+01]
Image optimization: 79%|#######9 | 397/500 [01:20<00:21, 4.70it/s, loss=1.216e+01]
Image optimization: 80%|#######9 | 398/500 [01:20<00:21, 4.70it/s, loss=1.214e+01]
Image optimization: 80%|#######9 | 399/500 [01:20<00:21, 4.71it/s, loss=1.214e+01]
Image optimization: 80%|######## | 400/500 [01:20<00:21, 4.70it/s, loss=1.210e+01]
Image optimization: 80%|######## | 401/500 [01:21<00:20, 4.71it/s, loss=1.208e+01]
Image optimization: 80%|######## | 402/500 [01:21<00:20, 4.70it/s, loss=1.204e+01]
Image optimization: 81%|######## | 403/500 [01:21<00:20, 4.70it/s, loss=1.202e+01]
Image optimization: 81%|######## | 404/500 [01:21<00:20, 4.70it/s, loss=1.199e+01]
Image optimization: 81%|########1 | 405/500 [01:21<00:20, 4.70it/s, loss=1.197e+01]
Image optimization: 81%|########1 | 406/500 [01:22<00:20, 4.70it/s, loss=1.195e+01]
Image optimization: 81%|########1 | 407/500 [01:22<00:19, 4.70it/s, loss=1.192e+01]
Image optimization: 82%|########1 | 408/500 [01:22<00:19, 4.69it/s, loss=1.189e+01]
Image optimization: 82%|########1 | 409/500 [01:22<00:19, 4.69it/s, loss=1.186e+01]
Image optimization: 82%|########2 | 410/500 [01:23<00:19, 4.68it/s, loss=1.185e+01]
Image optimization: 82%|########2 | 411/500 [01:23<00:18, 4.70it/s, loss=1.183e+01]
Image optimization: 82%|########2 | 412/500 [01:23<00:18, 4.69it/s, loss=1.179e+01]
Image optimization: 83%|########2 | 413/500 [01:23<00:18, 4.69it/s, loss=1.176e+01]
Image optimization: 83%|########2 | 414/500 [01:23<00:18, 4.68it/s, loss=1.174e+01]
Image optimization: 83%|########2 | 415/500 [01:24<00:18, 4.69it/s, loss=1.172e+01]
Image optimization: 83%|########3 | 416/500 [01:24<00:17, 4.68it/s, loss=1.169e+01]
Image optimization: 83%|########3 | 417/500 [01:24<00:17, 4.69it/s, loss=1.167e+01]
Image optimization: 84%|########3 | 418/500 [01:24<00:17, 4.68it/s, loss=1.164e+01]
Image optimization: 84%|########3 | 419/500 [01:24<00:17, 4.69it/s, loss=1.162e+01]
Image optimization: 84%|########4 | 420/500 [01:25<00:17, 4.68it/s, loss=1.160e+01]
Image optimization: 84%|########4 | 421/500 [01:25<00:16, 4.69it/s, loss=1.157e+01]
Image optimization: 84%|########4 | 422/500 [01:25<00:16, 4.67it/s, loss=1.154e+01]
Image optimization: 85%|########4 | 423/500 [01:25<00:16, 4.69it/s, loss=1.152e+01]
Image optimization: 85%|########4 | 424/500 [01:26<00:16, 4.68it/s, loss=1.149e+01]
Image optimization: 85%|########5 | 425/500 [01:26<00:16, 4.68it/s, loss=1.147e+01]
Image optimization: 85%|########5 | 426/500 [01:26<00:15, 4.68it/s, loss=1.145e+01]
Image optimization: 85%|########5 | 427/500 [01:26<00:15, 4.69it/s, loss=1.142e+01]
Image optimization: 86%|########5 | 428/500 [01:26<00:15, 4.68it/s, loss=1.140e+01]
Image optimization: 86%|########5 | 429/500 [01:27<00:15, 4.68it/s, loss=1.137e+01]
Image optimization: 86%|########6 | 430/500 [01:27<00:14, 4.67it/s, loss=1.135e+01]
Image optimization: 86%|########6 | 431/500 [01:27<00:14, 4.67it/s, loss=1.132e+01]
Image optimization: 86%|########6 | 432/500 [01:27<00:14, 4.67it/s, loss=1.130e+01]
Image optimization: 87%|########6 | 433/500 [01:27<00:14, 4.68it/s, loss=1.128e+01]
Image optimization: 87%|########6 | 434/500 [01:28<00:14, 4.67it/s, loss=1.126e+01]
Image optimization: 87%|########7 | 435/500 [01:28<00:13, 4.67it/s, loss=1.123e+01]
Image optimization: 87%|########7 | 436/500 [01:28<00:13, 4.67it/s, loss=1.122e+01]
Image optimization: 87%|########7 | 437/500 [01:28<00:13, 4.67it/s, loss=1.119e+01]
Image optimization: 88%|########7 | 438/500 [01:29<00:13, 4.68it/s, loss=1.117e+01]
Image optimization: 88%|########7 | 439/500 [01:29<00:13, 4.66it/s, loss=1.114e+01]
Image optimization: 88%|########8 | 440/500 [01:29<00:12, 4.67it/s, loss=1.112e+01]
Image optimization: 88%|########8 | 441/500 [01:29<00:12, 4.67it/s, loss=1.110e+01]
Image optimization: 88%|########8 | 442/500 [01:29<00:12, 4.67it/s, loss=1.110e+01]
Image optimization: 89%|########8 | 443/500 [01:30<00:12, 4.67it/s, loss=1.106e+01]
Image optimization: 89%|########8 | 444/500 [01:30<00:12, 4.66it/s, loss=1.105e+01]
Image optimization: 89%|########9 | 445/500 [01:30<00:11, 4.66it/s, loss=1.103e+01]
Image optimization: 89%|########9 | 446/500 [01:30<00:11, 4.65it/s, loss=1.101e+01]
Image optimization: 89%|########9 | 447/500 [01:30<00:11, 4.67it/s, loss=1.098e+01]
Image optimization: 90%|########9 | 448/500 [01:31<00:11, 4.65it/s, loss=1.096e+01]
Image optimization: 90%|########9 | 449/500 [01:31<00:10, 4.66it/s, loss=1.094e+01]
Image optimization: 90%|######### | 450/500 [01:31<00:10, 4.65it/s, loss=1.092e+01]
Image optimization: 90%|######### | 451/500 [01:31<00:10, 4.64it/s, loss=1.089e+01]
Image optimization: 90%|######### | 452/500 [01:32<00:10, 4.66it/s, loss=1.087e+01]
Image optimization: 91%|######### | 453/500 [01:32<00:10, 4.64it/s, loss=1.085e+01]
Image optimization: 91%|######### | 454/500 [01:32<00:09, 4.65it/s, loss=1.084e+01]
Image optimization: 91%|#########1| 455/500 [01:32<00:09, 4.64it/s, loss=1.082e+01]
Image optimization: 91%|#########1| 456/500 [01:32<00:09, 4.64it/s, loss=1.080e+01]
Image optimization: 91%|#########1| 457/500 [01:33<00:09, 4.66it/s, loss=1.078e+01]
Image optimization: 92%|#########1| 458/500 [01:33<00:09, 4.65it/s, loss=1.076e+01]
Image optimization: 92%|#########1| 459/500 [01:33<00:08, 4.66it/s, loss=1.074e+01]
Image optimization: 92%|#########2| 460/500 [01:33<00:08, 4.64it/s, loss=1.071e+01]
Image optimization: 92%|#########2| 461/500 [01:33<00:08, 4.64it/s, loss=1.070e+01]
Image optimization: 92%|#########2| 462/500 [01:34<00:08, 4.65it/s, loss=1.068e+01]
Image optimization: 93%|#########2| 463/500 [01:34<00:07, 4.64it/s, loss=1.066e+01]
Image optimization: 93%|#########2| 464/500 [01:34<00:07, 4.66it/s, loss=1.064e+01]
Image optimization: 93%|#########3| 465/500 [01:34<00:07, 4.64it/s, loss=1.062e+01]
Image optimization: 93%|#########3| 466/500 [01:35<00:07, 4.63it/s, loss=1.060e+01]
Image optimization: 93%|#########3| 467/500 [01:35<00:07, 4.64it/s, loss=1.058e+01]
Image optimization: 94%|#########3| 468/500 [01:35<00:06, 4.62it/s, loss=1.056e+01]
Image optimization: 94%|#########3| 469/500 [01:35<00:06, 4.64it/s, loss=1.055e+01]
Image optimization: 94%|#########3| 470/500 [01:35<00:06, 4.63it/s, loss=1.053e+01]
Image optimization: 94%|#########4| 471/500 [01:36<00:06, 4.62it/s, loss=1.052e+01]
Image optimization: 94%|#########4| 472/500 [01:36<00:06, 4.62it/s, loss=1.050e+01]
Image optimization: 95%|#########4| 473/500 [01:36<00:05, 4.61it/s, loss=1.048e+01]
Image optimization: 95%|#########4| 474/500 [01:36<00:05, 4.62it/s, loss=1.046e+01]
Image optimization: 95%|#########5| 475/500 [01:37<00:05, 4.62it/s, loss=1.045e+01]
Image optimization: 95%|#########5| 476/500 [01:37<00:05, 4.62it/s, loss=1.043e+01]
Image optimization: 95%|#########5| 477/500 [01:37<00:04, 4.63it/s, loss=1.042e+01]
Image optimization: 96%|#########5| 478/500 [01:37<00:04, 4.63it/s, loss=1.040e+01]
Image optimization: 96%|#########5| 479/500 [01:37<00:04, 4.63it/s, loss=1.038e+01]
Image optimization: 96%|#########6| 480/500 [01:38<00:04, 4.63it/s, loss=1.036e+01]
Image optimization: 96%|#########6| 481/500 [01:38<00:04, 4.63it/s, loss=1.035e+01]
Image optimization: 96%|#########6| 482/500 [01:38<00:03, 4.65it/s, loss=1.033e+01]
Image optimization: 97%|#########6| 483/500 [01:38<00:03, 4.64it/s, loss=1.032e+01]
Image optimization: 97%|#########6| 484/500 [01:38<00:03, 4.63it/s, loss=1.030e+01]
Image optimization: 97%|#########7| 485/500 [01:39<00:03, 4.64it/s, loss=1.029e+01]
Image optimization: 97%|#########7| 486/500 [01:39<00:03, 4.62it/s, loss=1.027e+01]
Image optimization: 97%|#########7| 487/500 [01:39<00:02, 4.63it/s, loss=1.025e+01]
Image optimization: 98%|#########7| 488/500 [01:39<00:02, 4.63it/s, loss=1.024e+01]
Image optimization: 98%|#########7| 489/500 [01:40<00:02, 4.61it/s, loss=1.023e+01]
Image optimization: 98%|#########8| 490/500 [01:40<00:02, 4.62it/s, loss=1.022e+01]
Image optimization: 98%|#########8| 491/500 [01:40<00:01, 4.62it/s, loss=1.020e+01]
Image optimization: 98%|#########8| 492/500 [01:40<00:01, 4.61it/s, loss=1.019e+01]
Image optimization: 99%|#########8| 493/500 [01:40<00:01, 4.62it/s, loss=1.017e+01]
Image optimization: 99%|#########8| 494/500 [01:41<00:01, 4.62it/s, loss=1.016e+01]
Image optimization: 99%|#########9| 495/500 [01:41<00:01, 4.61it/s, loss=1.015e+01]
Image optimization: 99%|#########9| 496/500 [01:41<00:00, 4.63it/s, loss=1.013e+01]
Image optimization: 99%|#########9| 497/500 [01:41<00:00, 4.60it/s, loss=1.011e+01]
Image optimization: 100%|#########9| 498/500 [01:41<00:00, 4.61it/s, loss=1.010e+01]
Image optimization: 100%|#########9| 499/500 [01:42<00:00, 4.61it/s, loss=1.010e+01]
Image optimization: 100%|##########| 500/500 [01:42<00:00, 4.60it/s, loss=1.009e+01]
Image optimization: 100%|##########| 500/500 [01:42<00:00, 4.88it/s, loss=1.009e+01]
After the NST we show the resulting image.
478 show_image(output_image, title="Output image")
Conclusion¶
As hopefully has become clear, an NST requires even in its simplest form quite a lot of utilities and boilerplate code. This makes it hard to maintain and keep bug free as it is easy to lose track of everything.
Judging by the lines of code one could (falsely) conclude that the actual NST is just
an appendix. If you feel the same you can stop worrying now: in
Neural Style Transfer with pystiche we showcase
how to achieve the same result with pystiche
.
Total running time of the script: ( 1 minutes 51.769 seconds)
Estimated memory usage: 2478 MB
Note
Click here to download the full example code
Neural Style Transfer with pystiche
¶
This example showcases how a basic Neural Style Transfer (NST), i.e. image
optimization, could be performed with pystiche
.
Note
This is an example how to implement an NST and not a tutorial on how NST works. As such, it will not explain why a specific choice was made or how a component works. If you have never worked with NST before, we strongly suggest you to read the Gist first.
Setup¶
We start this example by importing everything we need and setting the device we will be working on.
23 import pystiche
24 from pystiche import demo, enc, loss, optim
25 from pystiche.image import show_image
26 from pystiche.misc import get_device, get_input_image
27
28 print(f"I'm working with pystiche=={pystiche.__version__}")
29
30 device = get_device()
31 print(f"I'm working with {device}")
Out:
I'm working with pystiche==1.1.0.dev44+gd9e3fd8
I'm working with cuda
Multi-layer Encoder¶
The content_loss
and the style_loss
operate on the encodings of an image
rather than on the image itself. These encodings are generated by a pretrained
encoder. Since we will be using encodings from multiple layers we load a
multi-layer encoder. In this example we use the
vgg19_multi_layer_encoder()
that is based on the VGG19
architecture introduced by Simonyan and Zisserman [SZ14] .
44 multi_layer_encoder = enc.vgg19_multi_layer_encoder()
45 print(multi_layer_encoder)
Out:
VGGMultiLayerEncoder(
arch=vgg19, framework=torch
(preprocessing): TorchPreprocessing(
(0): Normalize(mean=('0.485', '0.456', '0.406'), std=('0.229', '0.224', '0.225'))
)
(conv1_1): Conv2d(3, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
(relu1_1): ReLU()
(conv1_2): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
(relu1_2): ReLU()
(pool1): MaxPool2d(kernel_size=2, stride=2, padding=0, dilation=1, ceil_mode=False)
(conv2_1): Conv2d(64, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
(relu2_1): ReLU()
(conv2_2): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
(relu2_2): ReLU()
(pool2): MaxPool2d(kernel_size=2, stride=2, padding=0, dilation=1, ceil_mode=False)
(conv3_1): Conv2d(128, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
(relu3_1): ReLU()
(conv3_2): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
(relu3_2): ReLU()
(conv3_3): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
(relu3_3): ReLU()
(conv3_4): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
(relu3_4): ReLU()
(pool3): MaxPool2d(kernel_size=2, stride=2, padding=0, dilation=1, ceil_mode=False)
(conv4_1): Conv2d(256, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
(relu4_1): ReLU()
(conv4_2): Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
(relu4_2): ReLU()
(conv4_3): Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
(relu4_3): ReLU()
(conv4_4): Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
(relu4_4): ReLU()
(pool4): MaxPool2d(kernel_size=2, stride=2, padding=0, dilation=1, ceil_mode=False)
(conv5_1): Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
(relu5_1): ReLU()
(conv5_2): Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
(relu5_2): ReLU()
(conv5_3): Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
(relu5_3): ReLU()
(conv5_4): Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
(relu5_4): ReLU()
(pool5): MaxPool2d(kernel_size=2, stride=2, padding=0, dilation=1, ceil_mode=False)
)
Perceptual Loss¶
The core components of every NST are the content_loss
and the style_loss
.
Combined they make up the perceptual loss, i.e. the optimization criterion.
In this example we use the FeatureReconstructionLoss
introduced by Mahendran and Vedaldi [MV15] as content_loss
. We first
extract the content_encoder
that generates encodings from the content_layer
.
Together with the content_weight
we can construct the content_loss
.
60 content_layer = "relu4_2"
61 content_encoder = multi_layer_encoder.extract_encoder(content_layer)
62 content_weight = 1e0
63 content_loss = loss.FeatureReconstructionLoss(
64 content_encoder, score_weight=content_weight
65 )
66 print(content_loss)
Out:
FeatureReconstructionLoss(
(encoder): VGGMultiLayerEncoder(layer=relu4_2, arch=vgg19, framework=torch)
)
We use the GramLoss
introduced by Gatys, Ecker, and Bethge
[GEB16] as style_loss
. Unlike before, we use multiple style_layers
.
The individual losses can be conveniently bundled in a
MultiLayerEncodingLoss
.
75 style_layers = ("relu1_1", "relu2_1", "relu3_1", "relu4_1", "relu5_1")
76 style_weight = 1e3
77
78
79 def get_style_op(encoder, layer_weight):
80 return loss.GramLoss(encoder, score_weight=layer_weight)
81
82
83 style_loss = loss.MultiLayerEncodingLoss(
84 multi_layer_encoder, style_layers, get_style_op, score_weight=style_weight,
85 )
86 print(style_loss)
Out:
MultiLayerEncodingLoss(
encoder=VGGMultiLayerEncoder(arch=vgg19, framework=torch), score_weight=1000
(relu1_1): GramLoss(score_weight=0.2)
(relu2_1): GramLoss(score_weight=0.2)
(relu3_1): GramLoss(score_weight=0.2)
(relu4_1): GramLoss(score_weight=0.2)
(relu5_1): GramLoss(score_weight=0.2)
)
We combine the content_loss
and style_loss
into a joined
PerceptualLoss
, which will serve as optimization criterion.
93 perceptual_loss = loss.PerceptualLoss(content_loss, style_loss).to(device)
94 print(perceptual_loss)
Out:
PerceptualLoss(
(content_loss): FeatureReconstructionLoss(
(encoder): VGGMultiLayerEncoder(layer=relu4_2, arch=vgg19, framework=torch)
)
(style_loss): MultiLayerEncodingLoss(
encoder=VGGMultiLayerEncoder(arch=vgg19, framework=torch), score_weight=1000
(relu1_1): GramLoss(score_weight=0.2)
(relu2_1): GramLoss(score_weight=0.2)
(relu3_1): GramLoss(score_weight=0.2)
(relu4_1): GramLoss(score_weight=0.2)
(relu5_1): GramLoss(score_weight=0.2)
)
)
Images¶
We now load and show the images that will be used in the NST. The images will be
resized to size=500
pixels.
104 images = demo.images()
105 images.download()
106 size = 500
Note
ìmages.download()
downloads all demo images upfront. If you only want to
download the images for this example remove this line. They will be downloaded at
runtime instead.
Note
If you want to work with other images you can load them with
read_image()
:
from pystiche.image import read_image
my_image = read_image("my_image.jpg", size=size, device=device)
130 content_image = images["bird1"].read(size=size, device=device)
131 show_image(content_image, title="Content image")
136 style_image = images["paint"].read(size=size, device=device)
137 show_image(style_image, title="Style image")
Neural Style Transfer¶
After loading the images they need to be set as targets for the optimization
criterion
.
147 perceptual_loss.set_content_image(content_image)
148 perceptual_loss.set_style_image(style_image)
As a last preliminary step we create the input image. We start from the
content_image
since this way the NST converges quickly.
155 starting_point = "content"
156 input_image = get_input_image(starting_point, content_image=content_image)
157 show_image(input_image, title="Input image")
Note
If you want to start from a white noise image instead use
starting_point = "random"
instead:
starting_point = "random"
input_image = get_input_image(starting_point, content_image=content_image)
Finally we run the NST with the image_optimization()
for
num_steps=500
steps.
In every step the perceptual_loss
is calculated nd propagated backward to the
pixels of the input_image
. If get_optimizer
is not specified, as is the case
here, the default_image_optimizer()
, i.e.
LBFGS
is used.
181 output_image = optim.image_optimization(input_image, perceptual_loss, num_steps=500)
Out:
Image optimization: 0%| | 0/500 [00:00<?, ?it/s]
Image optimization: 0%| | 1/500 [00:00<01:35, 5.24it/s, loss=4.369e+03]
Image optimization: 0%| | 2/500 [00:00<01:35, 5.22it/s, loss=4.368e+03]
Image optimization: 1%| | 3/500 [00:00<01:34, 5.24it/s, loss=2.303e+05]
Image optimization: 1%| | 4/500 [00:00<01:34, 5.24it/s, loss=2.760e+03]
Image optimization: 1%|1 | 5/500 [00:00<01:35, 5.21it/s, loss=2.334e+03]
Image optimization: 1%|1 | 6/500 [00:01<01:35, 5.17it/s, loss=1.663e+03]
Image optimization: 1%|1 | 7/500 [00:01<01:35, 5.16it/s, loss=1.354e+03]
Image optimization: 2%|1 | 8/500 [00:01<01:35, 5.16it/s, loss=1.178e+03]
Image optimization: 2%|1 | 9/500 [00:01<01:34, 5.17it/s, loss=9.652e+02]
Image optimization: 2%|2 | 10/500 [00:01<01:34, 5.16it/s, loss=7.869e+02]
Image optimization: 2%|2 | 11/500 [00:02<01:34, 5.15it/s, loss=6.813e+02]
Image optimization: 2%|2 | 12/500 [00:02<01:35, 5.12it/s, loss=6.047e+02]
Image optimization: 3%|2 | 13/500 [00:02<01:35, 5.11it/s, loss=5.567e+02]
Image optimization: 3%|2 | 14/500 [00:02<01:34, 5.13it/s, loss=4.829e+02]
Image optimization: 3%|3 | 15/500 [00:02<01:34, 5.12it/s, loss=4.387e+02]
Image optimization: 3%|3 | 16/500 [00:03<01:34, 5.10it/s, loss=3.989e+02]
Image optimization: 3%|3 | 17/500 [00:03<01:34, 5.09it/s, loss=3.784e+02]
Image optimization: 4%|3 | 18/500 [00:03<01:34, 5.09it/s, loss=3.505e+02]
Image optimization: 4%|3 | 19/500 [00:03<01:34, 5.07it/s, loss=3.271e+02]
Image optimization: 4%|4 | 20/500 [00:03<01:34, 5.07it/s, loss=3.117e+02]
Image optimization: 4%|4 | 21/500 [00:04<01:34, 5.08it/s, loss=2.929e+02]
Image optimization: 4%|4 | 22/500 [00:04<01:34, 5.05it/s, loss=2.684e+02]
Image optimization: 5%|4 | 23/500 [00:04<01:34, 5.05it/s, loss=2.649e+02]
Image optimization: 5%|4 | 24/500 [00:04<01:34, 5.04it/s, loss=2.486e+02]
Image optimization: 5%|5 | 25/500 [00:04<01:34, 5.05it/s, loss=2.406e+02]
Image optimization: 5%|5 | 26/500 [00:05<01:34, 5.04it/s, loss=2.340e+02]
Image optimization: 5%|5 | 27/500 [00:05<01:33, 5.03it/s, loss=2.216e+02]
Image optimization: 6%|5 | 28/500 [00:05<01:34, 5.01it/s, loss=2.098e+02]
Image optimization: 6%|5 | 29/500 [00:05<01:34, 5.00it/s, loss=2.040e+02]
Image optimization: 6%|6 | 30/500 [00:05<01:34, 4.98it/s, loss=1.985e+02]
Image optimization: 6%|6 | 31/500 [00:06<01:33, 4.99it/s, loss=1.917e+02]
Image optimization: 6%|6 | 32/500 [00:06<01:33, 5.00it/s, loss=1.848e+02]
Image optimization: 7%|6 | 33/500 [00:06<01:33, 5.00it/s, loss=1.793e+02]
Image optimization: 7%|6 | 34/500 [00:06<01:33, 4.98it/s, loss=1.733e+02]
Image optimization: 7%|7 | 35/500 [00:06<01:33, 4.97it/s, loss=1.698e+02]
Image optimization: 7%|7 | 36/500 [00:07<01:33, 4.95it/s, loss=1.628e+02]
Image optimization: 7%|7 | 37/500 [00:07<01:33, 4.95it/s, loss=1.571e+02]
Image optimization: 8%|7 | 38/500 [00:07<01:33, 4.95it/s, loss=1.514e+02]
Image optimization: 8%|7 | 39/500 [00:07<01:33, 4.95it/s, loss=1.448e+02]
Image optimization: 8%|8 | 40/500 [00:07<01:33, 4.91it/s, loss=1.420e+02]
Image optimization: 8%|8 | 41/500 [00:08<01:33, 4.91it/s, loss=1.385e+02]
Image optimization: 8%|8 | 42/500 [00:08<01:33, 4.92it/s, loss=1.347e+02]
Image optimization: 9%|8 | 43/500 [00:08<01:32, 4.91it/s, loss=1.317e+02]
Image optimization: 9%|8 | 44/500 [00:08<01:32, 4.92it/s, loss=1.285e+02]
Image optimization: 9%|9 | 45/500 [00:08<01:32, 4.91it/s, loss=1.248e+02]
Image optimization: 9%|9 | 46/500 [00:09<01:32, 4.90it/s, loss=1.251e+02]
Image optimization: 9%|9 | 47/500 [00:09<01:32, 4.90it/s, loss=1.166e+02]
Image optimization: 10%|9 | 48/500 [00:09<01:32, 4.90it/s, loss=1.148e+02]
Image optimization: 10%|9 | 49/500 [00:09<01:31, 4.91it/s, loss=1.127e+02]
Image optimization: 10%|# | 50/500 [00:09<01:31, 4.90it/s, loss=1.088e+02]
Image optimization: 10%|# | 51/500 [00:10<01:31, 4.89it/s, loss=1.048e+02]
Image optimization: 10%|# | 52/500 [00:10<01:31, 4.88it/s, loss=1.012e+02]
Image optimization: 11%|# | 53/500 [00:10<01:31, 4.86it/s, loss=9.719e+01]
Image optimization: 11%|# | 54/500 [00:10<01:32, 4.84it/s, loss=9.601e+01]
Image optimization: 11%|#1 | 55/500 [00:10<01:31, 4.85it/s, loss=9.234e+01]
Image optimization: 11%|#1 | 56/500 [00:11<01:31, 4.86it/s, loss=9.005e+01]
Image optimization: 11%|#1 | 57/500 [00:11<01:31, 4.86it/s, loss=8.728e+01]
Image optimization: 12%|#1 | 58/500 [00:11<01:31, 4.85it/s, loss=8.482e+01]
Image optimization: 12%|#1 | 59/500 [00:11<01:31, 4.83it/s, loss=8.265e+01]
Image optimization: 12%|#2 | 60/500 [00:12<01:31, 4.81it/s, loss=8.111e+01]
Image optimization: 12%|#2 | 61/500 [00:12<01:30, 4.83it/s, loss=7.893e+01]
Image optimization: 12%|#2 | 62/500 [00:12<01:30, 4.83it/s, loss=7.679e+01]
Image optimization: 13%|#2 | 63/500 [00:12<01:30, 4.81it/s, loss=7.514e+01]
Image optimization: 13%|#2 | 64/500 [00:12<01:31, 4.79it/s, loss=7.286e+01]
Image optimization: 13%|#3 | 65/500 [00:13<01:30, 4.79it/s, loss=7.068e+01]
Image optimization: 13%|#3 | 66/500 [00:13<01:30, 4.79it/s, loss=6.907e+01]
Image optimization: 13%|#3 | 67/500 [00:13<01:30, 4.77it/s, loss=6.754e+01]
Image optimization: 14%|#3 | 68/500 [00:13<01:30, 4.77it/s, loss=6.658e+01]
Image optimization: 14%|#3 | 69/500 [00:13<01:30, 4.77it/s, loss=6.513e+01]
Image optimization: 14%|#4 | 70/500 [00:14<01:30, 4.75it/s, loss=6.399e+01]
Image optimization: 14%|#4 | 71/500 [00:14<01:30, 4.76it/s, loss=6.280e+01]
Image optimization: 14%|#4 | 72/500 [00:14<01:29, 4.76it/s, loss=6.092e+01]
Image optimization: 15%|#4 | 73/500 [00:14<01:30, 4.74it/s, loss=5.955e+01]
Image optimization: 15%|#4 | 74/500 [00:14<01:29, 4.74it/s, loss=5.836e+01]
Image optimization: 15%|#5 | 75/500 [00:15<01:29, 4.74it/s, loss=5.732e+01]
Image optimization: 15%|#5 | 76/500 [00:15<01:29, 4.73it/s, loss=5.606e+01]
Image optimization: 15%|#5 | 77/500 [00:15<01:29, 4.74it/s, loss=5.534e+01]
Image optimization: 16%|#5 | 78/500 [00:15<01:29, 4.72it/s, loss=5.475e+01]
Image optimization: 16%|#5 | 79/500 [00:16<01:29, 4.73it/s, loss=5.382e+01]
Image optimization: 16%|#6 | 80/500 [00:16<01:29, 4.72it/s, loss=5.319e+01]
Image optimization: 16%|#6 | 81/500 [00:16<01:28, 4.71it/s, loss=5.247e+01]
Image optimization: 16%|#6 | 82/500 [00:16<01:28, 4.70it/s, loss=5.160e+01]
Image optimization: 17%|#6 | 83/500 [00:16<01:28, 4.70it/s, loss=5.070e+01]
Image optimization: 17%|#6 | 84/500 [00:17<01:28, 4.69it/s, loss=4.993e+01]
Image optimization: 17%|#7 | 85/500 [00:17<01:28, 4.69it/s, loss=4.899e+01]
Image optimization: 17%|#7 | 86/500 [00:17<01:28, 4.68it/s, loss=4.806e+01]
Image optimization: 17%|#7 | 87/500 [00:17<01:28, 4.68it/s, loss=4.759e+01]
Image optimization: 18%|#7 | 88/500 [00:17<01:28, 4.67it/s, loss=4.718e+01]
Image optimization: 18%|#7 | 89/500 [00:18<01:27, 4.68it/s, loss=4.660e+01]
Image optimization: 18%|#8 | 90/500 [00:18<01:27, 4.67it/s, loss=4.597e+01]
Image optimization: 18%|#8 | 91/500 [00:18<01:27, 4.66it/s, loss=4.546e+01]
Image optimization: 18%|#8 | 92/500 [00:18<01:27, 4.66it/s, loss=4.467e+01]
Image optimization: 19%|#8 | 93/500 [00:19<01:27, 4.64it/s, loss=4.412e+01]
Image optimization: 19%|#8 | 94/500 [00:19<01:27, 4.66it/s, loss=4.383e+01]
Image optimization: 19%|#9 | 95/500 [00:19<01:27, 4.63it/s, loss=4.326e+01]
Image optimization: 19%|#9 | 96/500 [00:19<01:27, 4.62it/s, loss=4.291e+01]
Image optimization: 19%|#9 | 97/500 [00:19<01:27, 4.63it/s, loss=4.249e+01]
Image optimization: 20%|#9 | 98/500 [00:20<01:27, 4.61it/s, loss=4.211e+01]
Image optimization: 20%|#9 | 99/500 [00:20<01:27, 4.60it/s, loss=4.144e+01]
Image optimization: 20%|## | 100/500 [00:20<01:27, 4.59it/s, loss=4.094e+01]
Image optimization: 20%|## | 101/500 [00:20<01:26, 4.59it/s, loss=4.064e+01]
Image optimization: 20%|## | 102/500 [00:20<01:26, 4.59it/s, loss=4.015e+01]
Image optimization: 21%|## | 103/500 [00:21<01:26, 4.58it/s, loss=3.983e+01]
Image optimization: 21%|## | 104/500 [00:21<01:26, 4.57it/s, loss=3.942e+01]
Image optimization: 21%|##1 | 105/500 [00:21<01:26, 4.58it/s, loss=3.909e+01]
Image optimization: 21%|##1 | 106/500 [00:21<01:25, 4.58it/s, loss=3.870e+01]
Image optimization: 21%|##1 | 107/500 [00:22<01:25, 4.58it/s, loss=3.829e+01]
Image optimization: 22%|##1 | 108/500 [00:22<01:25, 4.58it/s, loss=3.794e+01]
Image optimization: 22%|##1 | 109/500 [00:22<01:25, 4.57it/s, loss=3.769e+01]
Image optimization: 22%|##2 | 110/500 [00:22<01:25, 4.56it/s, loss=3.742e+01]
Image optimization: 22%|##2 | 111/500 [00:22<01:25, 4.56it/s, loss=3.707e+01]
Image optimization: 22%|##2 | 112/500 [00:23<01:25, 4.56it/s, loss=3.677e+01]
Image optimization: 23%|##2 | 113/500 [00:23<01:24, 4.57it/s, loss=3.644e+01]
Image optimization: 23%|##2 | 114/500 [00:23<01:24, 4.57it/s, loss=3.613e+01]
Image optimization: 23%|##3 | 115/500 [00:23<01:24, 4.57it/s, loss=3.580e+01]
Image optimization: 23%|##3 | 116/500 [00:24<01:23, 4.57it/s, loss=3.550e+01]
Image optimization: 23%|##3 | 117/500 [00:24<01:23, 4.57it/s, loss=3.526e+01]
Image optimization: 24%|##3 | 118/500 [00:24<01:23, 4.57it/s, loss=3.495e+01]
Image optimization: 24%|##3 | 119/500 [00:24<01:23, 4.56it/s, loss=3.494e+01]
Image optimization: 24%|##4 | 120/500 [00:24<01:23, 4.55it/s, loss=3.442e+01]
Image optimization: 24%|##4 | 121/500 [00:25<01:23, 4.55it/s, loss=3.424e+01]
Image optimization: 24%|##4 | 122/500 [00:25<01:23, 4.55it/s, loss=3.395e+01]
Image optimization: 25%|##4 | 123/500 [00:25<01:22, 4.56it/s, loss=3.359e+01]
Image optimization: 25%|##4 | 124/500 [00:25<01:22, 4.56it/s, loss=3.329e+01]
Image optimization: 25%|##5 | 125/500 [00:26<01:22, 4.56it/s, loss=3.306e+01]
Image optimization: 25%|##5 | 126/500 [00:26<01:21, 4.57it/s, loss=3.287e+01]
Image optimization: 25%|##5 | 127/500 [00:26<01:21, 4.57it/s, loss=3.261e+01]
Image optimization: 26%|##5 | 128/500 [00:26<01:21, 4.56it/s, loss=3.239e+01]
Image optimization: 26%|##5 | 129/500 [00:26<01:21, 4.56it/s, loss=3.209e+01]
Image optimization: 26%|##6 | 130/500 [00:27<01:21, 4.55it/s, loss=3.191e+01]
Image optimization: 26%|##6 | 131/500 [00:27<01:21, 4.55it/s, loss=3.167e+01]
Image optimization: 26%|##6 | 132/500 [00:27<01:21, 4.54it/s, loss=3.146e+01]
Image optimization: 27%|##6 | 133/500 [00:27<01:20, 4.53it/s, loss=3.121e+01]
Image optimization: 27%|##6 | 134/500 [00:27<01:20, 4.55it/s, loss=3.104e+01]
Image optimization: 27%|##7 | 135/500 [00:28<01:20, 4.55it/s, loss=3.085e+01]
Image optimization: 27%|##7 | 136/500 [00:28<01:19, 4.55it/s, loss=3.067e+01]
Image optimization: 27%|##7 | 137/500 [00:28<01:19, 4.55it/s, loss=3.044e+01]
Image optimization: 28%|##7 | 138/500 [00:28<01:19, 4.53it/s, loss=3.020e+01]
Image optimization: 28%|##7 | 139/500 [00:29<01:19, 4.53it/s, loss=2.997e+01]
Image optimization: 28%|##8 | 140/500 [00:29<01:19, 4.54it/s, loss=2.983e+01]
Image optimization: 28%|##8 | 141/500 [00:29<01:19, 4.54it/s, loss=2.960e+01]
Image optimization: 28%|##8 | 142/500 [00:29<01:18, 4.54it/s, loss=2.945e+01]
Image optimization: 29%|##8 | 143/500 [00:29<01:18, 4.54it/s, loss=2.928e+01]
Image optimization: 29%|##8 | 144/500 [00:30<01:18, 4.52it/s, loss=2.907e+01]
Image optimization: 29%|##9 | 145/500 [00:30<01:18, 4.51it/s, loss=2.886e+01]
Image optimization: 29%|##9 | 146/500 [00:30<01:18, 4.51it/s, loss=2.870e+01]
Image optimization: 29%|##9 | 147/500 [00:30<01:18, 4.51it/s, loss=2.853e+01]
Image optimization: 30%|##9 | 148/500 [00:31<01:18, 4.50it/s, loss=2.829e+01]
Image optimization: 30%|##9 | 149/500 [00:31<01:18, 4.49it/s, loss=2.811e+01]
Image optimization: 30%|### | 150/500 [00:31<01:17, 4.50it/s, loss=2.798e+01]
Image optimization: 30%|### | 151/500 [00:31<01:17, 4.51it/s, loss=2.790e+01]
Image optimization: 30%|### | 152/500 [00:31<01:16, 4.52it/s, loss=2.774e+01]
Image optimization: 31%|### | 153/500 [00:32<01:16, 4.52it/s, loss=2.762e+01]
Image optimization: 31%|### | 154/500 [00:32<01:16, 4.52it/s, loss=2.747e+01]
Image optimization: 31%|###1 | 155/500 [00:32<01:16, 4.53it/s, loss=2.728e+01]
Image optimization: 31%|###1 | 156/500 [00:32<01:15, 4.53it/s, loss=2.712e+01]
Image optimization: 31%|###1 | 157/500 [00:33<01:16, 4.50it/s, loss=2.701e+01]
Image optimization: 32%|###1 | 158/500 [00:33<01:15, 4.50it/s, loss=2.677e+01]
Image optimization: 32%|###1 | 159/500 [00:33<01:15, 4.49it/s, loss=2.676e+01]
Image optimization: 32%|###2 | 160/500 [00:33<01:15, 4.49it/s, loss=2.650e+01]
Image optimization: 32%|###2 | 161/500 [00:33<01:15, 4.48it/s, loss=2.640e+01]
Image optimization: 32%|###2 | 162/500 [00:34<01:15, 4.48it/s, loss=2.630e+01]
Image optimization: 33%|###2 | 163/500 [00:34<01:15, 4.48it/s, loss=2.611e+01]
Image optimization: 33%|###2 | 164/500 [00:34<01:14, 4.49it/s, loss=2.596e+01]
Image optimization: 33%|###3 | 165/500 [00:34<01:14, 4.48it/s, loss=2.582e+01]
Image optimization: 33%|###3 | 166/500 [00:35<01:14, 4.48it/s, loss=2.567e+01]
Image optimization: 33%|###3 | 167/500 [00:35<01:14, 4.48it/s, loss=2.552e+01]
Image optimization: 34%|###3 | 168/500 [00:35<01:14, 4.48it/s, loss=2.537e+01]
Image optimization: 34%|###3 | 169/500 [00:35<01:13, 4.48it/s, loss=2.525e+01]
Image optimization: 34%|###4 | 170/500 [00:35<01:13, 4.48it/s, loss=2.512e+01]
Image optimization: 34%|###4 | 171/500 [00:36<01:13, 4.47it/s, loss=2.505e+01]
Image optimization: 34%|###4 | 172/500 [00:36<01:13, 4.48it/s, loss=2.493e+01]
Image optimization: 35%|###4 | 173/500 [00:36<01:13, 4.48it/s, loss=2.484e+01]
Image optimization: 35%|###4 | 174/500 [00:36<01:12, 4.48it/s, loss=2.473e+01]
Image optimization: 35%|###5 | 175/500 [00:37<01:12, 4.47it/s, loss=2.454e+01]
Image optimization: 35%|###5 | 176/500 [00:37<01:12, 4.47it/s, loss=2.443e+01]
Image optimization: 35%|###5 | 177/500 [00:37<01:12, 4.47it/s, loss=2.434e+01]
Image optimization: 36%|###5 | 178/500 [00:37<01:11, 4.48it/s, loss=2.426e+01]
Image optimization: 36%|###5 | 179/500 [00:37<01:11, 4.47it/s, loss=2.416e+01]
Image optimization: 36%|###6 | 180/500 [00:38<01:11, 4.47it/s, loss=2.402e+01]
Image optimization: 36%|###6 | 181/500 [00:38<01:11, 4.48it/s, loss=2.386e+01]
Image optimization: 36%|###6 | 182/500 [00:38<01:10, 4.48it/s, loss=2.378e+01]
Image optimization: 37%|###6 | 183/500 [00:38<01:10, 4.48it/s, loss=2.364e+01]
Image optimization: 37%|###6 | 184/500 [00:39<01:10, 4.47it/s, loss=2.357e+01]
Image optimization: 37%|###7 | 185/500 [00:39<01:10, 4.48it/s, loss=2.346e+01]
Image optimization: 37%|###7 | 186/500 [00:39<01:10, 4.48it/s, loss=2.335e+01]
Image optimization: 37%|###7 | 187/500 [00:39<01:09, 4.48it/s, loss=2.327e+01]
Image optimization: 38%|###7 | 188/500 [00:40<01:09, 4.48it/s, loss=2.310e+01]
Image optimization: 38%|###7 | 189/500 [00:40<01:09, 4.48it/s, loss=2.300e+01]
Image optimization: 38%|###8 | 190/500 [00:40<01:09, 4.48it/s, loss=2.290e+01]
Image optimization: 38%|###8 | 191/500 [00:40<01:09, 4.47it/s, loss=2.283e+01]
Image optimization: 38%|###8 | 192/500 [00:40<01:08, 4.48it/s, loss=2.276e+01]
Image optimization: 39%|###8 | 193/500 [00:41<01:08, 4.48it/s, loss=2.270e+01]
Image optimization: 39%|###8 | 194/500 [00:41<01:08, 4.48it/s, loss=2.258e+01]
Image optimization: 39%|###9 | 195/500 [00:41<01:08, 4.48it/s, loss=2.250e+01]
Image optimization: 39%|###9 | 196/500 [00:41<01:07, 4.47it/s, loss=2.239e+01]
Image optimization: 39%|###9 | 197/500 [00:42<01:07, 4.47it/s, loss=2.230e+01]
Image optimization: 40%|###9 | 198/500 [00:42<01:07, 4.47it/s, loss=2.221e+01]
Image optimization: 40%|###9 | 199/500 [00:42<01:07, 4.48it/s, loss=2.210e+01]
Image optimization: 40%|#### | 200/500 [00:42<01:07, 4.47it/s, loss=2.201e+01]
Image optimization: 40%|#### | 201/500 [00:42<01:06, 4.47it/s, loss=2.192e+01]
Image optimization: 40%|#### | 202/500 [00:43<01:06, 4.47it/s, loss=2.184e+01]
Image optimization: 41%|#### | 203/500 [00:43<01:06, 4.48it/s, loss=2.177e+01]
Image optimization: 41%|#### | 204/500 [00:43<01:06, 4.47it/s, loss=2.168e+01]
Image optimization: 41%|####1 | 205/500 [00:43<01:06, 4.47it/s, loss=2.157e+01]
Image optimization: 41%|####1 | 206/500 [00:44<01:05, 4.48it/s, loss=2.147e+01]
Image optimization: 41%|####1 | 207/500 [00:44<01:05, 4.48it/s, loss=2.139e+01]
Image optimization: 42%|####1 | 208/500 [00:44<01:05, 4.47it/s, loss=2.128e+01]
Image optimization: 42%|####1 | 209/500 [00:44<01:05, 4.47it/s, loss=2.123e+01]
Image optimization: 42%|####2 | 210/500 [00:44<01:04, 4.47it/s, loss=2.114e+01]
Image optimization: 42%|####2 | 211/500 [00:45<01:04, 4.46it/s, loss=2.107e+01]
Image optimization: 42%|####2 | 212/500 [00:45<01:04, 4.46it/s, loss=2.101e+01]
Image optimization: 43%|####2 | 213/500 [00:45<01:04, 4.46it/s, loss=2.089e+01]
Image optimization: 43%|####2 | 214/500 [00:45<01:04, 4.46it/s, loss=2.080e+01]
Image optimization: 43%|####3 | 215/500 [00:46<01:03, 4.46it/s, loss=2.074e+01]
Image optimization: 43%|####3 | 216/500 [00:46<01:03, 4.46it/s, loss=2.066e+01]
Image optimization: 43%|####3 | 217/500 [00:46<01:03, 4.45it/s, loss=2.058e+01]
Image optimization: 44%|####3 | 218/500 [00:46<01:03, 4.46it/s, loss=2.049e+01]
Image optimization: 44%|####3 | 219/500 [00:46<01:03, 4.46it/s, loss=2.040e+01]
Image optimization: 44%|####4 | 220/500 [00:47<01:02, 4.45it/s, loss=2.035e+01]
Image optimization: 44%|####4 | 221/500 [00:47<01:02, 4.44it/s, loss=2.027e+01]
Image optimization: 44%|####4 | 222/500 [00:47<01:02, 4.42it/s, loss=2.020e+01]
Image optimization: 45%|####4 | 223/500 [00:47<01:02, 4.43it/s, loss=2.015e+01]
Image optimization: 45%|####4 | 224/500 [00:48<01:02, 4.43it/s, loss=2.007e+01]
Image optimization: 45%|####5 | 225/500 [00:48<01:01, 4.44it/s, loss=1.999e+01]
Image optimization: 45%|####5 | 226/500 [00:48<01:01, 4.43it/s, loss=1.993e+01]
Image optimization: 45%|####5 | 227/500 [00:48<01:01, 4.44it/s, loss=1.986e+01]
Image optimization: 46%|####5 | 228/500 [00:48<01:01, 4.43it/s, loss=1.979e+01]
Image optimization: 46%|####5 | 229/500 [00:49<01:01, 4.42it/s, loss=1.973e+01]
Image optimization: 46%|####6 | 230/500 [00:49<01:01, 4.41it/s, loss=1.963e+01]
Image optimization: 46%|####6 | 231/500 [00:49<01:00, 4.42it/s, loss=1.957e+01]
Image optimization: 46%|####6 | 232/500 [00:49<01:00, 4.41it/s, loss=1.951e+01]
Image optimization: 47%|####6 | 233/500 [00:50<01:00, 4.42it/s, loss=1.945e+01]
Image optimization: 47%|####6 | 234/500 [00:50<01:00, 4.43it/s, loss=1.941e+01]
Image optimization: 47%|####6 | 235/500 [00:50<00:59, 4.43it/s, loss=1.935e+01]
Image optimization: 47%|####7 | 236/500 [00:50<00:59, 4.42it/s, loss=1.929e+01]
Image optimization: 47%|####7 | 237/500 [00:51<00:59, 4.40it/s, loss=1.924e+01]
Image optimization: 48%|####7 | 238/500 [00:51<00:59, 4.41it/s, loss=1.914e+01]
Image optimization: 48%|####7 | 239/500 [00:51<00:59, 4.41it/s, loss=1.906e+01]
Image optimization: 48%|####8 | 240/500 [00:51<00:58, 4.42it/s, loss=1.901e+01]
Image optimization: 48%|####8 | 241/500 [00:51<00:58, 4.43it/s, loss=1.893e+01]
Image optimization: 48%|####8 | 242/500 [00:52<00:58, 4.41it/s, loss=1.888e+01]
Image optimization: 49%|####8 | 243/500 [00:52<00:58, 4.41it/s, loss=1.882e+01]
Image optimization: 49%|####8 | 244/500 [00:52<00:58, 4.40it/s, loss=1.876e+01]
Image optimization: 49%|####9 | 245/500 [00:52<00:57, 4.40it/s, loss=1.869e+01]
Image optimization: 49%|####9 | 246/500 [00:53<00:57, 4.40it/s, loss=1.862e+01]
Image optimization: 49%|####9 | 247/500 [00:53<00:57, 4.41it/s, loss=1.856e+01]
Image optimization: 50%|####9 | 248/500 [00:53<00:57, 4.41it/s, loss=1.850e+01]
Image optimization: 50%|####9 | 249/500 [00:53<00:57, 4.39it/s, loss=1.845e+01]
Image optimization: 50%|##### | 250/500 [00:53<00:56, 4.40it/s, loss=1.839e+01]
Image optimization: 50%|##### | 251/500 [00:54<00:56, 4.41it/s, loss=1.833e+01]
Image optimization: 50%|##### | 252/500 [00:54<00:56, 4.41it/s, loss=1.828e+01]
Image optimization: 51%|##### | 253/500 [00:54<00:56, 4.41it/s, loss=1.823e+01]
Image optimization: 51%|##### | 254/500 [00:54<00:56, 4.35it/s, loss=1.816e+01]
Image optimization: 51%|#####1 | 255/500 [00:55<00:56, 4.37it/s, loss=1.810e+01]
Image optimization: 51%|#####1 | 256/500 [00:55<00:55, 4.39it/s, loss=1.806e+01]
Image optimization: 51%|#####1 | 257/500 [00:55<00:55, 4.41it/s, loss=1.801e+01]
Image optimization: 52%|#####1 | 258/500 [00:55<00:55, 4.39it/s, loss=1.796e+01]
Image optimization: 52%|#####1 | 259/500 [00:56<00:55, 4.36it/s, loss=1.792e+01]
Image optimization: 52%|#####2 | 260/500 [00:56<00:54, 4.37it/s, loss=1.786e+01]
Image optimization: 52%|#####2 | 261/500 [00:56<00:54, 4.39it/s, loss=1.782e+01]
Image optimization: 52%|#####2 | 262/500 [00:56<00:54, 4.40it/s, loss=1.775e+01]
Image optimization: 53%|#####2 | 263/500 [00:56<00:54, 4.38it/s, loss=1.770e+01]
Image optimization: 53%|#####2 | 264/500 [00:57<00:54, 4.35it/s, loss=1.767e+01]
Image optimization: 53%|#####3 | 265/500 [00:57<00:53, 4.37it/s, loss=1.761e+01]
Image optimization: 53%|#####3 | 266/500 [00:57<00:53, 4.39it/s, loss=1.755e+01]
Image optimization: 53%|#####3 | 267/500 [00:57<00:53, 4.39it/s, loss=1.749e+01]
Image optimization: 54%|#####3 | 268/500 [00:58<00:53, 4.38it/s, loss=1.747e+01]
Image optimization: 54%|#####3 | 269/500 [00:58<00:52, 4.36it/s, loss=1.743e+01]
Image optimization: 54%|#####4 | 270/500 [00:58<00:52, 4.37it/s, loss=1.740e+01]
Image optimization: 54%|#####4 | 271/500 [00:58<00:52, 4.39it/s, loss=1.736e+01]
Image optimization: 54%|#####4 | 272/500 [00:58<00:51, 4.39it/s, loss=1.729e+01]
Image optimization: 55%|#####4 | 273/500 [00:59<00:51, 4.37it/s, loss=1.725e+01]
Image optimization: 55%|#####4 | 274/500 [00:59<00:51, 4.36it/s, loss=1.720e+01]
Image optimization: 55%|#####5 | 275/500 [00:59<00:51, 4.36it/s, loss=1.717e+01]
Image optimization: 55%|#####5 | 276/500 [00:59<00:51, 4.38it/s, loss=1.714e+01]
Image optimization: 55%|#####5 | 277/500 [01:00<00:51, 4.37it/s, loss=1.707e+01]
Image optimization: 56%|#####5 | 278/500 [01:00<00:50, 4.36it/s, loss=1.702e+01]
Image optimization: 56%|#####5 | 279/500 [01:00<00:50, 4.35it/s, loss=1.699e+01]
Image optimization: 56%|#####6 | 280/500 [01:00<00:50, 4.36it/s, loss=1.694e+01]
Image optimization: 56%|#####6 | 281/500 [01:01<00:50, 4.36it/s, loss=1.690e+01]
Image optimization: 56%|#####6 | 282/500 [01:01<00:49, 4.36it/s, loss=1.684e+01]
Image optimization: 57%|#####6 | 283/500 [01:01<00:49, 4.36it/s, loss=1.679e+01]
Image optimization: 57%|#####6 | 284/500 [01:01<00:49, 4.37it/s, loss=1.676e+01]
Image optimization: 57%|#####6 | 285/500 [01:01<00:49, 4.37it/s, loss=1.670e+01]
Image optimization: 57%|#####7 | 286/500 [01:02<00:49, 4.36it/s, loss=1.666e+01]
Image optimization: 57%|#####7 | 287/500 [01:02<00:48, 4.36it/s, loss=1.662e+01]
Image optimization: 58%|#####7 | 288/500 [01:02<00:48, 4.34it/s, loss=1.657e+01]
Image optimization: 58%|#####7 | 289/500 [01:02<00:48, 4.37it/s, loss=1.653e+01]
Image optimization: 58%|#####8 | 290/500 [01:03<00:48, 4.36it/s, loss=1.648e+01]
Image optimization: 58%|#####8 | 291/500 [01:03<00:48, 4.35it/s, loss=1.644e+01]
Image optimization: 58%|#####8 | 292/500 [01:03<00:47, 4.34it/s, loss=1.642e+01]
Image optimization: 59%|#####8 | 293/500 [01:03<00:47, 4.34it/s, loss=1.637e+01]
Image optimization: 59%|#####8 | 294/500 [01:04<00:47, 4.33it/s, loss=1.634e+01]
Image optimization: 59%|#####8 | 295/500 [01:04<00:47, 4.34it/s, loss=1.631e+01]
Image optimization: 59%|#####9 | 296/500 [01:04<00:47, 4.34it/s, loss=1.625e+01]
Image optimization: 59%|#####9 | 297/500 [01:04<00:46, 4.35it/s, loss=1.620e+01]
Image optimization: 60%|#####9 | 298/500 [01:04<00:46, 4.34it/s, loss=1.617e+01]
Image optimization: 60%|#####9 | 299/500 [01:05<00:46, 4.34it/s, loss=1.614e+01]
Image optimization: 60%|###### | 300/500 [01:05<00:45, 4.36it/s, loss=1.610e+01]
Image optimization: 60%|###### | 301/500 [01:05<00:45, 4.35it/s, loss=1.606e+01]
Image optimization: 60%|###### | 302/500 [01:05<00:45, 4.35it/s, loss=1.601e+01]
Image optimization: 61%|###### | 303/500 [01:06<00:45, 4.34it/s, loss=1.597e+01]
Image optimization: 61%|###### | 304/500 [01:06<00:45, 4.34it/s, loss=1.595e+01]
Image optimization: 61%|######1 | 305/500 [01:06<00:44, 4.34it/s, loss=1.591e+01]
Image optimization: 61%|######1 | 306/500 [01:06<00:44, 4.33it/s, loss=1.588e+01]
Image optimization: 61%|######1 | 307/500 [01:07<00:44, 4.32it/s, loss=1.584e+01]
Image optimization: 62%|######1 | 308/500 [01:07<00:44, 4.33it/s, loss=1.579e+01]
Image optimization: 62%|######1 | 309/500 [01:07<00:43, 4.34it/s, loss=1.575e+01]
Image optimization: 62%|######2 | 310/500 [01:07<00:43, 4.34it/s, loss=1.572e+01]
Image optimization: 62%|######2 | 311/500 [01:07<00:43, 4.33it/s, loss=1.568e+01]
Image optimization: 62%|######2 | 312/500 [01:08<00:43, 4.33it/s, loss=1.564e+01]
Image optimization: 63%|######2 | 313/500 [01:08<00:43, 4.31it/s, loss=1.560e+01]
Image optimization: 63%|######2 | 314/500 [01:08<00:42, 4.33it/s, loss=1.557e+01]
Image optimization: 63%|######3 | 315/500 [01:08<00:42, 4.34it/s, loss=1.554e+01]
Image optimization: 63%|######3 | 316/500 [01:09<00:42, 4.33it/s, loss=1.550e+01]
Image optimization: 63%|######3 | 317/500 [01:09<00:42, 4.34it/s, loss=1.545e+01]
Image optimization: 64%|######3 | 318/500 [01:09<00:41, 4.34it/s, loss=1.541e+01]
Image optimization: 64%|######3 | 319/500 [01:09<00:41, 4.35it/s, loss=1.538e+01]
Image optimization: 64%|######4 | 320/500 [01:10<00:41, 4.35it/s, loss=1.535e+01]
Image optimization: 64%|######4 | 321/500 [01:10<00:41, 4.34it/s, loss=1.532e+01]
Image optimization: 64%|######4 | 322/500 [01:10<00:41, 4.33it/s, loss=1.529e+01]
Image optimization: 65%|######4 | 323/500 [01:10<00:40, 4.36it/s, loss=1.525e+01]
Image optimization: 65%|######4 | 324/500 [01:10<00:40, 4.34it/s, loss=1.522e+01]
Image optimization: 65%|######5 | 325/500 [01:11<00:40, 4.33it/s, loss=1.517e+01]
Image optimization: 65%|######5 | 326/500 [01:11<00:39, 4.35it/s, loss=1.514e+01]
Image optimization: 65%|######5 | 327/500 [01:11<00:39, 4.34it/s, loss=1.511e+01]
Image optimization: 66%|######5 | 328/500 [01:11<00:39, 4.35it/s, loss=1.508e+01]
Image optimization: 66%|######5 | 329/500 [01:12<00:39, 4.34it/s, loss=1.506e+01]
Image optimization: 66%|######6 | 330/500 [01:12<00:39, 4.34it/s, loss=1.502e+01]
Image optimization: 66%|######6 | 331/500 [01:12<00:39, 4.33it/s, loss=1.498e+01]
Image optimization: 66%|######6 | 332/500 [01:12<00:38, 4.35it/s, loss=1.495e+01]
Image optimization: 67%|######6 | 333/500 [01:13<00:38, 4.35it/s, loss=1.491e+01]
Image optimization: 67%|######6 | 334/500 [01:13<00:38, 4.35it/s, loss=1.487e+01]
Image optimization: 67%|######7 | 335/500 [01:13<00:38, 4.34it/s, loss=1.485e+01]
Image optimization: 67%|######7 | 336/500 [01:13<00:37, 4.34it/s, loss=1.483e+01]
Image optimization: 67%|######7 | 337/500 [01:13<00:37, 4.36it/s, loss=1.479e+01]
Image optimization: 68%|######7 | 338/500 [01:14<00:37, 4.35it/s, loss=1.477e+01]
Image optimization: 68%|######7 | 339/500 [01:14<00:37, 4.35it/s, loss=1.472e+01]
Image optimization: 68%|######8 | 340/500 [01:14<00:36, 4.35it/s, loss=1.469e+01]
Image optimization: 68%|######8 | 341/500 [01:14<00:36, 4.34it/s, loss=1.465e+01]
Image optimization: 68%|######8 | 342/500 [01:15<00:36, 4.37it/s, loss=1.461e+01]
Image optimization: 69%|######8 | 343/500 [01:15<00:36, 4.35it/s, loss=1.457e+01]
Image optimization: 69%|######8 | 344/500 [01:15<00:35, 4.35it/s, loss=1.455e+01]
Image optimization: 69%|######9 | 345/500 [01:15<00:35, 4.36it/s, loss=1.452e+01]
Image optimization: 69%|######9 | 346/500 [01:16<00:35, 4.35it/s, loss=1.449e+01]
Image optimization: 69%|######9 | 347/500 [01:16<00:35, 4.37it/s, loss=1.446e+01]
Image optimization: 70%|######9 | 348/500 [01:16<00:34, 4.36it/s, loss=1.441e+01]
Image optimization: 70%|######9 | 349/500 [01:16<00:34, 4.37it/s, loss=1.437e+01]
Image optimization: 70%|####### | 350/500 [01:16<00:34, 4.37it/s, loss=1.435e+01]
Image optimization: 70%|####### | 351/500 [01:17<00:34, 4.36it/s, loss=1.432e+01]
Image optimization: 70%|####### | 352/500 [01:17<00:33, 4.37it/s, loss=1.429e+01]
Image optimization: 71%|####### | 353/500 [01:17<00:33, 4.35it/s, loss=1.426e+01]
Image optimization: 71%|####### | 354/500 [01:17<00:33, 4.35it/s, loss=1.422e+01]
Image optimization: 71%|#######1 | 355/500 [01:18<00:33, 4.37it/s, loss=1.419e+01]
Image optimization: 71%|#######1 | 356/500 [01:18<00:32, 4.38it/s, loss=1.416e+01]
Image optimization: 71%|#######1 | 357/500 [01:18<00:32, 4.37it/s, loss=1.413e+01]
Image optimization: 72%|#######1 | 358/500 [01:18<00:32, 4.36it/s, loss=1.409e+01]
Image optimization: 72%|#######1 | 359/500 [01:18<00:32, 4.37it/s, loss=1.406e+01]
Image optimization: 72%|#######2 | 360/500 [01:19<00:31, 4.38it/s, loss=1.403e+01]
Image optimization: 72%|#######2 | 361/500 [01:19<00:31, 4.38it/s, loss=1.400e+01]
Image optimization: 72%|#######2 | 362/500 [01:19<00:31, 4.39it/s, loss=1.397e+01]
Image optimization: 73%|#######2 | 363/500 [01:19<00:31, 4.36it/s, loss=1.395e+01]
Image optimization: 73%|#######2 | 364/500 [01:20<00:31, 4.36it/s, loss=1.390e+01]
Image optimization: 73%|#######3 | 365/500 [01:20<00:30, 4.37it/s, loss=1.388e+01]
Image optimization: 73%|#######3 | 366/500 [01:20<00:30, 4.36it/s, loss=1.385e+01]
Image optimization: 73%|#######3 | 367/500 [01:20<00:30, 4.38it/s, loss=1.382e+01]
Image optimization: 74%|#######3 | 368/500 [01:21<00:30, 4.38it/s, loss=1.379e+01]
Image optimization: 74%|#######3 | 369/500 [01:21<00:29, 4.39it/s, loss=1.378e+01]
Image optimization: 74%|#######4 | 370/500 [01:21<00:29, 4.39it/s, loss=1.373e+01]
Image optimization: 74%|#######4 | 371/500 [01:21<00:29, 4.37it/s, loss=1.372e+01]
Image optimization: 74%|#######4 | 372/500 [01:21<00:29, 4.36it/s, loss=1.369e+01]
Image optimization: 75%|#######4 | 373/500 [01:22<00:29, 4.37it/s, loss=1.365e+01]
Image optimization: 75%|#######4 | 374/500 [01:22<00:28, 4.36it/s, loss=1.361e+01]
Image optimization: 75%|#######5 | 375/500 [01:22<00:28, 4.38it/s, loss=1.358e+01]
Image optimization: 75%|#######5 | 376/500 [01:22<00:28, 4.36it/s, loss=1.356e+01]
Image optimization: 75%|#######5 | 377/500 [01:23<00:28, 4.36it/s, loss=1.352e+01]
Image optimization: 76%|#######5 | 378/500 [01:23<00:27, 4.37it/s, loss=1.349e+01]
Image optimization: 76%|#######5 | 379/500 [01:23<00:27, 4.36it/s, loss=1.347e+01]
Image optimization: 76%|#######6 | 380/500 [01:23<00:27, 4.38it/s, loss=1.346e+01]
Image optimization: 76%|#######6 | 381/500 [01:24<00:27, 4.36it/s, loss=1.342e+01]
Image optimization: 76%|#######6 | 382/500 [01:24<00:26, 4.37it/s, loss=1.340e+01]
Image optimization: 77%|#######6 | 383/500 [01:24<00:26, 4.38it/s, loss=1.337e+01]
Image optimization: 77%|#######6 | 384/500 [01:24<00:26, 4.39it/s, loss=1.334e+01]
Image optimization: 77%|#######7 | 385/500 [01:24<00:26, 4.39it/s, loss=1.330e+01]
Image optimization: 77%|#######7 | 386/500 [01:25<00:26, 4.37it/s, loss=1.327e+01]
Image optimization: 77%|#######7 | 387/500 [01:25<00:25, 4.39it/s, loss=1.325e+01]
Image optimization: 78%|#######7 | 388/500 [01:25<00:25, 4.39it/s, loss=1.321e+01]
Image optimization: 78%|#######7 | 389/500 [01:25<00:25, 4.39it/s, loss=1.319e+01]
Image optimization: 78%|#######8 | 390/500 [01:26<00:25, 4.38it/s, loss=1.316e+01]
Image optimization: 78%|#######8 | 391/500 [01:26<00:24, 4.36it/s, loss=1.315e+01]
Image optimization: 78%|#######8 | 392/500 [01:26<00:24, 4.39it/s, loss=1.313e+01]
Image optimization: 79%|#######8 | 393/500 [01:26<00:24, 4.39it/s, loss=1.311e+01]
Image optimization: 79%|#######8 | 394/500 [01:26<00:24, 4.39it/s, loss=1.308e+01]
Image optimization: 79%|#######9 | 395/500 [01:27<00:24, 4.36it/s, loss=1.303e+01]
Image optimization: 79%|#######9 | 396/500 [01:27<00:23, 4.36it/s, loss=1.301e+01]
Image optimization: 79%|#######9 | 397/500 [01:27<00:23, 4.37it/s, loss=1.299e+01]
Image optimization: 80%|#######9 | 398/500 [01:27<00:23, 4.37it/s, loss=1.297e+01]
Image optimization: 80%|#######9 | 399/500 [01:28<00:23, 4.38it/s, loss=1.295e+01]
Image optimization: 80%|######## | 400/500 [01:28<00:22, 4.35it/s, loss=1.293e+01]
Image optimization: 80%|######## | 401/500 [01:28<00:22, 4.36it/s, loss=1.290e+01]
Image optimization: 80%|######## | 402/500 [01:28<00:22, 4.36it/s, loss=1.286e+01]
Image optimization: 81%|######## | 403/500 [01:29<00:22, 4.38it/s, loss=1.284e+01]
Image optimization: 81%|######## | 404/500 [01:29<00:22, 4.36it/s, loss=1.281e+01]
Image optimization: 81%|########1 | 405/500 [01:29<00:21, 4.35it/s, loss=1.279e+01]
Image optimization: 81%|########1 | 406/500 [01:29<00:21, 4.37it/s, loss=1.277e+01]
Image optimization: 81%|########1 | 407/500 [01:29<00:21, 4.38it/s, loss=1.274e+01]
Image optimization: 82%|########1 | 408/500 [01:30<00:21, 4.38it/s, loss=1.271e+01]
Image optimization: 82%|########1 | 409/500 [01:30<00:20, 4.36it/s, loss=1.269e+01]
Image optimization: 82%|########2 | 410/500 [01:30<00:20, 4.38it/s, loss=1.267e+01]
Image optimization: 82%|########2 | 411/500 [01:30<00:20, 4.38it/s, loss=1.264e+01]
Image optimization: 82%|########2 | 412/500 [01:31<00:20, 4.39it/s, loss=1.261e+01]
Image optimization: 83%|########2 | 413/500 [01:31<00:19, 4.37it/s, loss=1.258e+01]
Image optimization: 83%|########2 | 414/500 [01:31<00:19, 4.37it/s, loss=1.255e+01]
Image optimization: 83%|########2 | 415/500 [01:31<00:19, 4.38it/s, loss=1.252e+01]
Image optimization: 83%|########3 | 416/500 [01:32<00:19, 4.39it/s, loss=1.250e+01]
Image optimization: 83%|########3 | 417/500 [01:32<00:18, 4.39it/s, loss=1.247e+01]
Image optimization: 84%|########3 | 418/500 [01:32<00:18, 4.36it/s, loss=1.244e+01]
Image optimization: 84%|########3 | 419/500 [01:32<00:18, 4.35it/s, loss=1.242e+01]
Image optimization: 84%|########4 | 420/500 [01:32<00:18, 4.37it/s, loss=1.239e+01]
Image optimization: 84%|########4 | 421/500 [01:33<00:18, 4.35it/s, loss=1.237e+01]
Image optimization: 84%|########4 | 422/500 [01:33<00:17, 4.36it/s, loss=1.234e+01]
Image optimization: 85%|########4 | 423/500 [01:33<00:17, 4.36it/s, loss=1.231e+01]
Image optimization: 85%|########4 | 424/500 [01:33<00:17, 4.35it/s, loss=1.229e+01]
Image optimization: 85%|########5 | 425/500 [01:34<00:17, 4.37it/s, loss=1.227e+01]
Image optimization: 85%|########5 | 426/500 [01:34<00:16, 4.36it/s, loss=1.224e+01]
Image optimization: 85%|########5 | 427/500 [01:34<00:16, 4.36it/s, loss=1.221e+01]
Image optimization: 86%|########5 | 428/500 [01:34<00:16, 4.35it/s, loss=1.218e+01]
Image optimization: 86%|########5 | 429/500 [01:35<00:16, 4.36it/s, loss=1.216e+01]
Image optimization: 86%|########6 | 430/500 [01:35<00:16, 4.36it/s, loss=1.213e+01]
Image optimization: 86%|########6 | 431/500 [01:35<00:15, 4.36it/s, loss=1.211e+01]
Image optimization: 86%|########6 | 432/500 [01:35<00:15, 4.37it/s, loss=1.209e+01]
Image optimization: 87%|########6 | 433/500 [01:35<00:15, 4.37it/s, loss=1.207e+01]
Image optimization: 87%|########6 | 434/500 [01:36<00:15, 4.38it/s, loss=1.204e+01]
Image optimization: 87%|########7 | 435/500 [01:36<00:14, 4.38it/s, loss=1.202e+01]
Image optimization: 87%|########7 | 436/500 [01:36<00:14, 4.37it/s, loss=1.199e+01]
Image optimization: 87%|########7 | 437/500 [01:36<00:14, 4.38it/s, loss=1.196e+01]
Image optimization: 88%|########7 | 438/500 [01:37<00:14, 4.38it/s, loss=1.194e+01]
Image optimization: 88%|########7 | 439/500 [01:37<00:13, 4.36it/s, loss=1.192e+01]
Image optimization: 88%|########8 | 440/500 [01:37<00:13, 4.37it/s, loss=1.190e+01]
Image optimization: 88%|########8 | 441/500 [01:37<00:13, 4.36it/s, loss=1.189e+01]
Image optimization: 88%|########8 | 442/500 [01:37<00:13, 4.37it/s, loss=1.186e+01]
Image optimization: 89%|########8 | 443/500 [01:38<00:13, 4.37it/s, loss=1.184e+01]
Image optimization: 89%|########8 | 444/500 [01:38<00:12, 4.38it/s, loss=1.182e+01]
Image optimization: 89%|########9 | 445/500 [01:38<00:12, 4.37it/s, loss=1.179e+01]
Image optimization: 89%|########9 | 446/500 [01:38<00:12, 4.37it/s, loss=1.178e+01]
Image optimization: 89%|########9 | 447/500 [01:39<00:12, 4.38it/s, loss=1.176e+01]
Image optimization: 90%|########9 | 448/500 [01:39<00:11, 4.37it/s, loss=1.175e+01]
Image optimization: 90%|########9 | 449/500 [01:39<00:11, 4.39it/s, loss=1.172e+01]
Image optimization: 90%|######### | 450/500 [01:39<00:11, 4.37it/s, loss=1.170e+01]
Image optimization: 90%|######### | 451/500 [01:40<00:11, 4.37it/s, loss=1.168e+01]
Image optimization: 90%|######### | 452/500 [01:40<00:10, 4.37it/s, loss=1.166e+01]
Image optimization: 91%|######### | 453/500 [01:40<00:10, 4.36it/s, loss=1.163e+01]
Image optimization: 91%|######### | 454/500 [01:40<00:10, 4.35it/s, loss=1.161e+01]
Image optimization: 91%|#########1| 455/500 [01:40<00:10, 4.37it/s, loss=1.159e+01]
Image optimization: 91%|#########1| 456/500 [01:41<00:10, 4.36it/s, loss=1.156e+01]
Image optimization: 91%|#########1| 457/500 [01:41<00:09, 4.36it/s, loss=1.154e+01]
Image optimization: 92%|#########1| 458/500 [01:41<00:09, 4.36it/s, loss=1.153e+01]
Image optimization: 92%|#########1| 459/500 [01:41<00:09, 4.37it/s, loss=1.151e+01]
Image optimization: 92%|#########2| 460/500 [01:42<00:09, 4.36it/s, loss=1.149e+01]
Image optimization: 92%|#########2| 461/500 [01:42<00:08, 4.35it/s, loss=1.148e+01]
Image optimization: 92%|#########2| 462/500 [01:42<00:08, 4.37it/s, loss=1.146e+01]
Image optimization: 93%|#########2| 463/500 [01:42<00:08, 4.36it/s, loss=1.143e+01]
Image optimization: 93%|#########2| 464/500 [01:43<00:08, 4.36it/s, loss=1.141e+01]
Image optimization: 93%|#########3| 465/500 [01:43<00:08, 4.36it/s, loss=1.139e+01]
Image optimization: 93%|#########3| 466/500 [01:43<00:07, 4.36it/s, loss=1.138e+01]
Image optimization: 93%|#########3| 467/500 [01:43<00:07, 4.37it/s, loss=1.136e+01]
Image optimization: 94%|#########3| 468/500 [01:43<00:07, 4.36it/s, loss=1.134e+01]
Image optimization: 94%|#########3| 469/500 [01:44<00:07, 4.37it/s, loss=1.132e+01]
Image optimization: 94%|#########3| 470/500 [01:44<00:06, 4.36it/s, loss=1.130e+01]
Image optimization: 94%|#########4| 471/500 [01:44<00:06, 4.37it/s, loss=1.128e+01]
Image optimization: 94%|#########4| 472/500 [01:44<00:06, 4.35it/s, loss=1.126e+01]
Image optimization: 95%|#########4| 473/500 [01:45<00:06, 4.34it/s, loss=1.125e+01]
Image optimization: 95%|#########4| 474/500 [01:45<00:05, 4.35it/s, loss=1.123e+01]
Image optimization: 95%|#########5| 475/500 [01:45<00:05, 4.35it/s, loss=1.121e+01]
Image optimization: 95%|#########5| 476/500 [01:45<00:05, 4.34it/s, loss=1.119e+01]
Image optimization: 95%|#########5| 477/500 [01:46<00:05, 4.35it/s, loss=1.118e+01]
Image optimization: 96%|#########5| 478/500 [01:46<00:05, 4.35it/s, loss=1.116e+01]
Image optimization: 96%|#########5| 479/500 [01:46<00:04, 4.36it/s, loss=1.114e+01]
Image optimization: 96%|#########6| 480/500 [01:46<00:04, 4.37it/s, loss=1.112e+01]
Image optimization: 96%|#########6| 481/500 [01:46<00:04, 4.36it/s, loss=1.111e+01]
Image optimization: 96%|#########6| 482/500 [01:47<00:04, 4.37it/s, loss=1.109e+01]
Image optimization: 97%|#########6| 483/500 [01:47<00:03, 4.36it/s, loss=1.107e+01]
Image optimization: 97%|#########6| 484/500 [01:47<00:03, 4.36it/s, loss=1.105e+01]
Image optimization: 97%|#########7| 485/500 [01:47<00:03, 4.35it/s, loss=1.104e+01]
Image optimization: 97%|#########7| 486/500 [01:48<00:03, 4.34it/s, loss=1.103e+01]
Image optimization: 97%|#########7| 487/500 [01:48<00:02, 4.35it/s, loss=1.102e+01]
Image optimization: 98%|#########7| 488/500 [01:48<00:02, 4.35it/s, loss=1.100e+01]
Image optimization: 98%|#########7| 489/500 [01:48<00:02, 4.34it/s, loss=1.099e+01]
Image optimization: 98%|#########8| 490/500 [01:48<00:02, 4.34it/s, loss=1.097e+01]
Image optimization: 98%|#########8| 491/500 [01:49<00:02, 4.34it/s, loss=1.095e+01]
Image optimization: 98%|#########8| 492/500 [01:49<00:01, 4.33it/s, loss=1.094e+01]
Image optimization: 99%|#########8| 493/500 [01:49<00:01, 4.32it/s, loss=1.093e+01]
Image optimization: 99%|#########8| 494/500 [01:49<00:01, 4.35it/s, loss=1.091e+01]
Image optimization: 99%|#########9| 495/500 [01:50<00:01, 4.35it/s, loss=1.089e+01]
Image optimization: 99%|#########9| 496/500 [01:50<00:00, 4.34it/s, loss=1.087e+01]
Image optimization: 99%|#########9| 497/500 [01:50<00:00, 4.35it/s, loss=1.086e+01]
Image optimization: 100%|#########9| 498/500 [01:50<00:00, 4.33it/s, loss=1.085e+01]
Image optimization: 100%|#########9| 499/500 [01:51<00:00, 4.33it/s, loss=1.083e+01]
Image optimization: 100%|##########| 500/500 [01:51<00:00, 4.35it/s, loss=1.082e+01]
Image optimization: 100%|##########| 500/500 [01:51<00:00, 4.49it/s, loss=1.082e+01]
After the NST is complete we show the result.
187 show_image(output_image, title="Output image")
Conclusion¶
If you started with the basic NST example without pystiche
this example hopefully
convinced you that pystiche
is a helpful tool. But this was just the beginning:
to unleash its full potential head over to the more advanced examples.
Total running time of the script: ( 1 minutes 54.637 seconds)
Estimated memory usage: 2300 MB
Note
Click here to download the full example code
Multi-layer Encoder¶
This example showcases the pystiche.enc.MultiLayerEncoder
.
We start this example by importing everything we need.
12 import itertools
13 import time
14 from collections import OrderedDict
15 from math import floor, log10
16
17 import torch
18 from torch import nn
19 from torchvision import models
20
21 import pystiche
22 from pystiche import enc
23
24 print(f"I'm working with pystiche=={pystiche.__version__}")
Out:
I'm working with pystiche==1.1.0.dev44+gd9e3fd8
In a second preliminary step we define some helper functions to ease the performance analysis later on.
31 SI_PREFIXES = {0: "", -3: "m", -6: "µ"}
32
33
34 def timeit(fn, times=10, cleanup=None):
35 total = 0.0
36 for _ in range(times):
37 start = time.time()
38 fn()
39 stop = time.time()
40 total += stop - start
41 if cleanup:
42 cleanup()
43 return total / times
44
45
46 def feng(num, unit, digits=3):
47 exp = int(floor(log10(num)))
48 exp -= exp % 3
49 sig = num * 10 ** -exp
50 prec = digits - len(str(int(sig)))
51 return f"{sig:.{prec}f} {SI_PREFIXES[exp]}{unit}"
52
53
54 def fsecs(seconds):
55 return feng(seconds, "s")
56
57
58 def ftimeit(fn, msg="The execution took {seconds}.", **kwargs):
59 return msg.format(seconds=fsecs(timeit(fn, **kwargs)))
60
61
62 def fdifftimeit(seq_fn, mle_fn, **kwargs):
63 time_seq = timeit(seq_fn, **kwargs)
64 time_mle = timeit(mle_fn, **kwargs)
65
66 abs_diff = time_mle - time_seq
67 rel_diff = abs_diff / time_seq
68
69 if abs_diff >= 0:
70 return (
71 f"Encoding the input with the enc.MultiLayerEncoder was "
72 f"{fsecs(abs_diff)} ({rel_diff:.0%}) slower."
73 )
74 else:
75 return "\n".join(
76 (
77 "Due to the very rough timing method used here, ",
78 "we detected a case where the encoding with the enc.MultiLayerEncoder ",
79 "was actually faster than the boiler-plate nn.Sequential. ",
80 "Since the enc.MultiLayerEncoder has some overhead, ",
81 "this is a measuring error. ",
82 "Still, this serves as indicator that the overhead is small enough, ",
83 "to be well in the measuring tolerance.",
84 )
85 )
Next up, we define the device we will be testing on as well as the input dimensions.
Note
We encourage the user to play with these parameters and see how the results change. In order to do that, you can use the download buttons at the bottom of this page.
96 device = torch.device("cpu")
97
98 batch_size = 32
99 num_channels = 3
100 height = width = 512
101
102 input = torch.rand((batch_size, num_channels, height, width), device=device)
As a toy example to showcase the MultiLayerEncoder
capabilities, we will use a CNN with three layers.
109 conv = nn.Conv2d(num_channels, num_channels, 3, padding=1)
110 relu = nn.ReLU(inplace=False)
111 pool = nn.MaxPool2d(2)
112
113 modules = [("conv", conv), ("relu", relu), ("pool", pool)]
114
115 seq = nn.Sequential(OrderedDict(modules)).to(device)
116 mle = enc.MultiLayerEncoder(modules).to(device)
117 print(mle)
Out:
MultiLayerEncoder(
(conv): Conv2d(3, 3, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
(relu): ReLU()
(pool): MaxPool2d(kernel_size=2, stride=2, padding=0, dilation=1, ceil_mode=False)
)
Before we dive into the additional functionalities of the
MultiLayerEncoder
we perform a smoke test and assert that it
indeed does the same as an torch.nn.Sequential
with the same layers.
125 assert torch.allclose(mle(input), seq(input))
126 print(fdifftimeit(lambda: seq(input), lambda: mle(input)))
Out:
Due to the very rough timing method used here,
we detected a case where the encoding with the enc.MultiLayerEncoder
was actually faster than the boiler-plate nn.Sequential.
Since the enc.MultiLayerEncoder has some overhead,
this is a measuring error.
Still, this serves as indicator that the overhead is small enough,
to be well in the measuring tolerance.
As we saw, the MultiLayerEncoder
produces the same output as
an torch.nn.Sequential
but is slower. In the following we will learn what
other functionalities a MultiLayerEncoder
has to offer that
justify this overhead.
Intermediate feature maps¶
By calling the multi-layer encoder with a layer name in addition to the input, the
intermediate layers of the MultiLayerEncoder
can be accessed.
This is helpful if one needs the feature maps from different layers of a model, as is
often the case during an NST.
143 assert torch.allclose(mle(input, "conv"), conv(input))
144 assert torch.allclose(mle(input, "relu"), relu(conv(input)))
145 assert torch.allclose(mle(input, "pool"), pool(relu(conv(input))))
For convenience, one can extract a pystiche.enc.SingleLayerEncoder
as an
interface to the multi-layer encoder for a specific layer.
152 sle = mle.extract_encoder("conv")
153 assert torch.allclose(sle(input), conv(input))
Caching¶
If the access intermediate feature maps is necessary, as is usually the case in an NST, it is important to only compute every layer once.
A MultiLayerEncoder()
enables this functionality by caching
already computed feature maps. Thus, after an input is cached, retrieving it is a
constant time lookup
In order to enable caching for a layer, it has to be registered first.
Note
The internal cache will be automatically cleared during the backward pass. Since we
don’t perform that here, we need to clear it manually by calling
clear_cache()
Note
extract_encoder()
automatically registers the
layer for caching.
180 shallow_layers = ("conv", "relu")
181 for layer in shallow_layers:
182 mle.register_layer(layer)
183
184 mle(input)
185
186 for layer in shallow_layers:
187 print(
188 ftimeit(
189 lambda: mle(input, layer),
190 (
191 f"After the forward pass was completed once for the input, "
192 f"extracting the encoding of the intermediate layer '{layer}' "
193 f"took {{seconds}}."
194 ),
195 )
196 )
197
198 mle.clear_cache()
Out:
After the forward pass was completed once for the input, extracting the encoding of the intermediate layer 'conv' took 6.70 µs.
After the forward pass was completed once for the input, extracting the encoding of the intermediate layer 'relu' took 3.36 µs.
Due to this caching, it doesn’t matter in which order the feature maps are requested:
If a shallow layer is requested before a deeper one, the encoding is later resumed from the feature map of the shallow layer.
If a deep layer is requested before a more shallow one, the feature map of the shallow one is cached while computing the deep layer.
210 def fn(layers):
211 for layer in layers:
212 mle(input, layer)
213
214
215 for permutation in itertools.permutations(("conv", "relu", "pool")):
216 order = f"""'{"' -> '".join(permutation)}'"""
217 print(
218 ftimeit(
219 lambda: fn(permutation),
220 f"The encoding of layers {order} took {{seconds}}.",
221 cleanup=mle.clear_cache,
222 )
223 )
Out:
The encoding of layers 'conv' -> 'relu' -> 'pool' took 360 ms.
The encoding of layers 'conv' -> 'pool' -> 'relu' took 327 ms.
The encoding of layers 'relu' -> 'conv' -> 'pool' took 360 ms.
The encoding of layers 'relu' -> 'pool' -> 'conv' took 360 ms.
The encoding of layers 'pool' -> 'conv' -> 'relu' took 328 ms.
The encoding of layers 'pool' -> 'relu' -> 'conv' took 327 ms.
Real-world example¶
Up to this point we used a toy example to demonstrate the capabilities of a
MultiLayerEncoder
. In addition to the boiler-plate
MultiLayerEncoder
, pystiche
has builtin implementations of
some well-known CNN architectures that are commonly used in NST papers.
Note
By default, vgg19_multi_layer_encoder()
loads weights provided
by torchvision
. We disable this here since we load the randomly initilaized
weights of the torchvision
model to enable a comparison.
Note
By default, vgg19_multi_layer_encoder()
adds an
internal_preprocessing
so that the user can simply pass the image as is,
without worrying about it. We disable this here to enable a comparison.
Note
By default, vgg19_multi_layer_encoder()
disallows in-place
operations since after they are carried out, the previous encoding is no longer
accessible. In order to enable a fair performance comparison, we allow them here,
since they are also used in vgg19()
.
Note
The fully connected stage of the original VGG19 architecture requires the input to
be exactly 224 pixels wide and high [SZ14]. Since this requirement can
usually not be met in an NST, the builtin multi-layer encoder only comprises the
size invariant convolutional stage. Thus, we only use vgg19().features
to
enable a comparison.
262 seq = models.vgg19()
263 mle = enc.vgg19_multi_layer_encoder(
264 pretrained=False, internal_preprocessing=False, allow_inplace=True
265 )
266 mle.load_state_dict(seq.state_dict())
267
268 input = torch.rand((4, 3, 256, 256), device=device)
269
270 assert torch.allclose(mle(input), seq.features(input))
271 print(fdifftimeit(lambda: seq.features(input), lambda: mle(input)))
Out:
Due to the very rough timing method used here,
we detected a case where the encoding with the enc.MultiLayerEncoder
was actually faster than the boiler-plate nn.Sequential.
Since the enc.MultiLayerEncoder has some overhead,
this is a measuring error.
Still, this serves as indicator that the overhead is small enough,
to be well in the measuring tolerance.
Total running time of the script: ( 0 minutes 55.868 seconds)
Estimated memory usage: 0 MB
Advanced¶
Note
Click here to download the full example code
Guided image optimization¶
This example showcases how a guided, i.e. regionally constraint, NST can be performed
in pystiche
.
Usually, the style_loss
discards spatial information since the style elements
should be able to be synthesized regardless of their position in the
style_image
. Especially for images with clear separated regions style elements
might leak into regions where they fit well with respect to the perceptual loss, but
don’t belong for a human observer. This can be overcome with spatial constraints also
called guides
([GEB+17]).
We start this example by importing everything we need and setting the device we will be working on.
21 import pystiche
22 from pystiche import demo, enc, loss, optim
23 from pystiche.image import guides_to_segmentation, show_image
24 from pystiche.misc import get_device, get_input_image
25
26 print(f"I'm working with pystiche=={pystiche.__version__}")
27
28 device = get_device()
29 print(f"I'm working with {device}")
Out:
I'm working with pystiche==1.1.0.dev44+gd9e3fd8
I'm working with cuda
In a first step we load and show the images that will be used in the NST.
35 images = demo.images()
36 images.download()
37 size = 500
41 content_image = images["castle"].read(size=size, device=device)
42 show_image(content_image)
47 style_image = images["church"].read(size=size, device=device)
48 show_image(style_image)
Unguided image optimization¶
As a baseline we use a default NST with a
FeatureReconstructionLoss
as content_loss
and
GramLoss
as style_loss
.
59 multi_layer_encoder = enc.vgg19_multi_layer_encoder()
60
61 content_layer = "relu4_2"
62 content_encoder = multi_layer_encoder.extract_encoder(content_layer)
63 content_weight = 1e0
64 content_loss = loss.FeatureReconstructionLoss(
65 content_encoder, score_weight=content_weight
66 )
67
68 style_layers = ("relu1_1", "relu2_1", "relu3_1", "relu4_1", "relu5_1")
69 style_weight = 1e4
70
71
72 def get_style_op(encoder, layer_weight):
73 return loss.GramLoss(encoder, score_weight=layer_weight)
74
75
76 style_loss = loss.MultiLayerEncodingLoss(
77 multi_layer_encoder, style_layers, get_style_op, score_weight=style_weight,
78 )
79
80
81 perceptual_loss = loss.PerceptualLoss(content_loss, style_loss).to(device)
82 print(perceptual_loss)
Out:
PerceptualLoss(
(content_loss): FeatureReconstructionLoss(
(encoder): VGGMultiLayerEncoder(layer=relu4_2, arch=vgg19, framework=torch)
)
(style_loss): MultiLayerEncodingLoss(
encoder=VGGMultiLayerEncoder(arch=vgg19, framework=torch), score_weight=10000
(relu1_1): GramLoss(score_weight=0.2)
(relu2_1): GramLoss(score_weight=0.2)
(relu3_1): GramLoss(score_weight=0.2)
(relu4_1): GramLoss(score_weight=0.2)
(relu5_1): GramLoss(score_weight=0.2)
)
)
We set the target images for the optimization criterion
.
88 perceptual_loss.set_content_image(content_image)
89 perceptual_loss.set_style_image(style_image)
We perform the unguided NST and show the result.
95 starting_point = "content"
96 input_image = get_input_image(starting_point, content_image=content_image)
97
98 output_image = optim.image_optimization(input_image, perceptual_loss, num_steps=500)
Out:
Image optimization: 0%| | 0/500 [00:00<?, ?it/s]
Image optimization: 0%| | 1/500 [00:00<02:40, 3.10it/s, loss=1.242e+04]
Image optimization: 0%| | 2/500 [00:00<02:19, 3.58it/s, loss=1.242e+04]
Image optimization: 1%| | 3/500 [00:00<02:12, 3.76it/s, loss=9.335e+03]
Image optimization: 1%| | 4/500 [00:01<02:10, 3.80it/s, loss=7.134e+03]
Image optimization: 1%|1 | 5/500 [00:01<02:09, 3.83it/s, loss=5.423e+03]
Image optimization: 1%|1 | 6/500 [00:01<02:07, 3.88it/s, loss=4.046e+03]
Image optimization: 1%|1 | 7/500 [00:01<02:06, 3.91it/s, loss=3.279e+03]
Image optimization: 2%|1 | 8/500 [00:02<02:06, 3.90it/s, loss=2.776e+03]
Image optimization: 2%|1 | 9/500 [00:02<02:06, 3.90it/s, loss=2.492e+03]
Image optimization: 2%|2 | 10/500 [00:02<02:05, 3.91it/s, loss=1.751e+03]
Image optimization: 2%|2 | 11/500 [00:02<02:04, 3.92it/s, loss=1.437e+03]
Image optimization: 2%|2 | 12/500 [00:03<02:05, 3.90it/s, loss=1.235e+03]
Image optimization: 3%|2 | 13/500 [00:03<02:05, 3.89it/s, loss=1.141e+03]
Image optimization: 3%|2 | 14/500 [00:03<02:04, 3.90it/s, loss=1.085e+03]
Image optimization: 3%|3 | 15/500 [00:03<02:04, 3.90it/s, loss=1.004e+03]
Image optimization: 3%|3 | 16/500 [00:04<02:04, 3.88it/s, loss=8.634e+02]
Image optimization: 3%|3 | 17/500 [00:04<02:04, 3.88it/s, loss=7.951e+02]
Image optimization: 4%|3 | 18/500 [00:04<02:04, 3.88it/s, loss=7.215e+02]
Image optimization: 4%|3 | 19/500 [00:04<02:04, 3.87it/s, loss=7.037e+02]
Image optimization: 4%|4 | 20/500 [00:05<02:04, 3.85it/s, loss=6.588e+02]
Image optimization: 4%|4 | 21/500 [00:05<02:04, 3.85it/s, loss=6.298e+02]
Image optimization: 4%|4 | 22/500 [00:05<02:04, 3.85it/s, loss=5.892e+02]
Image optimization: 5%|4 | 23/500 [00:05<02:04, 3.84it/s, loss=5.617e+02]
Image optimization: 5%|4 | 24/500 [00:06<02:03, 3.84it/s, loss=5.468e+02]
Image optimization: 5%|5 | 25/500 [00:06<02:04, 3.83it/s, loss=5.325e+02]
Image optimization: 5%|5 | 26/500 [00:06<02:04, 3.82it/s, loss=5.025e+02]
Image optimization: 5%|5 | 27/500 [00:07<02:04, 3.81it/s, loss=4.754e+02]
Image optimization: 6%|5 | 28/500 [00:07<02:04, 3.81it/s, loss=4.613e+02]
Image optimization: 6%|5 | 29/500 [00:07<02:03, 3.80it/s, loss=4.496e+02]
Image optimization: 6%|6 | 30/500 [00:07<02:03, 3.80it/s, loss=4.390e+02]
Image optimization: 6%|6 | 31/500 [00:08<02:03, 3.79it/s, loss=4.265e+02]
Image optimization: 6%|6 | 32/500 [00:08<02:03, 3.78it/s, loss=4.138e+02]
Image optimization: 7%|6 | 33/500 [00:08<02:03, 3.78it/s, loss=4.018e+02]
Image optimization: 7%|6 | 34/500 [00:08<02:03, 3.78it/s, loss=3.931e+02]
Image optimization: 7%|7 | 35/500 [00:09<02:03, 3.78it/s, loss=3.873e+02]
Image optimization: 7%|7 | 36/500 [00:09<02:03, 3.77it/s, loss=3.794e+02]
Image optimization: 7%|7 | 37/500 [00:09<02:02, 3.77it/s, loss=3.726e+02]
Image optimization: 8%|7 | 38/500 [00:09<02:02, 3.76it/s, loss=3.571e+02]
Image optimization: 8%|7 | 39/500 [00:10<02:02, 3.76it/s, loss=3.497e+02]
Image optimization: 8%|8 | 40/500 [00:10<02:02, 3.75it/s, loss=3.388e+02]
Image optimization: 8%|8 | 41/500 [00:10<02:02, 3.74it/s, loss=3.337e+02]
Image optimization: 8%|8 | 42/500 [00:11<02:02, 3.74it/s, loss=3.293e+02]
Image optimization: 9%|8 | 43/500 [00:11<02:02, 3.73it/s, loss=3.261e+02]
Image optimization: 9%|8 | 44/500 [00:11<02:02, 3.72it/s, loss=3.224e+02]
Image optimization: 9%|9 | 45/500 [00:11<02:02, 3.72it/s, loss=3.176e+02]
Image optimization: 9%|9 | 46/500 [00:12<02:02, 3.72it/s, loss=3.064e+02]
Image optimization: 9%|9 | 47/500 [00:12<02:02, 3.70it/s, loss=3.139e+02]
Image optimization: 10%|9 | 48/500 [00:12<02:02, 3.70it/s, loss=2.983e+02]
Image optimization: 10%|9 | 49/500 [00:12<02:01, 3.71it/s, loss=2.959e+02]
Image optimization: 10%|# | 50/500 [00:13<02:01, 3.70it/s, loss=2.928e+02]
Image optimization: 10%|# | 51/500 [00:13<02:01, 3.69it/s, loss=2.837e+02]
Image optimization: 10%|# | 52/500 [00:13<02:01, 3.69it/s, loss=2.791e+02]
Image optimization: 11%|# | 53/500 [00:13<02:01, 3.68it/s, loss=2.756e+02]
Image optimization: 11%|# | 54/500 [00:14<02:01, 3.67it/s, loss=2.729e+02]
Image optimization: 11%|#1 | 55/500 [00:14<02:01, 3.67it/s, loss=2.706e+02]
Image optimization: 11%|#1 | 56/500 [00:14<02:01, 3.67it/s, loss=2.671e+02]
Image optimization: 11%|#1 | 57/500 [00:15<02:01, 3.65it/s, loss=2.621e+02]
Image optimization: 12%|#1 | 58/500 [00:15<02:01, 3.65it/s, loss=2.588e+02]
Image optimization: 12%|#1 | 59/500 [00:15<02:00, 3.65it/s, loss=2.550e+02]
Image optimization: 12%|#2 | 60/500 [00:15<02:00, 3.65it/s, loss=2.511e+02]
Image optimization: 12%|#2 | 61/500 [00:16<02:00, 3.63it/s, loss=2.480e+02]
Image optimization: 12%|#2 | 62/500 [00:16<02:00, 3.63it/s, loss=2.455e+02]
Image optimization: 13%|#2 | 63/500 [00:16<02:00, 3.62it/s, loss=2.432e+02]
Image optimization: 13%|#2 | 64/500 [00:17<02:00, 3.62it/s, loss=2.395e+02]
Image optimization: 13%|#3 | 65/500 [00:17<02:00, 3.62it/s, loss=2.360e+02]
Image optimization: 13%|#3 | 66/500 [00:17<02:00, 3.61it/s, loss=2.333e+02]
Image optimization: 13%|#3 | 67/500 [00:17<02:00, 3.60it/s, loss=2.315e+02]
Image optimization: 14%|#3 | 68/500 [00:18<02:00, 3.60it/s, loss=2.296e+02]
Image optimization: 14%|#3 | 69/500 [00:18<01:59, 3.59it/s, loss=2.261e+02]
Image optimization: 14%|#4 | 70/500 [00:18<01:59, 3.59it/s, loss=2.228e+02]
Image optimization: 14%|#4 | 71/500 [00:18<01:59, 3.58it/s, loss=2.198e+02]
Image optimization: 14%|#4 | 72/500 [00:19<01:59, 3.58it/s, loss=2.186e+02]
Image optimization: 15%|#4 | 73/500 [00:19<01:59, 3.57it/s, loss=2.166e+02]
Image optimization: 15%|#4 | 74/500 [00:19<01:59, 3.57it/s, loss=2.151e+02]
Image optimization: 15%|#5 | 75/500 [00:20<01:59, 3.56it/s, loss=2.129e+02]
Image optimization: 15%|#5 | 76/500 [00:20<01:59, 3.55it/s, loss=2.099e+02]
Image optimization: 15%|#5 | 77/500 [00:20<01:59, 3.54it/s, loss=2.072e+02]
Image optimization: 16%|#5 | 78/500 [00:20<01:59, 3.53it/s, loss=2.049e+02]
Image optimization: 16%|#5 | 79/500 [00:21<01:59, 3.54it/s, loss=2.036e+02]
Image optimization: 16%|#6 | 80/500 [00:21<01:58, 3.53it/s, loss=2.017e+02]
Image optimization: 16%|#6 | 81/500 [00:21<01:58, 3.54it/s, loss=2.000e+02]
Image optimization: 16%|#6 | 82/500 [00:22<01:57, 3.55it/s, loss=1.974e+02]
Image optimization: 17%|#6 | 83/500 [00:22<01:58, 3.53it/s, loss=1.955e+02]
Image optimization: 17%|#6 | 84/500 [00:22<01:58, 3.52it/s, loss=1.943e+02]
Image optimization: 17%|#7 | 85/500 [00:22<01:58, 3.51it/s, loss=1.925e+02]
Image optimization: 17%|#7 | 86/500 [00:23<01:57, 3.52it/s, loss=1.911e+02]
Image optimization: 17%|#7 | 87/500 [00:23<01:57, 3.52it/s, loss=1.895e+02]
Image optimization: 18%|#7 | 88/500 [00:23<01:57, 3.50it/s, loss=1.872e+02]
Image optimization: 18%|#7 | 89/500 [00:24<01:57, 3.51it/s, loss=1.854e+02]
Image optimization: 18%|#8 | 90/500 [00:24<01:57, 3.50it/s, loss=1.844e+02]
Image optimization: 18%|#8 | 91/500 [00:24<01:56, 3.50it/s, loss=1.837e+02]
Image optimization: 18%|#8 | 92/500 [00:24<01:56, 3.50it/s, loss=1.819e+02]
Image optimization: 19%|#8 | 93/500 [00:25<01:56, 3.50it/s, loss=1.813e+02]
Image optimization: 19%|#8 | 94/500 [00:25<01:56, 3.49it/s, loss=1.796e+02]
Image optimization: 19%|#9 | 95/500 [00:25<01:56, 3.48it/s, loss=1.781e+02]
Image optimization: 19%|#9 | 96/500 [00:26<01:56, 3.47it/s, loss=1.760e+02]
Image optimization: 19%|#9 | 97/500 [00:26<01:56, 3.47it/s, loss=1.745e+02]
Image optimization: 20%|#9 | 98/500 [00:26<01:55, 3.47it/s, loss=1.736e+02]
Image optimization: 20%|#9 | 99/500 [00:26<01:55, 3.47it/s, loss=1.723e+02]
Image optimization: 20%|## | 100/500 [00:27<01:55, 3.47it/s, loss=1.712e+02]
Image optimization: 20%|## | 101/500 [00:27<01:55, 3.46it/s, loss=1.696e+02]
Image optimization: 20%|## | 102/500 [00:27<01:55, 3.46it/s, loss=1.685e+02]
Image optimization: 21%|## | 103/500 [00:28<01:54, 3.46it/s, loss=1.679e+02]
Image optimization: 21%|## | 104/500 [00:28<01:54, 3.45it/s, loss=1.667e+02]
Image optimization: 21%|##1 | 105/500 [00:28<01:54, 3.44it/s, loss=1.656e+02]
Image optimization: 21%|##1 | 106/500 [00:28<01:54, 3.44it/s, loss=1.644e+02]
Image optimization: 21%|##1 | 107/500 [00:29<01:53, 3.45it/s, loss=1.631e+02]
Image optimization: 22%|##1 | 108/500 [00:29<01:53, 3.46it/s, loss=1.617e+02]
Image optimization: 22%|##1 | 109/500 [00:29<01:53, 3.43it/s, loss=1.608e+02]
Image optimization: 22%|##2 | 110/500 [00:30<01:53, 3.43it/s, loss=1.598e+02]
Image optimization: 22%|##2 | 111/500 [00:30<01:52, 3.45it/s, loss=1.589e+02]
Image optimization: 22%|##2 | 112/500 [00:30<01:52, 3.44it/s, loss=1.575e+02]
Image optimization: 23%|##2 | 113/500 [00:31<01:52, 3.43it/s, loss=1.562e+02]
Image optimization: 23%|##2 | 114/500 [00:31<01:52, 3.43it/s, loss=1.553e+02]
Image optimization: 23%|##3 | 115/500 [00:31<01:51, 3.44it/s, loss=1.543e+02]
Image optimization: 23%|##3 | 116/500 [00:31<01:52, 3.42it/s, loss=1.540e+02]
Image optimization: 23%|##3 | 117/500 [00:32<01:51, 3.43it/s, loss=1.527e+02]
Image optimization: 24%|##3 | 118/500 [00:32<01:51, 3.43it/s, loss=1.522e+02]
Image optimization: 24%|##3 | 119/500 [00:32<01:51, 3.42it/s, loss=1.508e+02]
Image optimization: 24%|##4 | 120/500 [00:33<01:51, 3.42it/s, loss=1.493e+02]
Image optimization: 24%|##4 | 121/500 [00:33<01:50, 3.42it/s, loss=1.481e+02]
Image optimization: 24%|##4 | 122/500 [00:33<01:50, 3.42it/s, loss=1.475e+02]
Image optimization: 25%|##4 | 123/500 [00:33<01:50, 3.42it/s, loss=1.466e+02]
Image optimization: 25%|##4 | 124/500 [00:34<01:50, 3.42it/s, loss=1.462e+02]
Image optimization: 25%|##5 | 125/500 [00:34<01:49, 3.42it/s, loss=1.449e+02]
Image optimization: 25%|##5 | 126/500 [00:34<01:49, 3.41it/s, loss=1.443e+02]
Image optimization: 25%|##5 | 127/500 [00:35<01:49, 3.42it/s, loss=1.438e+02]
Image optimization: 26%|##5 | 128/500 [00:35<01:48, 3.42it/s, loss=1.429e+02]
Image optimization: 26%|##5 | 129/500 [00:35<01:48, 3.42it/s, loss=1.418e+02]
Image optimization: 26%|##6 | 130/500 [00:35<01:48, 3.41it/s, loss=1.405e+02]
Image optimization: 26%|##6 | 131/500 [00:36<01:48, 3.41it/s, loss=1.395e+02]
Image optimization: 26%|##6 | 132/500 [00:36<01:47, 3.42it/s, loss=1.390e+02]
Image optimization: 27%|##6 | 133/500 [00:36<01:47, 3.42it/s, loss=1.384e+02]
Image optimization: 27%|##6 | 134/500 [00:37<01:47, 3.41it/s, loss=1.376e+02]
Image optimization: 27%|##7 | 135/500 [00:37<01:46, 3.41it/s, loss=1.364e+02]
Image optimization: 27%|##7 | 136/500 [00:37<01:46, 3.41it/s, loss=1.355e+02]
Image optimization: 27%|##7 | 137/500 [00:38<01:46, 3.41it/s, loss=1.347e+02]
Image optimization: 28%|##7 | 138/500 [00:38<01:46, 3.40it/s, loss=1.334e+02]
Image optimization: 28%|##7 | 139/500 [00:38<01:45, 3.41it/s, loss=1.326e+02]
Image optimization: 28%|##8 | 140/500 [00:38<01:45, 3.40it/s, loss=1.319e+02]
Image optimization: 28%|##8 | 141/500 [00:39<01:45, 3.41it/s, loss=1.317e+02]
Image optimization: 28%|##8 | 142/500 [00:39<01:45, 3.41it/s, loss=1.309e+02]
Image optimization: 29%|##8 | 143/500 [00:39<01:44, 3.41it/s, loss=1.304e+02]
Image optimization: 29%|##8 | 144/500 [00:40<01:44, 3.41it/s, loss=1.294e+02]
Image optimization: 29%|##9 | 145/500 [00:40<01:44, 3.41it/s, loss=1.283e+02]
Image optimization: 29%|##9 | 146/500 [00:40<01:43, 3.41it/s, loss=1.274e+02]
Image optimization: 29%|##9 | 147/500 [00:40<01:43, 3.40it/s, loss=1.266e+02]
Image optimization: 30%|##9 | 148/500 [00:41<01:43, 3.40it/s, loss=1.261e+02]
Image optimization: 30%|##9 | 149/500 [00:41<01:43, 3.40it/s, loss=1.254e+02]
Image optimization: 30%|### | 150/500 [00:41<01:42, 3.41it/s, loss=1.245e+02]
Image optimization: 30%|### | 151/500 [00:42<01:42, 3.41it/s, loss=1.234e+02]
Image optimization: 30%|### | 152/500 [00:42<01:42, 3.41it/s, loss=1.225e+02]
Image optimization: 31%|### | 153/500 [00:42<01:41, 3.41it/s, loss=1.217e+02]
Image optimization: 31%|### | 154/500 [00:43<01:41, 3.41it/s, loss=1.207e+02]
Image optimization: 31%|###1 | 155/500 [00:43<01:41, 3.41it/s, loss=1.198e+02]
Image optimization: 31%|###1 | 156/500 [00:43<01:40, 3.41it/s, loss=1.194e+02]
Image optimization: 31%|###1 | 157/500 [00:43<01:40, 3.42it/s, loss=1.190e+02]
Image optimization: 32%|###1 | 158/500 [00:44<01:40, 3.41it/s, loss=1.182e+02]
Image optimization: 32%|###1 | 159/500 [00:44<01:39, 3.42it/s, loss=1.179e+02]
Image optimization: 32%|###2 | 160/500 [00:44<01:39, 3.42it/s, loss=1.166e+02]
Image optimization: 32%|###2 | 161/500 [00:45<01:39, 3.41it/s, loss=1.159e+02]
Image optimization: 32%|###2 | 162/500 [00:45<01:39, 3.41it/s, loss=1.152e+02]
Image optimization: 33%|###2 | 163/500 [00:45<01:38, 3.41it/s, loss=1.146e+02]
Image optimization: 33%|###2 | 164/500 [00:45<01:38, 3.42it/s, loss=1.141e+02]
Image optimization: 33%|###3 | 165/500 [00:46<01:38, 3.41it/s, loss=1.137e+02]
Image optimization: 33%|###3 | 166/500 [00:46<01:37, 3.42it/s, loss=1.130e+02]
Image optimization: 33%|###3 | 167/500 [00:46<01:37, 3.42it/s, loss=1.120e+02]
Image optimization: 34%|###3 | 168/500 [00:47<01:37, 3.41it/s, loss=1.111e+02]
Image optimization: 34%|###3 | 169/500 [00:47<01:36, 3.42it/s, loss=1.108e+02]
Image optimization: 34%|###4 | 170/500 [00:47<01:36, 3.41it/s, loss=1.098e+02]
Image optimization: 34%|###4 | 171/500 [00:48<01:36, 3.42it/s, loss=1.093e+02]
Image optimization: 34%|###4 | 172/500 [00:48<01:35, 3.42it/s, loss=1.089e+02]
Image optimization: 35%|###4 | 173/500 [00:48<01:35, 3.41it/s, loss=1.081e+02]
Image optimization: 35%|###4 | 174/500 [00:48<01:35, 3.42it/s, loss=1.074e+02]
Image optimization: 35%|###5 | 175/500 [00:49<01:35, 3.41it/s, loss=1.067e+02]
Image optimization: 35%|###5 | 176/500 [00:49<01:34, 3.42it/s, loss=1.060e+02]
Image optimization: 35%|###5 | 177/500 [00:49<01:34, 3.42it/s, loss=1.056e+02]
Image optimization: 36%|###5 | 178/500 [00:50<01:34, 3.42it/s, loss=1.046e+02]
Image optimization: 36%|###5 | 179/500 [00:50<01:33, 3.42it/s, loss=1.041e+02]
Image optimization: 36%|###6 | 180/500 [00:50<01:33, 3.42it/s, loss=1.035e+02]
Image optimization: 36%|###6 | 181/500 [00:50<01:33, 3.42it/s, loss=1.028e+02]
Image optimization: 36%|###6 | 182/500 [00:51<01:32, 3.42it/s, loss=1.021e+02]
Image optimization: 37%|###6 | 183/500 [00:51<01:32, 3.42it/s, loss=1.013e+02]
Image optimization: 37%|###6 | 184/500 [00:51<01:32, 3.42it/s, loss=1.005e+02]
Image optimization: 37%|###7 | 185/500 [00:52<01:31, 3.43it/s, loss=9.974e+01]
Image optimization: 37%|###7 | 186/500 [00:52<01:31, 3.42it/s, loss=9.914e+01]
Image optimization: 37%|###7 | 187/500 [00:52<01:31, 3.42it/s, loss=9.843e+01]
Image optimization: 38%|###7 | 188/500 [00:52<01:30, 3.43it/s, loss=9.791e+01]
Image optimization: 38%|###7 | 189/500 [00:53<01:30, 3.42it/s, loss=9.759e+01]
Image optimization: 38%|###8 | 190/500 [00:53<01:30, 3.43it/s, loss=9.693e+01]
Image optimization: 38%|###8 | 191/500 [00:53<01:30, 3.42it/s, loss=9.637e+01]
Image optimization: 38%|###8 | 192/500 [00:54<01:29, 3.43it/s, loss=9.610e+01]
Image optimization: 39%|###8 | 193/500 [00:54<01:29, 3.42it/s, loss=9.552e+01]
Image optimization: 39%|###8 | 194/500 [00:54<01:29, 3.42it/s, loss=9.457e+01]
Image optimization: 39%|###9 | 195/500 [00:55<01:29, 3.43it/s, loss=9.347e+01]
Image optimization: 39%|###9 | 196/500 [00:55<01:28, 3.43it/s, loss=9.327e+01]
Image optimization: 39%|###9 | 197/500 [00:55<01:28, 3.43it/s, loss=9.263e+01]
Image optimization: 40%|###9 | 198/500 [00:55<01:28, 3.43it/s, loss=9.228e+01]
Image optimization: 40%|###9 | 199/500 [00:56<01:27, 3.42it/s, loss=9.169e+01]
Image optimization: 40%|#### | 200/500 [00:56<01:27, 3.42it/s, loss=9.139e+01]
Image optimization: 40%|#### | 201/500 [00:56<01:27, 3.42it/s, loss=9.083e+01]
Image optimization: 40%|#### | 202/500 [00:57<01:26, 3.43it/s, loss=8.980e+01]
Image optimization: 41%|#### | 203/500 [00:57<01:26, 3.43it/s, loss=8.888e+01]
Image optimization: 41%|#### | 204/500 [00:57<01:26, 3.43it/s, loss=8.819e+01]
Image optimization: 41%|####1 | 205/500 [00:57<01:25, 3.43it/s, loss=8.790e+01]
Image optimization: 41%|####1 | 206/500 [00:58<01:25, 3.43it/s, loss=8.726e+01]
Image optimization: 41%|####1 | 207/500 [00:58<01:25, 3.43it/s, loss=8.688e+01]
Image optimization: 42%|####1 | 208/500 [00:58<01:25, 3.43it/s, loss=8.633e+01]
Image optimization: 42%|####1 | 209/500 [00:59<01:24, 3.43it/s, loss=8.543e+01]
Image optimization: 42%|####2 | 210/500 [00:59<01:24, 3.42it/s, loss=8.472e+01]
Image optimization: 42%|####2 | 211/500 [00:59<01:24, 3.42it/s, loss=8.432e+01]
Image optimization: 42%|####2 | 212/500 [00:59<01:24, 3.43it/s, loss=8.389e+01]
Image optimization: 43%|####2 | 213/500 [01:00<01:23, 3.43it/s, loss=8.326e+01]
Image optimization: 43%|####2 | 214/500 [01:00<01:23, 3.43it/s, loss=8.254e+01]
Image optimization: 43%|####3 | 215/500 [01:00<01:23, 3.43it/s, loss=8.175e+01]
Image optimization: 43%|####3 | 216/500 [01:01<01:22, 3.43it/s, loss=8.107e+01]
Image optimization: 43%|####3 | 217/500 [01:01<01:22, 3.43it/s, loss=8.112e+01]
Image optimization: 44%|####3 | 218/500 [01:01<01:22, 3.43it/s, loss=8.018e+01]
Image optimization: 44%|####3 | 219/500 [01:02<01:21, 3.43it/s, loss=7.987e+01]
Image optimization: 44%|####4 | 220/500 [01:02<01:21, 3.43it/s, loss=7.916e+01]
Image optimization: 44%|####4 | 221/500 [01:02<01:21, 3.43it/s, loss=7.827e+01]
Image optimization: 44%|####4 | 222/500 [01:02<01:20, 3.43it/s, loss=7.764e+01]
Image optimization: 45%|####4 | 223/500 [01:03<01:20, 3.43it/s, loss=7.708e+01]
Image optimization: 45%|####4 | 224/500 [01:03<01:20, 3.43it/s, loss=7.680e+01]
Image optimization: 45%|####5 | 225/500 [01:03<01:20, 3.43it/s, loss=7.639e+01]
Image optimization: 45%|####5 | 226/500 [01:04<01:19, 3.43it/s, loss=7.573e+01]
Image optimization: 45%|####5 | 227/500 [01:04<01:19, 3.43it/s, loss=7.500e+01]
Image optimization: 46%|####5 | 228/500 [01:04<01:19, 3.43it/s, loss=7.444e+01]
Image optimization: 46%|####5 | 229/500 [01:04<01:19, 3.43it/s, loss=7.390e+01]
Image optimization: 46%|####6 | 230/500 [01:05<01:18, 3.43it/s, loss=7.358e+01]
Image optimization: 46%|####6 | 231/500 [01:05<01:18, 3.43it/s, loss=7.327e+01]
Image optimization: 46%|####6 | 232/500 [01:05<01:17, 3.44it/s, loss=7.278e+01]
Image optimization: 47%|####6 | 233/500 [01:06<01:17, 3.43it/s, loss=7.236e+01]
Image optimization: 47%|####6 | 234/500 [01:06<01:17, 3.43it/s, loss=7.156e+01]
Image optimization: 47%|####6 | 235/500 [01:06<01:17, 3.43it/s, loss=7.130e+01]
Image optimization: 47%|####7 | 236/500 [01:06<01:17, 3.43it/s, loss=7.054e+01]
Image optimization: 47%|####7 | 237/500 [01:07<01:16, 3.43it/s, loss=7.036e+01]
Image optimization: 48%|####7 | 238/500 [01:07<01:16, 3.43it/s, loss=7.000e+01]
Image optimization: 48%|####7 | 239/500 [01:07<01:16, 3.43it/s, loss=6.965e+01]
Image optimization: 48%|####8 | 240/500 [01:08<01:15, 3.43it/s, loss=6.898e+01]
Image optimization: 48%|####8 | 241/500 [01:08<01:15, 3.43it/s, loss=6.839e+01]
Image optimization: 48%|####8 | 242/500 [01:08<01:15, 3.43it/s, loss=6.782e+01]
Image optimization: 49%|####8 | 243/500 [01:09<01:14, 3.43it/s, loss=6.749e+01]
Image optimization: 49%|####8 | 244/500 [01:09<01:14, 3.43it/s, loss=6.697e+01]
Image optimization: 49%|####9 | 245/500 [01:09<01:14, 3.43it/s, loss=6.642e+01]
Image optimization: 49%|####9 | 246/500 [01:09<01:13, 3.43it/s, loss=6.589e+01]
Image optimization: 49%|####9 | 247/500 [01:10<01:13, 3.42it/s, loss=6.549e+01]
Image optimization: 50%|####9 | 248/500 [01:10<01:13, 3.42it/s, loss=6.512e+01]
Image optimization: 50%|####9 | 249/500 [01:10<01:13, 3.43it/s, loss=6.477e+01]
Image optimization: 50%|##### | 250/500 [01:11<01:12, 3.43it/s, loss=6.415e+01]
Image optimization: 50%|##### | 251/500 [01:11<01:12, 3.42it/s, loss=6.369e+01]
Image optimization: 50%|##### | 252/500 [01:11<01:12, 3.43it/s, loss=6.319e+01]
Image optimization: 51%|##### | 253/500 [01:11<01:12, 3.43it/s, loss=6.274e+01]
Image optimization: 51%|##### | 254/500 [01:12<01:11, 3.43it/s, loss=6.249e+01]
Image optimization: 51%|#####1 | 255/500 [01:12<01:11, 3.43it/s, loss=6.207e+01]
Image optimization: 51%|#####1 | 256/500 [01:12<01:11, 3.43it/s, loss=6.177e+01]
Image optimization: 51%|#####1 | 257/500 [01:13<01:10, 3.43it/s, loss=6.137e+01]
Image optimization: 52%|#####1 | 258/500 [01:13<01:10, 3.43it/s, loss=6.102e+01]
Image optimization: 52%|#####1 | 259/500 [01:13<01:10, 3.43it/s, loss=6.045e+01]
Image optimization: 52%|#####2 | 260/500 [01:13<01:09, 3.43it/s, loss=5.997e+01]
Image optimization: 52%|#####2 | 261/500 [01:14<01:09, 3.43it/s, loss=5.957e+01]
Image optimization: 52%|#####2 | 262/500 [01:14<01:09, 3.43it/s, loss=5.924e+01]
Image optimization: 53%|#####2 | 263/500 [01:14<01:09, 3.43it/s, loss=5.897e+01]
Image optimization: 53%|#####2 | 264/500 [01:15<01:08, 3.43it/s, loss=5.869e+01]
Image optimization: 53%|#####3 | 265/500 [01:15<01:08, 3.44it/s, loss=5.842e+01]
Image optimization: 53%|#####3 | 266/500 [01:15<01:08, 3.43it/s, loss=5.810e+01]
Image optimization: 53%|#####3 | 267/500 [01:16<01:07, 3.43it/s, loss=5.751e+01]
Image optimization: 54%|#####3 | 268/500 [01:16<01:07, 3.43it/s, loss=5.711e+01]
Image optimization: 54%|#####3 | 269/500 [01:16<01:07, 3.43it/s, loss=5.673e+01]
Image optimization: 54%|#####4 | 270/500 [01:16<01:07, 3.43it/s, loss=5.649e+01]
Image optimization: 54%|#####4 | 271/500 [01:17<01:06, 3.43it/s, loss=5.619e+01]
Image optimization: 54%|#####4 | 272/500 [01:17<01:06, 3.44it/s, loss=5.574e+01]
Image optimization: 55%|#####4 | 273/500 [01:17<01:06, 3.43it/s, loss=5.608e+01]
Image optimization: 55%|#####4 | 274/500 [01:18<01:05, 3.43it/s, loss=5.514e+01]
Image optimization: 55%|#####5 | 275/500 [01:18<01:05, 3.44it/s, loss=5.495e+01]
Image optimization: 55%|#####5 | 276/500 [01:18<01:05, 3.44it/s, loss=5.460e+01]
Image optimization: 55%|#####5 | 277/500 [01:18<01:05, 3.43it/s, loss=5.422e+01]
Image optimization: 56%|#####5 | 278/500 [01:19<01:04, 3.43it/s, loss=5.374e+01]
Image optimization: 56%|#####5 | 279/500 [01:19<01:04, 3.43it/s, loss=5.345e+01]
Image optimization: 56%|#####6 | 280/500 [01:19<01:04, 3.43it/s, loss=5.320e+01]
Image optimization: 56%|#####6 | 281/500 [01:20<01:03, 3.44it/s, loss=5.295e+01]
Image optimization: 56%|#####6 | 282/500 [01:20<01:03, 3.43it/s, loss=5.280e+01]
Image optimization: 57%|#####6 | 283/500 [01:20<01:03, 3.44it/s, loss=5.240e+01]
Image optimization: 57%|#####6 | 284/500 [01:20<01:02, 3.43it/s, loss=5.199e+01]
Image optimization: 57%|#####6 | 285/500 [01:21<01:02, 3.43it/s, loss=5.159e+01]
Image optimization: 57%|#####7 | 286/500 [01:21<01:02, 3.43it/s, loss=5.133e+01]
Image optimization: 57%|#####7 | 287/500 [01:21<01:02, 3.43it/s, loss=5.119e+01]
Image optimization: 58%|#####7 | 288/500 [01:22<01:01, 3.43it/s, loss=5.089e+01]
Image optimization: 58%|#####7 | 289/500 [01:22<01:01, 3.43it/s, loss=5.072e+01]
Image optimization: 58%|#####8 | 290/500 [01:22<01:01, 3.43it/s, loss=5.049e+01]
Image optimization: 58%|#####8 | 291/500 [01:23<01:00, 3.43it/s, loss=5.031e+01]
Image optimization: 58%|#####8 | 292/500 [01:23<01:00, 3.43it/s, loss=4.978e+01]
Image optimization: 59%|#####8 | 293/500 [01:23<01:00, 3.43it/s, loss=4.979e+01]
Image optimization: 59%|#####8 | 294/500 [01:23<01:00, 3.43it/s, loss=4.929e+01]
Image optimization: 59%|#####8 | 295/500 [01:24<00:59, 3.43it/s, loss=4.916e+01]
Image optimization: 59%|#####9 | 296/500 [01:24<00:59, 3.43it/s, loss=4.902e+01]
Image optimization: 59%|#####9 | 297/500 [01:24<00:59, 3.43it/s, loss=4.882e+01]
Image optimization: 60%|#####9 | 298/500 [01:25<00:58, 3.43it/s, loss=4.852e+01]
Image optimization: 60%|#####9 | 299/500 [01:25<00:58, 3.43it/s, loss=4.823e+01]
Image optimization: 60%|###### | 300/500 [01:25<00:58, 3.43it/s, loss=4.805e+01]
Image optimization: 60%|###### | 301/500 [01:25<00:58, 3.43it/s, loss=4.770e+01]
Image optimization: 60%|###### | 302/500 [01:26<00:57, 3.43it/s, loss=4.760e+01]
Image optimization: 61%|###### | 303/500 [01:26<00:57, 3.43it/s, loss=4.745e+01]
Image optimization: 61%|###### | 304/500 [01:26<00:57, 3.43it/s, loss=4.729e+01]
Image optimization: 61%|######1 | 305/500 [01:27<00:56, 3.43it/s, loss=4.713e+01]
Image optimization: 61%|######1 | 306/500 [01:27<00:56, 3.43it/s, loss=4.670e+01]
Image optimization: 61%|######1 | 307/500 [01:27<00:56, 3.43it/s, loss=4.647e+01]
Image optimization: 62%|######1 | 308/500 [01:27<00:56, 3.43it/s, loss=4.628e+01]
Image optimization: 62%|######1 | 309/500 [01:28<00:55, 3.43it/s, loss=4.610e+01]
Image optimization: 62%|######2 | 310/500 [01:28<00:55, 3.43it/s, loss=4.594e+01]
Image optimization: 62%|######2 | 311/500 [01:28<00:55, 3.43it/s, loss=4.573e+01]
Image optimization: 62%|######2 | 312/500 [01:29<00:54, 3.43it/s, loss=4.555e+01]
Image optimization: 63%|######2 | 313/500 [01:29<00:54, 3.43it/s, loss=4.530e+01]
Image optimization: 63%|######2 | 314/500 [01:29<00:54, 3.43it/s, loss=4.514e+01]
Image optimization: 63%|######3 | 315/500 [01:30<00:53, 3.43it/s, loss=4.501e+01]
Image optimization: 63%|######3 | 316/500 [01:30<00:53, 3.43it/s, loss=4.470e+01]
Image optimization: 63%|######3 | 317/500 [01:30<00:53, 3.43it/s, loss=4.452e+01]
Image optimization: 64%|######3 | 318/500 [01:30<00:53, 3.43it/s, loss=4.432e+01]
Image optimization: 64%|######3 | 319/500 [01:31<00:52, 3.43it/s, loss=4.414e+01]
Image optimization: 64%|######4 | 320/500 [01:31<00:52, 3.43it/s, loss=4.402e+01]
Image optimization: 64%|######4 | 321/500 [01:31<00:52, 3.42it/s, loss=4.379e+01]
Image optimization: 64%|######4 | 322/500 [01:32<00:51, 3.43it/s, loss=4.364e+01]
Image optimization: 65%|######4 | 323/500 [01:32<00:51, 3.43it/s, loss=4.344e+01]
Image optimization: 65%|######4 | 324/500 [01:32<00:51, 3.43it/s, loss=4.329e+01]
Image optimization: 65%|######5 | 325/500 [01:32<00:51, 3.43it/s, loss=4.317e+01]
Image optimization: 65%|######5 | 326/500 [01:33<00:50, 3.44it/s, loss=4.302e+01]
Image optimization: 65%|######5 | 327/500 [01:33<00:50, 3.43it/s, loss=4.278e+01]
Image optimization: 66%|######5 | 328/500 [01:33<00:50, 3.43it/s, loss=4.253e+01]
Image optimization: 66%|######5 | 329/500 [01:34<00:49, 3.43it/s, loss=4.234e+01]
Image optimization: 66%|######6 | 330/500 [01:34<00:49, 3.43it/s, loss=4.222e+01]
Image optimization: 66%|######6 | 331/500 [01:34<00:49, 3.43it/s, loss=4.205e+01]
Image optimization: 66%|######6 | 332/500 [01:34<00:48, 3.43it/s, loss=4.202e+01]
Image optimization: 67%|######6 | 333/500 [01:35<00:48, 3.43it/s, loss=4.177e+01]
Image optimization: 67%|######6 | 334/500 [01:35<00:48, 3.43it/s, loss=4.168e+01]
Image optimization: 67%|######7 | 335/500 [01:35<00:48, 3.43it/s, loss=4.154e+01]
Image optimization: 67%|######7 | 336/500 [01:36<00:47, 3.43it/s, loss=4.132e+01]
Image optimization: 67%|######7 | 337/500 [01:36<00:47, 3.44it/s, loss=4.119e+01]
Image optimization: 68%|######7 | 338/500 [01:36<00:47, 3.44it/s, loss=4.102e+01]
Image optimization: 68%|######7 | 339/500 [01:36<00:46, 3.43it/s, loss=4.097e+01]
Image optimization: 68%|######8 | 340/500 [01:37<00:46, 3.44it/s, loss=4.089e+01]
Image optimization: 68%|######8 | 341/500 [01:37<00:46, 3.44it/s, loss=4.064e+01]
Image optimization: 68%|######8 | 342/500 [01:37<00:45, 3.44it/s, loss=4.051e+01]
Image optimization: 69%|######8 | 343/500 [01:38<00:45, 3.43it/s, loss=4.038e+01]
Image optimization: 69%|######8 | 344/500 [01:38<00:45, 3.43it/s, loss=4.020e+01]
Image optimization: 69%|######9 | 345/500 [01:38<00:45, 3.43it/s, loss=4.010e+01]
Image optimization: 69%|######9 | 346/500 [01:39<00:44, 3.43it/s, loss=3.996e+01]
Image optimization: 69%|######9 | 347/500 [01:39<00:44, 3.43it/s, loss=3.984e+01]
Image optimization: 70%|######9 | 348/500 [01:39<00:44, 3.43it/s, loss=3.971e+01]
Image optimization: 70%|######9 | 349/500 [01:39<00:44, 3.43it/s, loss=3.951e+01]
Image optimization: 70%|####### | 350/500 [01:40<00:43, 3.43it/s, loss=3.942e+01]
Image optimization: 70%|####### | 351/500 [01:40<00:43, 3.43it/s, loss=3.924e+01]
Image optimization: 70%|####### | 352/500 [01:40<00:43, 3.43it/s, loss=3.916e+01]
Image optimization: 71%|####### | 353/500 [01:41<00:42, 3.43it/s, loss=3.909e+01]
Image optimization: 71%|####### | 354/500 [01:41<00:42, 3.43it/s, loss=3.900e+01]
Image optimization: 71%|#######1 | 355/500 [01:41<00:42, 3.43it/s, loss=3.890e+01]
Image optimization: 71%|#######1 | 356/500 [01:41<00:41, 3.43it/s, loss=3.882e+01]
Image optimization: 71%|#######1 | 357/500 [01:42<00:41, 3.43it/s, loss=3.866e+01]
Image optimization: 72%|#######1 | 358/500 [01:42<00:41, 3.43it/s, loss=3.846e+01]
Image optimization: 72%|#######1 | 359/500 [01:42<00:41, 3.44it/s, loss=3.838e+01]
Image optimization: 72%|#######2 | 360/500 [01:43<00:40, 3.44it/s, loss=3.823e+01]
Image optimization: 72%|#######2 | 361/500 [01:43<00:40, 3.44it/s, loss=3.819e+01]
Image optimization: 72%|#######2 | 362/500 [01:43<00:40, 3.44it/s, loss=3.811e+01]
Image optimization: 73%|#######2 | 363/500 [01:43<00:39, 3.43it/s, loss=3.801e+01]
Image optimization: 73%|#######2 | 364/500 [01:44<00:39, 3.42it/s, loss=3.792e+01]
Image optimization: 73%|#######3 | 365/500 [01:44<00:39, 3.42it/s, loss=3.775e+01]
Image optimization: 73%|#######3 | 366/500 [01:44<00:39, 3.43it/s, loss=3.764e+01]
Image optimization: 73%|#######3 | 367/500 [01:45<00:38, 3.43it/s, loss=3.755e+01]
Image optimization: 74%|#######3 | 368/500 [01:45<00:38, 3.43it/s, loss=3.747e+01]
Image optimization: 74%|#######3 | 369/500 [01:45<00:38, 3.43it/s, loss=3.741e+01]
Image optimization: 74%|#######4 | 370/500 [01:46<00:37, 3.44it/s, loss=3.729e+01]
Image optimization: 74%|#######4 | 371/500 [01:46<00:37, 3.44it/s, loss=3.716e+01]
Image optimization: 74%|#######4 | 372/500 [01:46<00:37, 3.44it/s, loss=3.705e+01]
Image optimization: 75%|#######4 | 373/500 [01:46<00:36, 3.43it/s, loss=3.697e+01]
Image optimization: 75%|#######4 | 374/500 [01:47<00:36, 3.44it/s, loss=3.686e+01]
Image optimization: 75%|#######5 | 375/500 [01:47<00:36, 3.44it/s, loss=3.679e+01]
Image optimization: 75%|#######5 | 376/500 [01:47<00:36, 3.43it/s, loss=3.671e+01]
Image optimization: 75%|#######5 | 377/500 [01:48<00:35, 3.43it/s, loss=3.665e+01]
Image optimization: 76%|#######5 | 378/500 [01:48<00:35, 3.43it/s, loss=3.659e+01]
Image optimization: 76%|#######5 | 379/500 [01:48<00:35, 3.44it/s, loss=3.642e+01]
Image optimization: 76%|#######6 | 380/500 [01:48<00:34, 3.44it/s, loss=3.637e+01]
Image optimization: 76%|#######6 | 381/500 [01:49<00:34, 3.43it/s, loss=3.623e+01]
Image optimization: 76%|#######6 | 382/500 [01:49<00:34, 3.44it/s, loss=3.618e+01]
Image optimization: 77%|#######6 | 383/500 [01:49<00:34, 3.43it/s, loss=3.613e+01]
Image optimization: 77%|#######6 | 384/500 [01:50<00:33, 3.42it/s, loss=3.605e+01]
Image optimization: 77%|#######7 | 385/500 [01:50<00:33, 3.43it/s, loss=3.592e+01]
Image optimization: 77%|#######7 | 386/500 [01:50<00:33, 3.44it/s, loss=3.582e+01]
Image optimization: 77%|#######7 | 387/500 [01:50<00:32, 3.44it/s, loss=3.573e+01]
Image optimization: 78%|#######7 | 388/500 [01:51<00:32, 3.43it/s, loss=3.566e+01]
Image optimization: 78%|#######7 | 389/500 [01:51<00:32, 3.44it/s, loss=3.557e+01]
Image optimization: 78%|#######8 | 390/500 [01:51<00:31, 3.44it/s, loss=3.549e+01]
Image optimization: 78%|#######8 | 391/500 [01:52<00:31, 3.43it/s, loss=3.542e+01]
Image optimization: 78%|#######8 | 392/500 [01:52<00:31, 3.44it/s, loss=3.533e+01]
Image optimization: 79%|#######8 | 393/500 [01:52<00:31, 3.44it/s, loss=3.524e+01]
Image optimization: 79%|#######8 | 394/500 [01:53<00:30, 3.44it/s, loss=3.515e+01]
Image optimization: 79%|#######9 | 395/500 [01:53<00:30, 3.44it/s, loss=3.506e+01]
Image optimization: 79%|#######9 | 396/500 [01:53<00:30, 3.44it/s, loss=3.498e+01]
Image optimization: 79%|#######9 | 397/500 [01:53<00:29, 3.43it/s, loss=3.492e+01]
Image optimization: 80%|#######9 | 398/500 [01:54<00:29, 3.43it/s, loss=3.486e+01]
Image optimization: 80%|#######9 | 399/500 [01:54<00:29, 3.44it/s, loss=3.482e+01]
Image optimization: 80%|######## | 400/500 [01:54<00:29, 3.43it/s, loss=3.476e+01]
Image optimization: 80%|######## | 401/500 [01:55<00:28, 3.43it/s, loss=3.471e+01]
Image optimization: 80%|######## | 402/500 [01:55<00:28, 3.43it/s, loss=3.465e+01]
Image optimization: 81%|######## | 403/500 [01:55<00:28, 3.43it/s, loss=3.454e+01]
Image optimization: 81%|######## | 404/500 [01:55<00:27, 3.43it/s, loss=3.443e+01]
Image optimization: 81%|########1 | 405/500 [01:56<00:27, 3.44it/s, loss=3.433e+01]
Image optimization: 81%|########1 | 406/500 [01:56<00:27, 3.43it/s, loss=3.428e+01]
Image optimization: 81%|########1 | 407/500 [01:56<00:27, 3.44it/s, loss=3.421e+01]
Image optimization: 82%|########1 | 408/500 [01:57<00:26, 3.44it/s, loss=3.416e+01]
Image optimization: 82%|########1 | 409/500 [01:57<00:26, 3.43it/s, loss=3.411e+01]
Image optimization: 82%|########2 | 410/500 [01:57<00:26, 3.43it/s, loss=3.403e+01]
Image optimization: 82%|########2 | 411/500 [01:57<00:25, 3.44it/s, loss=3.399e+01]
Image optimization: 82%|########2 | 412/500 [01:58<00:25, 3.43it/s, loss=3.391e+01]
Image optimization: 83%|########2 | 413/500 [01:58<00:25, 3.43it/s, loss=3.382e+01]
Image optimization: 83%|########2 | 414/500 [01:58<00:25, 3.43it/s, loss=3.374e+01]
Image optimization: 83%|########2 | 415/500 [01:59<00:24, 3.43it/s, loss=3.367e+01]
Image optimization: 83%|########3 | 416/500 [01:59<00:24, 3.43it/s, loss=3.361e+01]
Image optimization: 83%|########3 | 417/500 [01:59<00:24, 3.43it/s, loss=3.353e+01]
Image optimization: 84%|########3 | 418/500 [02:00<00:23, 3.43it/s, loss=3.347e+01]
Image optimization: 84%|########3 | 419/500 [02:00<00:23, 3.43it/s, loss=3.342e+01]
Image optimization: 84%|########4 | 420/500 [02:00<00:23, 3.43it/s, loss=3.336e+01]
Image optimization: 84%|########4 | 421/500 [02:00<00:23, 3.43it/s, loss=3.332e+01]
Image optimization: 84%|########4 | 422/500 [02:01<00:22, 3.43it/s, loss=3.326e+01]
Image optimization: 85%|########4 | 423/500 [02:01<00:22, 3.43it/s, loss=3.319e+01]
Image optimization: 85%|########4 | 424/500 [02:01<00:22, 3.43it/s, loss=3.311e+01]
Image optimization: 85%|########5 | 425/500 [02:02<00:21, 3.43it/s, loss=3.304e+01]
Image optimization: 85%|########5 | 426/500 [02:02<00:21, 3.44it/s, loss=3.300e+01]
Image optimization: 85%|########5 | 427/500 [02:02<00:21, 3.43it/s, loss=3.296e+01]
Image optimization: 86%|########5 | 428/500 [02:02<00:20, 3.44it/s, loss=3.290e+01]
Image optimization: 86%|########5 | 429/500 [02:03<00:20, 3.44it/s, loss=3.282e+01]
Image optimization: 86%|########6 | 430/500 [02:03<00:20, 3.43it/s, loss=3.276e+01]
Image optimization: 86%|########6 | 431/500 [02:03<00:20, 3.44it/s, loss=3.271e+01]
Image optimization: 86%|########6 | 432/500 [02:04<00:19, 3.44it/s, loss=3.264e+01]
Image optimization: 87%|########6 | 433/500 [02:04<00:19, 3.44it/s, loss=3.259e+01]
Image optimization: 87%|########6 | 434/500 [02:04<00:19, 3.44it/s, loss=3.255e+01]
Image optimization: 87%|########7 | 435/500 [02:04<00:18, 3.44it/s, loss=3.251e+01]
Image optimization: 87%|########7 | 436/500 [02:05<00:18, 3.43it/s, loss=3.247e+01]
Image optimization: 87%|########7 | 437/500 [02:05<00:18, 3.43it/s, loss=3.241e+01]
Image optimization: 88%|########7 | 438/500 [02:05<00:18, 3.43it/s, loss=3.233e+01]
Image optimization: 88%|########7 | 439/500 [02:06<00:17, 3.43it/s, loss=3.227e+01]
Image optimization: 88%|########8 | 440/500 [02:06<00:17, 3.43it/s, loss=3.222e+01]
Image optimization: 88%|########8 | 441/500 [02:06<00:17, 3.43it/s, loss=3.217e+01]
Image optimization: 88%|########8 | 442/500 [02:06<00:16, 3.43it/s, loss=3.212e+01]
Image optimization: 89%|########8 | 443/500 [02:07<00:16, 3.44it/s, loss=3.207e+01]
Image optimization: 89%|########8 | 444/500 [02:07<00:16, 3.43it/s, loss=3.203e+01]
Image optimization: 89%|########9 | 445/500 [02:07<00:16, 3.43it/s, loss=3.197e+01]
Image optimization: 89%|########9 | 446/500 [02:08<00:15, 3.44it/s, loss=3.192e+01]
Image optimization: 89%|########9 | 447/500 [02:08<00:15, 3.42it/s, loss=3.185e+01]
Image optimization: 90%|########9 | 448/500 [02:08<00:15, 3.42it/s, loss=3.182e+01]
Image optimization: 90%|########9 | 449/500 [02:09<00:14, 3.43it/s, loss=3.178e+01]
Image optimization: 90%|######### | 450/500 [02:09<00:14, 3.42it/s, loss=3.173e+01]
Image optimization: 90%|######### | 451/500 [02:09<00:14, 3.43it/s, loss=3.169e+01]
Image optimization: 90%|######### | 452/500 [02:09<00:13, 3.43it/s, loss=3.163e+01]
Image optimization: 91%|######### | 453/500 [02:10<00:13, 3.44it/s, loss=3.156e+01]
Image optimization: 91%|######### | 454/500 [02:10<00:13, 3.43it/s, loss=3.150e+01]
Image optimization: 91%|#########1| 455/500 [02:10<00:13, 3.43it/s, loss=3.147e+01]
Image optimization: 91%|#########1| 456/500 [02:11<00:12, 3.43it/s, loss=3.143e+01]
Image optimization: 91%|#########1| 457/500 [02:11<00:12, 3.44it/s, loss=3.140e+01]
Image optimization: 92%|#########1| 458/500 [02:11<00:12, 3.44it/s, loss=3.134e+01]
Image optimization: 92%|#########1| 459/500 [02:11<00:11, 3.43it/s, loss=3.128e+01]
Image optimization: 92%|#########2| 460/500 [02:12<00:11, 3.43it/s, loss=3.123e+01]
Image optimization: 92%|#########2| 461/500 [02:12<00:11, 3.44it/s, loss=3.118e+01]
Image optimization: 92%|#########2| 462/500 [02:12<00:11, 3.43it/s, loss=3.115e+01]
Image optimization: 93%|#########2| 463/500 [02:13<00:10, 3.44it/s, loss=3.111e+01]
Image optimization: 93%|#########2| 464/500 [02:13<00:10, 3.43it/s, loss=3.107e+01]
Image optimization: 93%|#########3| 465/500 [02:13<00:10, 3.43it/s, loss=3.103e+01]
Image optimization: 93%|#########3| 466/500 [02:13<00:09, 3.44it/s, loss=3.100e+01]
Image optimization: 93%|#########3| 467/500 [02:14<00:09, 3.44it/s, loss=3.095e+01]
Image optimization: 94%|#########3| 468/500 [02:14<00:09, 3.44it/s, loss=3.090e+01]
Image optimization: 94%|#########3| 469/500 [02:14<00:09, 3.44it/s, loss=3.085e+01]
Image optimization: 94%|#########3| 470/500 [02:15<00:08, 3.45it/s, loss=3.080e+01]
Image optimization: 94%|#########4| 471/500 [02:15<00:08, 3.44it/s, loss=3.075e+01]
Image optimization: 94%|#########4| 472/500 [02:15<00:08, 3.43it/s, loss=3.070e+01]
Image optimization: 95%|#########4| 473/500 [02:16<00:07, 3.43it/s, loss=3.066e+01]
Image optimization: 95%|#########4| 474/500 [02:16<00:07, 3.43it/s, loss=3.065e+01]
Image optimization: 95%|#########5| 475/500 [02:16<00:07, 3.43it/s, loss=3.061e+01]
Image optimization: 95%|#########5| 476/500 [02:16<00:06, 3.43it/s, loss=3.059e+01]
Image optimization: 95%|#########5| 477/500 [02:17<00:06, 3.44it/s, loss=3.056e+01]
Image optimization: 96%|#########5| 478/500 [02:17<00:06, 3.43it/s, loss=3.051e+01]
Image optimization: 96%|#########5| 479/500 [02:17<00:06, 3.43it/s, loss=3.044e+01]
Image optimization: 96%|#########6| 480/500 [02:18<00:05, 3.43it/s, loss=3.041e+01]
Image optimization: 96%|#########6| 481/500 [02:18<00:05, 3.44it/s, loss=3.035e+01]
Image optimization: 96%|#########6| 482/500 [02:18<00:05, 3.44it/s, loss=3.034e+01]
Image optimization: 97%|#########6| 483/500 [02:18<00:04, 3.43it/s, loss=3.031e+01]
Image optimization: 97%|#########6| 484/500 [02:19<00:04, 3.44it/s, loss=3.028e+01]
Image optimization: 97%|#########7| 485/500 [02:19<00:04, 3.44it/s, loss=3.022e+01]
Image optimization: 97%|#########7| 486/500 [02:19<00:04, 3.44it/s, loss=3.017e+01]
Image optimization: 97%|#########7| 487/500 [02:20<00:03, 3.44it/s, loss=3.013e+01]
Image optimization: 98%|#########7| 488/500 [02:20<00:03, 3.44it/s, loss=3.009e+01]
Image optimization: 98%|#########7| 489/500 [02:20<00:03, 3.44it/s, loss=3.004e+01]
Image optimization: 98%|#########8| 490/500 [02:20<00:02, 3.43it/s, loss=3.001e+01]
Image optimization: 98%|#########8| 491/500 [02:21<00:02, 3.44it/s, loss=2.997e+01]
Image optimization: 98%|#########8| 492/500 [02:21<00:02, 3.43it/s, loss=2.993e+01]
Image optimization: 99%|#########8| 493/500 [02:21<00:02, 3.44it/s, loss=2.993e+01]
Image optimization: 99%|#########8| 494/500 [02:22<00:01, 3.44it/s, loss=2.990e+01]
Image optimization: 99%|#########9| 495/500 [02:22<00:01, 3.43it/s, loss=2.988e+01]
Image optimization: 99%|#########9| 496/500 [02:22<00:01, 3.43it/s, loss=2.983e+01]
Image optimization: 99%|#########9| 497/500 [02:23<00:00, 3.43it/s, loss=2.979e+01]
Image optimization: 100%|#########9| 498/500 [02:23<00:00, 3.44it/s, loss=2.973e+01]
Image optimization: 100%|#########9| 499/500 [02:23<00:00, 3.44it/s, loss=2.970e+01]
Image optimization: 100%|##########| 500/500 [02:23<00:00, 3.44it/s, loss=2.967e+01]
Image optimization: 100%|##########| 500/500 [02:23<00:00, 3.48it/s, loss=2.967e+01]
103 show_image(output_image)
While the result is not completely unreasonable, the building has a strong blueish cast that looks unnatural. Since the optimization was unconstrained the color of the sky was used for the building. In the remainder of this example we will solve this by dividing the images in multiple separate regions.
Guided image optimization¶
For both the content_image
and style_image
we load regional guides
and
show them.
Note
In pystiche
a guide
is a binary image in which the white pixels make up the
region that is guided. Multiple guides
can be combined into a segmentation
for a better overview. In a segmentation
the regions are separated by color.
You can use guides_to_segmentation()
and
segmentation_to_guides()
to convert one format to the other.
Note
The guides used within this example were created manually. It is possible to
generate them automatically [CZP+18], but this is outside the scope of
pystiche
.
134 content_guides = images["castle"].guides.read(size=size, device=device)
135 content_segmentation = guides_to_segmentation(content_guides)
136 show_image(content_segmentation, title="Content segmentation")
141 style_guides = images["church"].guides.read(size=size, device=device)
142 style_segmentation = guides_to_segmentation(style_guides)
143 show_image(style_segmentation, title="Style segmentation")
The content_image
is separated in three regions
: the "building"
, the
"sky"
, and the "water"
.
Note
Since no water is present in the style image we reuse the "sky"
for the
"water"
region.
154 regions = ("building", "sky", "water")
155
156 style_guides["water"] = style_guides["sky"]
Since the stylization should be performed for each region individually, we also need
separate losses. Within each region we use the same setup as before. Similar to
how a MultiLayerEncodingLoss
bundles multiple
operators acting on different layers a MultiRegionLoss
bundles multiple losses acting in different regions.
The guiding is only needed for the style_loss
since the content_loss
by
definition honors the position of the content during the optimization. Thus, the
previously defined content_loss
is combined with the new regional style_loss
.
171 def get_region_op(region, region_weight):
172 return loss.MultiLayerEncodingLoss(
173 multi_layer_encoder, style_layers, get_style_op, score_weight=region_weight,
174 )
175
176
177 style_loss = loss.MultiRegionLoss(regions, get_region_op, score_weight=style_weight)
178
179 perceptual_loss = loss.PerceptualLoss(content_loss, style_loss).to(device)
180 print(perceptual_loss)
Out:
PerceptualLoss(
(content_loss): FeatureReconstructionLoss(
(encoder): VGGMultiLayerEncoder(layer=relu4_2, arch=vgg19, framework=torch)
)
(style_loss): MultiRegionLoss(
score_weight=10000
(building): MultiLayerEncodingLoss(
encoder=VGGMultiLayerEncoder(arch=vgg19, framework=torch)
(relu1_1): GramLoss(score_weight=0.2)
(relu2_1): GramLoss(score_weight=0.2)
(relu3_1): GramLoss(score_weight=0.2)
(relu4_1): GramLoss(score_weight=0.2)
(relu5_1): GramLoss(score_weight=0.2)
)
(sky): MultiLayerEncodingLoss(
encoder=VGGMultiLayerEncoder(arch=vgg19, framework=torch)
(relu1_1): GramLoss(score_weight=0.2)
(relu2_1): GramLoss(score_weight=0.2)
(relu3_1): GramLoss(score_weight=0.2)
(relu4_1): GramLoss(score_weight=0.2)
(relu5_1): GramLoss(score_weight=0.2)
)
(water): MultiLayerEncodingLoss(
encoder=VGGMultiLayerEncoder(arch=vgg19, framework=torch)
(relu1_1): GramLoss(score_weight=0.2)
(relu2_1): GramLoss(score_weight=0.2)
(relu3_1): GramLoss(score_weight=0.2)
(relu4_1): GramLoss(score_weight=0.2)
(relu5_1): GramLoss(score_weight=0.2)
)
)
)
The content_loss
is unguided and thus the content image can be set as we did
before. For the style_loss
we use the same style_image
for all regions and
only vary the guides.
188 perceptual_loss.set_content_image(content_image)
189
190 for region in regions:
191 perceptual_loss.set_style_image(
192 style_image, guide=style_guides[region], region=region
193 )
194 perceptual_loss.set_content_guide(content_guides[region], region=region)
We rerun the optimization with the new constrained optimization criterion
and
show the result.
201 starting_point = "content"
202 input_image = get_input_image(starting_point, content_image=content_image)
203
204 output_image = optim.image_optimization(input_image, perceptual_loss, num_steps=500)
Out:
Image optimization: 0%| | 0/500 [00:00<?, ?it/s]
Image optimization: 0%| | 1/500 [00:00<02:44, 3.04it/s, loss=6.988e+03]
Image optimization: 0%| | 2/500 [00:00<02:45, 3.00it/s, loss=6.983e+03]
Image optimization: 1%| | 3/500 [00:01<02:52, 2.89it/s, loss=4.626e+03]
Image optimization: 1%| | 4/500 [00:01<02:49, 2.92it/s, loss=4.027e+03]
Image optimization: 1%|1 | 5/500 [00:01<02:49, 2.91it/s, loss=3.232e+03]
Image optimization: 1%|1 | 6/500 [00:02<02:50, 2.89it/s, loss=2.584e+03]
Image optimization: 1%|1 | 7/500 [00:02<02:48, 2.92it/s, loss=2.119e+03]
Image optimization: 2%|1 | 8/500 [00:02<02:48, 2.91it/s, loss=1.870e+03]
Image optimization: 2%|1 | 9/500 [00:03<02:48, 2.91it/s, loss=1.683e+03]
Image optimization: 2%|2 | 10/500 [00:03<02:48, 2.91it/s, loss=1.573e+03]
Image optimization: 2%|2 | 11/500 [00:03<02:47, 2.91it/s, loss=1.321e+03]
Image optimization: 2%|2 | 12/500 [00:04<02:48, 2.90it/s, loss=1.229e+03]
Image optimization: 3%|2 | 13/500 [00:04<02:47, 2.91it/s, loss=1.087e+03]
Image optimization: 3%|2 | 14/500 [00:04<02:47, 2.91it/s, loss=1.038e+03]
Image optimization: 3%|3 | 15/500 [00:05<02:47, 2.90it/s, loss=9.842e+02]
Image optimization: 3%|3 | 16/500 [00:05<02:46, 2.90it/s, loss=9.097e+02]
Image optimization: 3%|3 | 17/500 [00:05<02:46, 2.90it/s, loss=8.584e+02]
Image optimization: 4%|3 | 18/500 [00:06<02:46, 2.89it/s, loss=8.259e+02]
Image optimization: 4%|3 | 19/500 [00:06<02:46, 2.89it/s, loss=7.766e+02]
Image optimization: 4%|4 | 20/500 [00:06<02:45, 2.89it/s, loss=7.341e+02]
Image optimization: 4%|4 | 21/500 [00:07<02:45, 2.89it/s, loss=7.051e+02]
Image optimization: 4%|4 | 22/500 [00:07<02:45, 2.89it/s, loss=6.784e+02]
Image optimization: 5%|4 | 23/500 [00:07<02:45, 2.89it/s, loss=6.548e+02]
Image optimization: 5%|4 | 24/500 [00:08<02:45, 2.88it/s, loss=6.381e+02]
Image optimization: 5%|5 | 25/500 [00:08<02:44, 2.88it/s, loss=6.189e+02]
Image optimization: 5%|5 | 26/500 [00:08<02:44, 2.88it/s, loss=6.047e+02]
Image optimization: 5%|5 | 27/500 [00:09<02:44, 2.88it/s, loss=5.871e+02]
Image optimization: 6%|5 | 28/500 [00:09<02:43, 2.88it/s, loss=5.681e+02]
Image optimization: 6%|5 | 29/500 [00:10<02:43, 2.88it/s, loss=5.517e+02]
Image optimization: 6%|6 | 30/500 [00:10<02:43, 2.87it/s, loss=5.396e+02]
Image optimization: 6%|6 | 31/500 [00:10<02:43, 2.88it/s, loss=5.305e+02]
Image optimization: 6%|6 | 32/500 [00:11<02:42, 2.88it/s, loss=5.194e+02]
Image optimization: 7%|6 | 33/500 [00:11<02:42, 2.87it/s, loss=5.081e+02]
Image optimization: 7%|6 | 34/500 [00:11<02:42, 2.87it/s, loss=4.971e+02]
Image optimization: 7%|7 | 35/500 [00:12<02:42, 2.87it/s, loss=4.901e+02]
Image optimization: 7%|7 | 36/500 [00:12<02:41, 2.87it/s, loss=4.792e+02]
Image optimization: 7%|7 | 37/500 [00:12<02:41, 2.86it/s, loss=4.735e+02]
Image optimization: 8%|7 | 38/500 [00:13<02:41, 2.87it/s, loss=4.661e+02]
Image optimization: 8%|7 | 39/500 [00:13<02:41, 2.86it/s, loss=4.604e+02]
Image optimization: 8%|8 | 40/500 [00:13<02:40, 2.86it/s, loss=4.552e+02]
Image optimization: 8%|8 | 41/500 [00:14<02:40, 2.86it/s, loss=4.484e+02]
Image optimization: 8%|8 | 42/500 [00:14<02:40, 2.86it/s, loss=4.414e+02]
Image optimization: 9%|8 | 43/500 [00:14<02:40, 2.86it/s, loss=4.365e+02]
Image optimization: 9%|8 | 44/500 [00:15<02:39, 2.86it/s, loss=4.286e+02]
Image optimization: 9%|9 | 45/500 [00:15<02:39, 2.85it/s, loss=4.238e+02]
Image optimization: 9%|9 | 46/500 [00:15<02:39, 2.85it/s, loss=4.185e+02]
Image optimization: 9%|9 | 47/500 [00:16<02:39, 2.85it/s, loss=4.141e+02]
Image optimization: 10%|9 | 48/500 [00:16<02:38, 2.85it/s, loss=4.102e+02]
Image optimization: 10%|9 | 49/500 [00:17<02:38, 2.84it/s, loss=4.057e+02]
Image optimization: 10%|# | 50/500 [00:17<02:38, 2.83it/s, loss=4.007e+02]
Image optimization: 10%|# | 51/500 [00:17<02:38, 2.84it/s, loss=3.960e+02]
Image optimization: 10%|# | 52/500 [00:18<02:38, 2.84it/s, loss=3.918e+02]
Image optimization: 11%|# | 53/500 [00:18<02:37, 2.83it/s, loss=3.893e+02]
Image optimization: 11%|# | 54/500 [00:18<02:37, 2.83it/s, loss=3.849e+02]
Image optimization: 11%|#1 | 55/500 [00:19<02:37, 2.83it/s, loss=3.810e+02]
Image optimization: 11%|#1 | 56/500 [00:19<02:37, 2.82it/s, loss=3.768e+02]
Image optimization: 11%|#1 | 57/500 [00:19<02:36, 2.82it/s, loss=3.741e+02]
Image optimization: 12%|#1 | 58/500 [00:20<02:36, 2.82it/s, loss=3.696e+02]
Image optimization: 12%|#1 | 59/500 [00:20<02:36, 2.82it/s, loss=3.680e+02]
Image optimization: 12%|#2 | 60/500 [00:20<02:35, 2.82it/s, loss=3.643e+02]
Image optimization: 12%|#2 | 61/500 [00:21<02:35, 2.82it/s, loss=3.621e+02]
Image optimization: 12%|#2 | 62/500 [00:21<02:35, 2.82it/s, loss=3.601e+02]
Image optimization: 13%|#2 | 63/500 [00:21<02:34, 2.82it/s, loss=3.583e+02]
Image optimization: 13%|#2 | 64/500 [00:22<02:34, 2.82it/s, loss=3.554e+02]
Image optimization: 13%|#3 | 65/500 [00:22<02:34, 2.81it/s, loss=3.536e+02]
Image optimization: 13%|#3 | 66/500 [00:23<02:34, 2.81it/s, loss=3.502e+02]
Image optimization: 13%|#3 | 67/500 [00:23<02:34, 2.81it/s, loss=3.481e+02]
Image optimization: 14%|#3 | 68/500 [00:23<02:33, 2.81it/s, loss=3.451e+02]
Image optimization: 14%|#3 | 69/500 [00:24<02:33, 2.81it/s, loss=3.433e+02]
Image optimization: 14%|#4 | 70/500 [00:24<02:33, 2.81it/s, loss=3.411e+02]
Image optimization: 14%|#4 | 71/500 [00:24<02:33, 2.80it/s, loss=3.390e+02]
Image optimization: 14%|#4 | 72/500 [00:25<02:32, 2.80it/s, loss=3.361e+02]
Image optimization: 15%|#4 | 73/500 [00:25<02:32, 2.79it/s, loss=3.346e+02]
Image optimization: 15%|#4 | 74/500 [00:25<02:32, 2.80it/s, loss=3.319e+02]
Image optimization: 15%|#5 | 75/500 [00:26<02:32, 2.80it/s, loss=3.297e+02]
Image optimization: 15%|#5 | 76/500 [00:26<02:31, 2.79it/s, loss=3.274e+02]
Image optimization: 15%|#5 | 77/500 [00:26<02:31, 2.79it/s, loss=3.260e+02]
Image optimization: 16%|#5 | 78/500 [00:27<02:31, 2.79it/s, loss=3.243e+02]
Image optimization: 16%|#5 | 79/500 [00:27<02:31, 2.78it/s, loss=3.228e+02]
Image optimization: 16%|#6 | 80/500 [00:28<02:31, 2.78it/s, loss=3.209e+02]
Image optimization: 16%|#6 | 81/500 [00:28<02:31, 2.77it/s, loss=3.196e+02]
Image optimization: 16%|#6 | 82/500 [00:28<02:30, 2.78it/s, loss=3.181e+02]
Image optimization: 17%|#6 | 83/500 [00:29<02:29, 2.78it/s, loss=3.153e+02]
Image optimization: 17%|#6 | 84/500 [00:29<02:29, 2.78it/s, loss=3.132e+02]
Image optimization: 17%|#7 | 85/500 [00:29<02:29, 2.77it/s, loss=3.114e+02]
Image optimization: 17%|#7 | 86/500 [00:30<02:29, 2.78it/s, loss=3.099e+02]
Image optimization: 17%|#7 | 87/500 [00:30<02:29, 2.77it/s, loss=3.080e+02]
Image optimization: 18%|#7 | 88/500 [00:30<02:28, 2.77it/s, loss=3.060e+02]
Image optimization: 18%|#7 | 89/500 [00:31<02:28, 2.76it/s, loss=3.045e+02]
Image optimization: 18%|#8 | 90/500 [00:31<02:28, 2.76it/s, loss=3.030e+02]
Image optimization: 18%|#8 | 91/500 [00:32<02:27, 2.77it/s, loss=3.011e+02]
Image optimization: 18%|#8 | 92/500 [00:32<02:27, 2.76it/s, loss=2.996e+02]
Image optimization: 19%|#8 | 93/500 [00:32<02:27, 2.76it/s, loss=2.980e+02]
Image optimization: 19%|#8 | 94/500 [00:33<02:27, 2.76it/s, loss=2.967e+02]
Image optimization: 19%|#9 | 95/500 [00:33<02:27, 2.75it/s, loss=2.953e+02]
Image optimization: 19%|#9 | 96/500 [00:33<02:26, 2.75it/s, loss=2.938e+02]
Image optimization: 19%|#9 | 97/500 [00:34<02:26, 2.75it/s, loss=2.924e+02]
Image optimization: 20%|#9 | 98/500 [00:34<02:25, 2.75it/s, loss=2.903e+02]
Image optimization: 20%|#9 | 99/500 [00:34<02:25, 2.75it/s, loss=2.890e+02]
Image optimization: 20%|## | 100/500 [00:35<02:25, 2.75it/s, loss=2.880e+02]
Image optimization: 20%|## | 101/500 [00:35<02:25, 2.75it/s, loss=2.867e+02]
Image optimization: 20%|## | 102/500 [00:36<02:24, 2.75it/s, loss=2.857e+02]
Image optimization: 21%|## | 103/500 [00:36<02:24, 2.74it/s, loss=2.841e+02]
Image optimization: 21%|## | 104/500 [00:36<02:24, 2.74it/s, loss=2.824e+02]
Image optimization: 21%|##1 | 105/500 [00:37<02:24, 2.74it/s, loss=2.811e+02]
Image optimization: 21%|##1 | 106/500 [00:37<02:23, 2.74it/s, loss=2.791e+02]
Image optimization: 21%|##1 | 107/500 [00:37<02:23, 2.74it/s, loss=2.779e+02]
Image optimization: 22%|##1 | 108/500 [00:38<02:23, 2.73it/s, loss=2.765e+02]
Image optimization: 22%|##1 | 109/500 [00:38<02:22, 2.74it/s, loss=2.755e+02]
Image optimization: 22%|##2 | 110/500 [00:38<02:22, 2.74it/s, loss=2.744e+02]
Image optimization: 22%|##2 | 111/500 [00:39<02:22, 2.73it/s, loss=2.728e+02]
Image optimization: 22%|##2 | 112/500 [00:39<02:22, 2.73it/s, loss=2.715e+02]
Image optimization: 23%|##2 | 113/500 [00:40<02:21, 2.74it/s, loss=2.702e+02]
Image optimization: 23%|##2 | 114/500 [00:40<02:21, 2.73it/s, loss=2.682e+02]
Image optimization: 23%|##3 | 115/500 [00:40<02:20, 2.74it/s, loss=2.673e+02]
Image optimization: 23%|##3 | 116/500 [00:41<02:20, 2.74it/s, loss=2.658e+02]
Image optimization: 23%|##3 | 117/500 [00:41<02:19, 2.74it/s, loss=2.649e+02]
Image optimization: 24%|##3 | 118/500 [00:41<02:19, 2.74it/s, loss=2.640e+02]
Image optimization: 24%|##3 | 119/500 [00:42<02:19, 2.74it/s, loss=2.621e+02]
Image optimization: 24%|##4 | 120/500 [00:42<02:19, 2.73it/s, loss=2.608e+02]
Image optimization: 24%|##4 | 121/500 [00:42<02:18, 2.74it/s, loss=2.594e+02]
Image optimization: 24%|##4 | 122/500 [00:43<02:18, 2.74it/s, loss=2.580e+02]
Image optimization: 25%|##4 | 123/500 [00:43<02:17, 2.74it/s, loss=2.566e+02]
Image optimization: 25%|##4 | 124/500 [00:44<02:17, 2.74it/s, loss=2.551e+02]
Image optimization: 25%|##5 | 125/500 [00:44<02:17, 2.73it/s, loss=2.542e+02]
Image optimization: 25%|##5 | 126/500 [00:44<02:16, 2.74it/s, loss=2.529e+02]
Image optimization: 25%|##5 | 127/500 [00:45<02:16, 2.74it/s, loss=2.517e+02]
Image optimization: 26%|##5 | 128/500 [00:45<02:15, 2.74it/s, loss=2.503e+02]
Image optimization: 26%|##5 | 129/500 [00:45<02:15, 2.74it/s, loss=2.488e+02]
Image optimization: 26%|##6 | 130/500 [00:46<02:15, 2.73it/s, loss=2.472e+02]
Image optimization: 26%|##6 | 131/500 [00:46<02:14, 2.74it/s, loss=2.456e+02]
Image optimization: 26%|##6 | 132/500 [00:46<02:14, 2.74it/s, loss=2.442e+02]
Image optimization: 27%|##6 | 133/500 [00:47<02:14, 2.74it/s, loss=2.432e+02]
Image optimization: 27%|##6 | 134/500 [00:47<02:13, 2.73it/s, loss=2.424e+02]
Image optimization: 27%|##7 | 135/500 [00:48<02:13, 2.74it/s, loss=2.409e+02]
Image optimization: 27%|##7 | 136/500 [00:48<02:13, 2.74it/s, loss=2.401e+02]
Image optimization: 27%|##7 | 137/500 [00:48<02:12, 2.73it/s, loss=2.383e+02]
Image optimization: 28%|##7 | 138/500 [00:49<02:12, 2.73it/s, loss=2.367e+02]
Image optimization: 28%|##7 | 139/500 [00:49<02:11, 2.74it/s, loss=2.351e+02]
Image optimization: 28%|##8 | 140/500 [00:49<02:11, 2.74it/s, loss=2.342e+02]
Image optimization: 28%|##8 | 141/500 [00:50<02:11, 2.73it/s, loss=2.333e+02]
Image optimization: 28%|##8 | 142/500 [00:50<02:10, 2.74it/s, loss=2.318e+02]
Image optimization: 29%|##8 | 143/500 [00:51<02:10, 2.74it/s, loss=2.300e+02]
Image optimization: 29%|##8 | 144/500 [00:51<02:10, 2.74it/s, loss=2.283e+02]
Image optimization: 29%|##9 | 145/500 [00:51<02:09, 2.74it/s, loss=2.270e+02]
Image optimization: 29%|##9 | 146/500 [00:52<02:09, 2.74it/s, loss=2.261e+02]
Image optimization: 29%|##9 | 147/500 [00:52<02:08, 2.74it/s, loss=2.250e+02]
Image optimization: 30%|##9 | 148/500 [00:52<02:08, 2.73it/s, loss=2.235e+02]
Image optimization: 30%|##9 | 149/500 [00:53<02:08, 2.73it/s, loss=2.225e+02]
Image optimization: 30%|### | 150/500 [00:53<02:08, 2.73it/s, loss=2.206e+02]
Image optimization: 30%|### | 151/500 [00:53<02:07, 2.73it/s, loss=2.193e+02]
Image optimization: 30%|### | 152/500 [00:54<02:07, 2.73it/s, loss=2.180e+02]
Image optimization: 31%|### | 153/500 [00:54<02:06, 2.73it/s, loss=2.168e+02]
Image optimization: 31%|### | 154/500 [00:55<02:06, 2.73it/s, loss=2.156e+02]
Image optimization: 31%|###1 | 155/500 [00:55<02:06, 2.73it/s, loss=2.139e+02]
Image optimization: 31%|###1 | 156/500 [00:55<02:05, 2.73it/s, loss=2.125e+02]
Image optimization: 31%|###1 | 157/500 [00:56<02:05, 2.74it/s, loss=2.110e+02]
Image optimization: 32%|###1 | 158/500 [00:56<02:04, 2.74it/s, loss=2.094e+02]
Image optimization: 32%|###1 | 159/500 [00:56<02:04, 2.73it/s, loss=2.079e+02]
Image optimization: 32%|###2 | 160/500 [00:57<02:04, 2.73it/s, loss=2.062e+02]
Image optimization: 32%|###2 | 161/500 [00:57<02:03, 2.73it/s, loss=2.052e+02]
Image optimization: 32%|###2 | 162/500 [00:57<02:03, 2.73it/s, loss=2.042e+02]
Image optimization: 33%|###2 | 163/500 [00:58<02:03, 2.73it/s, loss=2.026e+02]
Image optimization: 33%|###2 | 164/500 [00:58<02:03, 2.73it/s, loss=2.010e+02]
Image optimization: 33%|###3 | 165/500 [00:59<02:02, 2.73it/s, loss=1.994e+02]
Image optimization: 33%|###3 | 166/500 [00:59<02:02, 2.73it/s, loss=1.981e+02]
Image optimization: 33%|###3 | 167/500 [00:59<02:01, 2.73it/s, loss=1.971e+02]
Image optimization: 34%|###3 | 168/500 [01:00<02:01, 2.74it/s, loss=1.960e+02]
Image optimization: 34%|###3 | 169/500 [01:00<02:01, 2.73it/s, loss=1.944e+02]
Image optimization: 34%|###4 | 170/500 [01:00<02:00, 2.73it/s, loss=1.930e+02]
Image optimization: 34%|###4 | 171/500 [01:01<02:00, 2.73it/s, loss=1.917e+02]
Image optimization: 34%|###4 | 172/500 [01:01<02:00, 2.73it/s, loss=1.907e+02]
Image optimization: 35%|###4 | 173/500 [01:01<01:59, 2.73it/s, loss=1.891e+02]
Image optimization: 35%|###4 | 174/500 [01:02<01:59, 2.73it/s, loss=1.892e+02]
Image optimization: 35%|###5 | 175/500 [01:02<01:58, 2.73it/s, loss=1.868e+02]
Image optimization: 35%|###5 | 176/500 [01:03<01:58, 2.73it/s, loss=1.861e+02]
Image optimization: 35%|###5 | 177/500 [01:03<01:58, 2.74it/s, loss=1.847e+02]
Image optimization: 36%|###5 | 178/500 [01:03<01:57, 2.73it/s, loss=1.833e+02]
Image optimization: 36%|###5 | 179/500 [01:04<01:57, 2.74it/s, loss=1.817e+02]
Image optimization: 36%|###6 | 180/500 [01:04<01:57, 2.73it/s, loss=1.805e+02]
Image optimization: 36%|###6 | 181/500 [01:04<01:56, 2.74it/s, loss=1.794e+02]
Image optimization: 36%|###6 | 182/500 [01:05<01:56, 2.74it/s, loss=1.781e+02]
Image optimization: 37%|###6 | 183/500 [01:05<01:55, 2.73it/s, loss=1.765e+02]
Image optimization: 37%|###6 | 184/500 [01:06<01:55, 2.74it/s, loss=1.751e+02]
Image optimization: 37%|###7 | 185/500 [01:06<01:55, 2.73it/s, loss=1.739e+02]
Image optimization: 37%|###7 | 186/500 [01:06<01:55, 2.73it/s, loss=1.728e+02]
Image optimization: 37%|###7 | 187/500 [01:07<01:54, 2.73it/s, loss=1.716e+02]
Image optimization: 38%|###7 | 188/500 [01:07<01:53, 2.74it/s, loss=1.707e+02]
Image optimization: 38%|###7 | 189/500 [01:07<01:53, 2.73it/s, loss=1.695e+02]
Image optimization: 38%|###8 | 190/500 [01:08<01:53, 2.73it/s, loss=1.682e+02]
Image optimization: 38%|###8 | 191/500 [01:08<01:53, 2.73it/s, loss=1.672e+02]
Image optimization: 38%|###8 | 192/500 [01:08<01:52, 2.73it/s, loss=1.662e+02]
Image optimization: 39%|###8 | 193/500 [01:09<01:52, 2.73it/s, loss=1.644e+02]
Image optimization: 39%|###8 | 194/500 [01:09<01:51, 2.73it/s, loss=1.635e+02]
Image optimization: 39%|###9 | 195/500 [01:10<01:51, 2.73it/s, loss=1.627e+02]
Image optimization: 39%|###9 | 196/500 [01:10<01:51, 2.73it/s, loss=1.617e+02]
Image optimization: 39%|###9 | 197/500 [01:10<01:50, 2.73it/s, loss=1.611e+02]
Image optimization: 40%|###9 | 198/500 [01:11<01:50, 2.73it/s, loss=1.599e+02]
Image optimization: 40%|###9 | 199/500 [01:11<01:49, 2.74it/s, loss=1.585e+02]
Image optimization: 40%|#### | 200/500 [01:11<01:49, 2.73it/s, loss=1.573e+02]
Image optimization: 40%|#### | 201/500 [01:12<01:49, 2.73it/s, loss=1.563e+02]
Image optimization: 40%|#### | 202/500 [01:12<01:48, 2.74it/s, loss=1.552e+02]
Image optimization: 41%|#### | 203/500 [01:12<01:48, 2.73it/s, loss=1.541e+02]
Image optimization: 41%|#### | 204/500 [01:13<01:48, 2.74it/s, loss=1.532e+02]
Image optimization: 41%|####1 | 205/500 [01:13<01:47, 2.73it/s, loss=1.521e+02]
Image optimization: 41%|####1 | 206/500 [01:14<01:47, 2.73it/s, loss=1.511e+02]
Image optimization: 41%|####1 | 207/500 [01:14<01:47, 2.73it/s, loss=1.501e+02]
Image optimization: 42%|####1 | 208/500 [01:14<01:46, 2.73it/s, loss=1.494e+02]
Image optimization: 42%|####1 | 209/500 [01:15<01:46, 2.73it/s, loss=1.482e+02]
Image optimization: 42%|####2 | 210/500 [01:15<01:46, 2.73it/s, loss=1.472e+02]
Image optimization: 42%|####2 | 211/500 [01:15<01:45, 2.73it/s, loss=1.462e+02]
Image optimization: 42%|####2 | 212/500 [01:16<01:45, 2.73it/s, loss=1.454e+02]
Image optimization: 43%|####2 | 213/500 [01:16<01:45, 2.73it/s, loss=1.447e+02]
Image optimization: 43%|####2 | 214/500 [01:16<01:44, 2.73it/s, loss=1.437e+02]
Image optimization: 43%|####3 | 215/500 [01:17<01:44, 2.73it/s, loss=1.425e+02]
Image optimization: 43%|####3 | 216/500 [01:17<01:44, 2.73it/s, loss=1.416e+02]
Image optimization: 43%|####3 | 217/500 [01:18<01:43, 2.73it/s, loss=1.408e+02]
Image optimization: 44%|####3 | 218/500 [01:18<01:43, 2.73it/s, loss=1.397e+02]
Image optimization: 44%|####3 | 219/500 [01:18<01:42, 2.73it/s, loss=1.390e+02]
Image optimization: 44%|####4 | 220/500 [01:19<01:42, 2.73it/s, loss=1.383e+02]
Image optimization: 44%|####4 | 221/500 [01:19<01:42, 2.73it/s, loss=1.374e+02]
Image optimization: 44%|####4 | 222/500 [01:19<01:41, 2.73it/s, loss=1.367e+02]
Image optimization: 45%|####4 | 223/500 [01:20<01:41, 2.73it/s, loss=1.358e+02]
Image optimization: 45%|####4 | 224/500 [01:20<01:41, 2.73it/s, loss=1.348e+02]
Image optimization: 45%|####5 | 225/500 [01:21<01:40, 2.73it/s, loss=1.340e+02]
Image optimization: 45%|####5 | 226/500 [01:21<01:40, 2.73it/s, loss=1.333e+02]
Image optimization: 45%|####5 | 227/500 [01:21<01:39, 2.73it/s, loss=1.324e+02]
Image optimization: 46%|####5 | 228/500 [01:22<01:39, 2.73it/s, loss=1.315e+02]
Image optimization: 46%|####5 | 229/500 [01:22<01:39, 2.73it/s, loss=1.306e+02]
Image optimization: 46%|####6 | 230/500 [01:22<01:38, 2.73it/s, loss=1.294e+02]
Image optimization: 46%|####6 | 231/500 [01:23<01:38, 2.73it/s, loss=1.285e+02]
Image optimization: 46%|####6 | 232/500 [01:23<01:38, 2.73it/s, loss=1.278e+02]
Image optimization: 47%|####6 | 233/500 [01:23<01:37, 2.74it/s, loss=1.271e+02]
Image optimization: 47%|####6 | 234/500 [01:24<01:37, 2.74it/s, loss=1.264e+02]
Image optimization: 47%|####6 | 235/500 [01:24<01:36, 2.74it/s, loss=1.258e+02]
Image optimization: 47%|####7 | 236/500 [01:25<01:36, 2.74it/s, loss=1.250e+02]
Image optimization: 47%|####7 | 237/500 [01:25<01:35, 2.74it/s, loss=1.243e+02]
Image optimization: 48%|####7 | 238/500 [01:25<01:35, 2.75it/s, loss=1.232e+02]
Image optimization: 48%|####7 | 239/500 [01:26<01:35, 2.75it/s, loss=1.223e+02]
Image optimization: 48%|####8 | 240/500 [01:26<01:34, 2.74it/s, loss=1.218e+02]
Image optimization: 48%|####8 | 241/500 [01:26<01:34, 2.74it/s, loss=1.211e+02]
Image optimization: 48%|####8 | 242/500 [01:27<01:34, 2.74it/s, loss=1.204e+02]
Image optimization: 49%|####8 | 243/500 [01:27<01:33, 2.74it/s, loss=1.193e+02]
Image optimization: 49%|####8 | 244/500 [01:27<01:33, 2.73it/s, loss=1.186e+02]
Image optimization: 49%|####9 | 245/500 [01:28<01:33, 2.73it/s, loss=1.183e+02]
Image optimization: 49%|####9 | 246/500 [01:28<01:32, 2.73it/s, loss=1.177e+02]
Image optimization: 49%|####9 | 247/500 [01:29<01:32, 2.73it/s, loss=1.172e+02]
Image optimization: 50%|####9 | 248/500 [01:29<01:32, 2.73it/s, loss=1.167e+02]
Image optimization: 50%|####9 | 249/500 [01:29<01:31, 2.73it/s, loss=1.157e+02]
Image optimization: 50%|##### | 250/500 [01:30<01:31, 2.73it/s, loss=1.146e+02]
Image optimization: 50%|##### | 251/500 [01:30<01:31, 2.73it/s, loss=1.138e+02]
Image optimization: 50%|##### | 252/500 [01:30<01:30, 2.73it/s, loss=1.133e+02]
Image optimization: 51%|##### | 253/500 [01:31<01:30, 2.73it/s, loss=1.125e+02]
Image optimization: 51%|##### | 254/500 [01:31<01:30, 2.73it/s, loss=1.119e+02]
Image optimization: 51%|#####1 | 255/500 [01:31<01:29, 2.73it/s, loss=1.112e+02]
Image optimization: 51%|#####1 | 256/500 [01:32<01:29, 2.73it/s, loss=1.104e+02]
Image optimization: 51%|#####1 | 257/500 [01:32<01:29, 2.73it/s, loss=1.097e+02]
Image optimization: 52%|#####1 | 258/500 [01:33<01:28, 2.73it/s, loss=1.090e+02]
Image optimization: 52%|#####1 | 259/500 [01:33<01:28, 2.73it/s, loss=1.084e+02]
Image optimization: 52%|#####2 | 260/500 [01:33<01:27, 2.73it/s, loss=1.077e+02]
Image optimization: 52%|#####2 | 261/500 [01:34<01:27, 2.73it/s, loss=1.070e+02]
Image optimization: 52%|#####2 | 262/500 [01:34<01:27, 2.73it/s, loss=1.063e+02]
Image optimization: 53%|#####2 | 263/500 [01:34<01:26, 2.73it/s, loss=1.058e+02]
Image optimization: 53%|#####2 | 264/500 [01:35<01:26, 2.73it/s, loss=1.051e+02]
Image optimization: 53%|#####3 | 265/500 [01:35<01:25, 2.73it/s, loss=1.045e+02]
Image optimization: 53%|#####3 | 266/500 [01:36<01:25, 2.74it/s, loss=1.038e+02]
Image optimization: 53%|#####3 | 267/500 [01:36<01:25, 2.74it/s, loss=1.033e+02]
Image optimization: 54%|#####3 | 268/500 [01:36<01:24, 2.74it/s, loss=1.028e+02]
Image optimization: 54%|#####3 | 269/500 [01:37<01:24, 2.74it/s, loss=1.022e+02]
Image optimization: 54%|#####4 | 270/500 [01:37<01:24, 2.73it/s, loss=1.015e+02]
Image optimization: 54%|#####4 | 271/500 [01:37<01:23, 2.73it/s, loss=1.010e+02]
Image optimization: 54%|#####4 | 272/500 [01:38<01:23, 2.73it/s, loss=1.002e+02]
Image optimization: 55%|#####4 | 273/500 [01:38<01:23, 2.73it/s, loss=9.965e+01]
Image optimization: 55%|#####4 | 274/500 [01:38<01:22, 2.73it/s, loss=9.908e+01]
Image optimization: 55%|#####5 | 275/500 [01:39<01:22, 2.73it/s, loss=9.873e+01]
Image optimization: 55%|#####5 | 276/500 [01:39<01:21, 2.74it/s, loss=9.829e+01]
Image optimization: 55%|#####5 | 277/500 [01:40<01:21, 2.74it/s, loss=9.796e+01]
Image optimization: 56%|#####5 | 278/500 [01:40<01:21, 2.74it/s, loss=9.746e+01]
Image optimization: 56%|#####5 | 279/500 [01:40<01:20, 2.73it/s, loss=9.669e+01]
Image optimization: 56%|#####6 | 280/500 [01:41<01:20, 2.74it/s, loss=9.598e+01]
Image optimization: 56%|#####6 | 281/500 [01:41<01:20, 2.73it/s, loss=9.542e+01]
Image optimization: 56%|#####6 | 282/500 [01:41<01:19, 2.74it/s, loss=9.504e+01]
Image optimization: 57%|#####6 | 283/500 [01:42<01:19, 2.73it/s, loss=9.456e+01]
Image optimization: 57%|#####6 | 284/500 [01:42<01:18, 2.73it/s, loss=9.421e+01]
Image optimization: 57%|#####6 | 285/500 [01:42<01:18, 2.73it/s, loss=9.376e+01]
Image optimization: 57%|#####7 | 286/500 [01:43<01:18, 2.73it/s, loss=9.312e+01]
Image optimization: 57%|#####7 | 287/500 [01:43<01:17, 2.74it/s, loss=9.264e+01]
Image optimization: 58%|#####7 | 288/500 [01:44<01:17, 2.73it/s, loss=9.209e+01]
Image optimization: 58%|#####7 | 289/500 [01:44<01:17, 2.73it/s, loss=9.161e+01]
Image optimization: 58%|#####8 | 290/500 [01:44<01:16, 2.74it/s, loss=9.116e+01]
Image optimization: 58%|#####8 | 291/500 [01:45<01:16, 2.73it/s, loss=9.067e+01]
Image optimization: 58%|#####8 | 292/500 [01:45<01:16, 2.74it/s, loss=9.021e+01]
Image optimization: 59%|#####8 | 293/500 [01:45<01:15, 2.74it/s, loss=8.972e+01]
Image optimization: 59%|#####8 | 294/500 [01:46<01:15, 2.73it/s, loss=8.921e+01]
Image optimization: 59%|#####8 | 295/500 [01:46<01:15, 2.73it/s, loss=8.872e+01]
Image optimization: 59%|#####9 | 296/500 [01:46<01:14, 2.73it/s, loss=8.833e+01]
Image optimization: 59%|#####9 | 297/500 [01:47<01:14, 2.73it/s, loss=8.787e+01]
Image optimization: 60%|#####9 | 298/500 [01:47<01:13, 2.74it/s, loss=8.746e+01]
Image optimization: 60%|#####9 | 299/500 [01:48<01:13, 2.73it/s, loss=8.699e+01]
Image optimization: 60%|###### | 300/500 [01:48<01:13, 2.73it/s, loss=8.663e+01]
Image optimization: 60%|###### | 301/500 [01:48<01:12, 2.73it/s, loss=8.633e+01]
Image optimization: 60%|###### | 302/500 [01:49<01:12, 2.73it/s, loss=8.596e+01]
Image optimization: 61%|###### | 303/500 [01:49<01:12, 2.73it/s, loss=8.553e+01]
Image optimization: 61%|###### | 304/500 [01:49<01:11, 2.73it/s, loss=8.508e+01]
Image optimization: 61%|######1 | 305/500 [01:50<01:11, 2.74it/s, loss=8.464e+01]
Image optimization: 61%|######1 | 306/500 [01:50<01:11, 2.73it/s, loss=8.438e+01]
Image optimization: 61%|######1 | 307/500 [01:51<01:10, 2.73it/s, loss=8.390e+01]
Image optimization: 62%|######1 | 308/500 [01:51<01:10, 2.73it/s, loss=8.371e+01]
Image optimization: 62%|######1 | 309/500 [01:51<01:09, 2.74it/s, loss=8.318e+01]
Image optimization: 62%|######2 | 310/500 [01:52<01:09, 2.74it/s, loss=8.294e+01]
Image optimization: 62%|######2 | 311/500 [01:52<01:09, 2.73it/s, loss=8.274e+01]
Image optimization: 62%|######2 | 312/500 [01:52<01:08, 2.73it/s, loss=8.228e+01]
Image optimization: 63%|######2 | 313/500 [01:53<01:08, 2.73it/s, loss=8.195e+01]
Image optimization: 63%|######2 | 314/500 [01:53<01:08, 2.73it/s, loss=8.160e+01]
Image optimization: 63%|######3 | 315/500 [01:53<01:07, 2.73it/s, loss=8.133e+01]
Image optimization: 63%|######3 | 316/500 [01:54<01:07, 2.73it/s, loss=8.109e+01]
Image optimization: 63%|######3 | 317/500 [01:54<01:06, 2.73it/s, loss=8.072e+01]
Image optimization: 64%|######3 | 318/500 [01:55<01:06, 2.74it/s, loss=8.029e+01]
Image optimization: 64%|######3 | 319/500 [01:55<01:06, 2.74it/s, loss=7.991e+01]
Image optimization: 64%|######4 | 320/500 [01:55<01:05, 2.73it/s, loss=7.965e+01]
Image optimization: 64%|######4 | 321/500 [01:56<01:05, 2.74it/s, loss=7.932e+01]
Image optimization: 64%|######4 | 322/500 [01:56<01:05, 2.73it/s, loss=7.903e+01]
Image optimization: 65%|######4 | 323/500 [01:56<01:04, 2.73it/s, loss=7.877e+01]
Image optimization: 65%|######4 | 324/500 [01:57<01:04, 2.73it/s, loss=7.843e+01]
Image optimization: 65%|######5 | 325/500 [01:57<01:04, 2.73it/s, loss=7.813e+01]
Image optimization: 65%|######5 | 326/500 [01:57<01:03, 2.73it/s, loss=7.787e+01]
Image optimization: 65%|######5 | 327/500 [01:58<01:03, 2.73it/s, loss=7.760e+01]
Image optimization: 66%|######5 | 328/500 [01:58<01:02, 2.73it/s, loss=7.733e+01]
Image optimization: 66%|######5 | 329/500 [01:59<01:02, 2.73it/s, loss=7.701e+01]
Image optimization: 66%|######6 | 330/500 [01:59<01:02, 2.73it/s, loss=7.677e+01]
Image optimization: 66%|######6 | 331/500 [01:59<01:01, 2.73it/s, loss=7.652e+01]
Image optimization: 66%|######6 | 332/500 [02:00<01:01, 2.73it/s, loss=7.627e+01]
Image optimization: 67%|######6 | 333/500 [02:00<01:01, 2.74it/s, loss=7.601e+01]
Image optimization: 67%|######6 | 334/500 [02:00<01:00, 2.73it/s, loss=7.579e+01]
Image optimization: 67%|######7 | 335/500 [02:01<01:00, 2.74it/s, loss=7.549e+01]
Image optimization: 67%|######7 | 336/500 [02:01<01:00, 2.73it/s, loss=7.526e+01]
Image optimization: 67%|######7 | 337/500 [02:01<00:59, 2.73it/s, loss=7.503e+01]
Image optimization: 68%|######7 | 338/500 [02:02<00:59, 2.73it/s, loss=7.471e+01]
Image optimization: 68%|######7 | 339/500 [02:02<00:58, 2.73it/s, loss=7.448e+01]
Image optimization: 68%|######8 | 340/500 [02:03<00:58, 2.73it/s, loss=7.425e+01]
Image optimization: 68%|######8 | 341/500 [02:03<00:58, 2.73it/s, loss=7.404e+01]
Image optimization: 68%|######8 | 342/500 [02:03<00:57, 2.73it/s, loss=7.384e+01]
Image optimization: 69%|######8 | 343/500 [02:04<00:57, 2.74it/s, loss=7.369e+01]
Image optimization: 69%|######8 | 344/500 [02:04<00:56, 2.74it/s, loss=7.332e+01]
Image optimization: 69%|######9 | 345/500 [02:04<00:56, 2.74it/s, loss=7.310e+01]
Image optimization: 69%|######9 | 346/500 [02:05<00:56, 2.74it/s, loss=7.287e+01]
Image optimization: 69%|######9 | 347/500 [02:05<00:55, 2.73it/s, loss=7.260e+01]
Image optimization: 70%|######9 | 348/500 [02:06<00:55, 2.73it/s, loss=7.239e+01]
Image optimization: 70%|######9 | 349/500 [02:06<00:55, 2.73it/s, loss=7.217e+01]
Image optimization: 70%|####### | 350/500 [02:06<00:54, 2.73it/s, loss=7.195e+01]
Image optimization: 70%|####### | 351/500 [02:07<00:54, 2.74it/s, loss=7.177e+01]
Image optimization: 70%|####### | 352/500 [02:07<00:54, 2.74it/s, loss=7.156e+01]
Image optimization: 71%|####### | 353/500 [02:07<00:53, 2.74it/s, loss=7.132e+01]
Image optimization: 71%|####### | 354/500 [02:08<00:53, 2.73it/s, loss=7.110e+01]
Image optimization: 71%|#######1 | 355/500 [02:08<00:53, 2.73it/s, loss=7.095e+01]
Image optimization: 71%|#######1 | 356/500 [02:08<00:52, 2.74it/s, loss=7.069e+01]
Image optimization: 71%|#######1 | 357/500 [02:09<00:52, 2.74it/s, loss=7.051e+01]
Image optimization: 72%|#######1 | 358/500 [02:09<00:51, 2.74it/s, loss=7.036e+01]
Image optimization: 72%|#######1 | 359/500 [02:10<00:51, 2.74it/s, loss=7.020e+01]
Image optimization: 72%|#######2 | 360/500 [02:10<00:51, 2.74it/s, loss=7.007e+01]
Image optimization: 72%|#######2 | 361/500 [02:10<00:50, 2.74it/s, loss=6.990e+01]
Image optimization: 72%|#######2 | 362/500 [02:11<00:50, 2.74it/s, loss=6.966e+01]
Image optimization: 73%|#######2 | 363/500 [02:11<00:50, 2.74it/s, loss=6.955e+01]
Image optimization: 73%|#######2 | 364/500 [02:11<00:49, 2.74it/s, loss=6.935e+01]
Image optimization: 73%|#######3 | 365/500 [02:12<00:49, 2.74it/s, loss=6.918e+01]
Image optimization: 73%|#######3 | 366/500 [02:12<00:48, 2.74it/s, loss=6.895e+01]
Image optimization: 73%|#######3 | 367/500 [02:12<00:48, 2.73it/s, loss=6.876e+01]
Image optimization: 74%|#######3 | 368/500 [02:13<00:48, 2.73it/s, loss=6.860e+01]
Image optimization: 74%|#######3 | 369/500 [02:13<00:47, 2.74it/s, loss=6.846e+01]
Image optimization: 74%|#######4 | 370/500 [02:14<00:47, 2.73it/s, loss=6.824e+01]
Image optimization: 74%|#######4 | 371/500 [02:14<00:47, 2.73it/s, loss=6.807e+01]
Image optimization: 74%|#######4 | 372/500 [02:14<00:46, 2.73it/s, loss=6.794e+01]
Image optimization: 75%|#######4 | 373/500 [02:15<00:46, 2.73it/s, loss=6.776e+01]
Image optimization: 75%|#######4 | 374/500 [02:15<00:46, 2.74it/s, loss=6.763e+01]
Image optimization: 75%|#######5 | 375/500 [02:15<00:45, 2.74it/s, loss=6.742e+01]
Image optimization: 75%|#######5 | 376/500 [02:16<00:45, 2.73it/s, loss=6.723e+01]
Image optimization: 75%|#######5 | 377/500 [02:16<00:44, 2.73it/s, loss=6.705e+01]
Image optimization: 76%|#######5 | 378/500 [02:16<00:44, 2.74it/s, loss=6.689e+01]
Image optimization: 76%|#######5 | 379/500 [02:17<00:44, 2.74it/s, loss=6.673e+01]
Image optimization: 76%|#######6 | 380/500 [02:17<00:43, 2.73it/s, loss=6.657e+01]
Image optimization: 76%|#######6 | 381/500 [02:18<00:43, 2.73it/s, loss=6.644e+01]
Image optimization: 76%|#######6 | 382/500 [02:18<00:43, 2.74it/s, loss=6.627e+01]
Image optimization: 77%|#######6 | 383/500 [02:18<00:42, 2.73it/s, loss=6.613e+01]
Image optimization: 77%|#######6 | 384/500 [02:19<00:42, 2.73it/s, loss=6.599e+01]
Image optimization: 77%|#######7 | 385/500 [02:19<00:42, 2.73it/s, loss=6.580e+01]
Image optimization: 77%|#######7 | 386/500 [02:19<00:41, 2.73it/s, loss=6.566e+01]
Image optimization: 77%|#######7 | 387/500 [02:20<00:41, 2.73it/s, loss=6.549e+01]
Image optimization: 78%|#######7 | 388/500 [02:20<00:40, 2.73it/s, loss=6.531e+01]
Image optimization: 78%|#######7 | 389/500 [02:20<00:40, 2.74it/s, loss=6.517e+01]
Image optimization: 78%|#######8 | 390/500 [02:21<00:40, 2.73it/s, loss=6.506e+01]
Image optimization: 78%|#######8 | 391/500 [02:21<00:39, 2.74it/s, loss=6.489e+01]
Image optimization: 78%|#######8 | 392/500 [02:22<00:39, 2.73it/s, loss=6.477e+01]
Image optimization: 79%|#######8 | 393/500 [02:22<00:39, 2.74it/s, loss=6.465e+01]
Image optimization: 79%|#######8 | 394/500 [02:22<00:38, 2.73it/s, loss=6.449e+01]
Image optimization: 79%|#######9 | 395/500 [02:23<00:38, 2.73it/s, loss=6.438e+01]
Image optimization: 79%|#######9 | 396/500 [02:23<00:38, 2.73it/s, loss=6.424e+01]
Image optimization: 79%|#######9 | 397/500 [02:23<00:37, 2.73it/s, loss=6.407e+01]
Image optimization: 80%|#######9 | 398/500 [02:24<00:37, 2.73it/s, loss=6.391e+01]
Image optimization: 80%|#######9 | 399/500 [02:24<00:36, 2.73it/s, loss=6.378e+01]
Image optimization: 80%|######## | 400/500 [02:25<00:36, 2.73it/s, loss=6.365e+01]
Image optimization: 80%|######## | 401/500 [02:25<00:36, 2.73it/s, loss=6.348e+01]
Image optimization: 80%|######## | 402/500 [02:25<00:35, 2.74it/s, loss=6.333e+01]
Image optimization: 81%|######## | 403/500 [02:26<00:35, 2.73it/s, loss=6.319e+01]
Image optimization: 81%|######## | 404/500 [02:26<00:35, 2.73it/s, loss=6.303e+01]
Image optimization: 81%|########1 | 405/500 [02:26<00:34, 2.73it/s, loss=6.288e+01]
Image optimization: 81%|########1 | 406/500 [02:27<00:34, 2.73it/s, loss=6.276e+01]
Image optimization: 81%|########1 | 407/500 [02:27<00:34, 2.73it/s, loss=6.261e+01]
Image optimization: 82%|########1 | 408/500 [02:27<00:33, 2.73it/s, loss=6.247e+01]
Image optimization: 82%|########1 | 409/500 [02:28<00:33, 2.73it/s, loss=6.232e+01]
Image optimization: 82%|########2 | 410/500 [02:28<00:32, 2.73it/s, loss=6.218e+01]
Image optimization: 82%|########2 | 411/500 [02:29<00:32, 2.73it/s, loss=6.202e+01]
Image optimization: 82%|########2 | 412/500 [02:29<00:32, 2.73it/s, loss=6.188e+01]
Image optimization: 83%|########2 | 413/500 [02:29<00:31, 2.73it/s, loss=6.175e+01]
Image optimization: 83%|########2 | 414/500 [02:30<00:31, 2.73it/s, loss=6.162e+01]
Image optimization: 83%|########2 | 415/500 [02:30<00:31, 2.73it/s, loss=6.151e+01]
Image optimization: 83%|########3 | 416/500 [02:30<00:30, 2.73it/s, loss=6.140e+01]
Image optimization: 83%|########3 | 417/500 [02:31<00:30, 2.73it/s, loss=6.122e+01]
Image optimization: 84%|########3 | 418/500 [02:31<00:30, 2.73it/s, loss=6.111e+01]
Image optimization: 84%|########3 | 419/500 [02:31<00:29, 2.73it/s, loss=6.099e+01]
Image optimization: 84%|########4 | 420/500 [02:32<00:29, 2.73it/s, loss=6.084e+01]
Image optimization: 84%|########4 | 421/500 [02:32<00:28, 2.73it/s, loss=6.072e+01]
Image optimization: 84%|########4 | 422/500 [02:33<00:28, 2.73it/s, loss=6.057e+01]
Image optimization: 85%|########4 | 423/500 [02:33<00:28, 2.73it/s, loss=6.043e+01]
Image optimization: 85%|########4 | 424/500 [02:33<00:27, 2.73it/s, loss=6.032e+01]
Image optimization: 85%|########5 | 425/500 [02:34<00:27, 2.73it/s, loss=6.018e+01]
Image optimization: 85%|########5 | 426/500 [02:34<00:27, 2.73it/s, loss=6.003e+01]
Image optimization: 85%|########5 | 427/500 [02:34<00:26, 2.73it/s, loss=5.989e+01]
Image optimization: 86%|########5 | 428/500 [02:35<00:26, 2.73it/s, loss=5.979e+01]
Image optimization: 86%|########5 | 429/500 [02:35<00:25, 2.73it/s, loss=5.964e+01]
Image optimization: 86%|########6 | 430/500 [02:36<00:25, 2.73it/s, loss=5.953e+01]
Image optimization: 86%|########6 | 431/500 [02:36<00:25, 2.73it/s, loss=5.944e+01]
Image optimization: 86%|########6 | 432/500 [02:36<00:24, 2.73it/s, loss=5.934e+01]
Image optimization: 87%|########6 | 433/500 [02:37<00:24, 2.73it/s, loss=5.927e+01]
Image optimization: 87%|########6 | 434/500 [02:37<00:24, 2.73it/s, loss=5.914e+01]
Image optimization: 87%|########7 | 435/500 [02:37<00:23, 2.73it/s, loss=5.901e+01]
Image optimization: 87%|########7 | 436/500 [02:38<00:23, 2.74it/s, loss=5.884e+01]
Image optimization: 87%|########7 | 437/500 [02:38<00:23, 2.73it/s, loss=5.873e+01]
Image optimization: 88%|########7 | 438/500 [02:38<00:22, 2.74it/s, loss=5.865e+01]
Image optimization: 88%|########7 | 439/500 [02:39<00:22, 2.74it/s, loss=5.851e+01]
Image optimization: 88%|########8 | 440/500 [02:39<00:21, 2.74it/s, loss=5.840e+01]
Image optimization: 88%|########8 | 441/500 [02:40<00:21, 2.74it/s, loss=5.828e+01]
Image optimization: 88%|########8 | 442/500 [02:40<00:21, 2.74it/s, loss=5.813e+01]
Image optimization: 89%|########8 | 443/500 [02:40<00:20, 2.74it/s, loss=5.804e+01]
Image optimization: 89%|########8 | 444/500 [02:41<00:20, 2.74it/s, loss=5.795e+01]
Image optimization: 89%|########9 | 445/500 [02:41<00:20, 2.74it/s, loss=5.782e+01]
Image optimization: 89%|########9 | 446/500 [02:41<00:19, 2.74it/s, loss=5.770e+01]
Image optimization: 89%|########9 | 447/500 [02:42<00:19, 2.74it/s, loss=5.759e+01]
Image optimization: 90%|########9 | 448/500 [02:42<00:19, 2.74it/s, loss=5.745e+01]
Image optimization: 90%|########9 | 449/500 [02:42<00:18, 2.73it/s, loss=5.732e+01]
Image optimization: 90%|######### | 450/500 [02:43<00:18, 2.73it/s, loss=5.720e+01]
Image optimization: 90%|######### | 451/500 [02:43<00:17, 2.73it/s, loss=5.710e+01]
Image optimization: 90%|######### | 452/500 [02:44<00:17, 2.73it/s, loss=5.698e+01]
Image optimization: 91%|######### | 453/500 [02:44<00:17, 2.73it/s, loss=5.687e+01]
Image optimization: 91%|######### | 454/500 [02:44<00:16, 2.74it/s, loss=5.676e+01]
Image optimization: 91%|#########1| 455/500 [02:45<00:16, 2.73it/s, loss=5.664e+01]
Image optimization: 91%|#########1| 456/500 [02:45<00:16, 2.73it/s, loss=5.652e+01]
Image optimization: 91%|#########1| 457/500 [02:45<00:15, 2.73it/s, loss=5.642e+01]
Image optimization: 92%|#########1| 458/500 [02:46<00:15, 2.74it/s, loss=5.632e+01]
Image optimization: 92%|#########1| 459/500 [02:46<00:14, 2.74it/s, loss=5.620e+01]
Image optimization: 92%|#########2| 460/500 [02:46<00:14, 2.74it/s, loss=5.608e+01]
Image optimization: 92%|#########2| 461/500 [02:47<00:14, 2.74it/s, loss=5.598e+01]
Image optimization: 92%|#########2| 462/500 [02:47<00:13, 2.73it/s, loss=5.587e+01]
Image optimization: 93%|#########2| 463/500 [02:48<00:13, 2.73it/s, loss=5.576e+01]
Image optimization: 93%|#########2| 464/500 [02:48<00:13, 2.73it/s, loss=5.564e+01]
Image optimization: 93%|#########3| 465/500 [02:48<00:12, 2.73it/s, loss=5.554e+01]
Image optimization: 93%|#########3| 466/500 [02:49<00:12, 2.74it/s, loss=5.546e+01]
Image optimization: 93%|#########3| 467/500 [02:49<00:12, 2.73it/s, loss=5.536e+01]
Image optimization: 94%|#########3| 468/500 [02:49<00:11, 2.74it/s, loss=5.523e+01]
Image optimization: 94%|#########3| 469/500 [02:50<00:11, 2.74it/s, loss=5.512e+01]
Image optimization: 94%|#########3| 470/500 [02:50<00:10, 2.74it/s, loss=5.501e+01]
Image optimization: 94%|#########4| 471/500 [02:50<00:10, 2.74it/s, loss=5.493e+01]
Image optimization: 94%|#########4| 472/500 [02:51<00:10, 2.74it/s, loss=5.481e+01]
Image optimization: 95%|#########4| 473/500 [02:51<00:09, 2.74it/s, loss=5.472e+01]
Image optimization: 95%|#########4| 474/500 [02:52<00:09, 2.74it/s, loss=5.461e+01]
Image optimization: 95%|#########5| 475/500 [02:52<00:09, 2.74it/s, loss=5.454e+01]
Image optimization: 95%|#########5| 476/500 [02:52<00:08, 2.74it/s, loss=5.448e+01]
Image optimization: 95%|#########5| 477/500 [02:53<00:08, 2.73it/s, loss=5.439e+01]
Image optimization: 96%|#########5| 478/500 [02:53<00:08, 2.74it/s, loss=5.430e+01]
Image optimization: 96%|#########5| 479/500 [02:53<00:07, 2.74it/s, loss=5.418e+01]
Image optimization: 96%|#########6| 480/500 [02:54<00:07, 2.73it/s, loss=5.408e+01]
Image optimization: 96%|#########6| 481/500 [02:54<00:06, 2.73it/s, loss=5.399e+01]
Image optimization: 96%|#########6| 482/500 [02:55<00:06, 2.73it/s, loss=5.392e+01]
Image optimization: 97%|#########6| 483/500 [02:55<00:06, 2.73it/s, loss=5.383e+01]
Image optimization: 97%|#########6| 484/500 [02:55<00:05, 2.73it/s, loss=5.372e+01]
Image optimization: 97%|#########7| 485/500 [02:56<00:05, 2.74it/s, loss=5.364e+01]
Image optimization: 97%|#########7| 486/500 [02:56<00:05, 2.74it/s, loss=5.357e+01]
Image optimization: 97%|#########7| 487/500 [02:56<00:04, 2.74it/s, loss=5.347e+01]
Image optimization: 98%|#########7| 488/500 [02:57<00:04, 2.73it/s, loss=5.338e+01]
Image optimization: 98%|#########7| 489/500 [02:57<00:04, 2.74it/s, loss=5.329e+01]
Image optimization: 98%|#########8| 490/500 [02:57<00:03, 2.74it/s, loss=5.318e+01]
Image optimization: 98%|#########8| 491/500 [02:58<00:03, 2.73it/s, loss=5.309e+01]
Image optimization: 98%|#########8| 492/500 [02:58<00:02, 2.73it/s, loss=5.301e+01]
Image optimization: 99%|#########8| 493/500 [02:59<00:02, 2.74it/s, loss=5.292e+01]
Image optimization: 99%|#########8| 494/500 [02:59<00:02, 2.73it/s, loss=5.284e+01]
Image optimization: 99%|#########9| 495/500 [02:59<00:01, 2.73it/s, loss=5.276e+01]
Image optimization: 99%|#########9| 496/500 [03:00<00:01, 2.73it/s, loss=5.269e+01]
Image optimization: 99%|#########9| 497/500 [03:00<00:01, 2.73it/s, loss=5.260e+01]
Image optimization: 100%|#########9| 498/500 [03:00<00:00, 2.73it/s, loss=5.251e+01]
Image optimization: 100%|#########9| 499/500 [03:01<00:00, 2.73it/s, loss=5.243e+01]
Image optimization: 100%|##########| 500/500 [03:01<00:00, 2.74it/s, loss=5.232e+01]
Image optimization: 100%|##########| 500/500 [03:01<00:00, 2.75it/s, loss=5.232e+01]
209 show_image(output_image)
With regional constraints we successfully removed the blueish cast from the building which leads to an overall higher quality. Unfortunately, reusing the sky region for the water did not work out too well: due to the vibrant color, the water looks unnatural.
Fortunately, this has an easy solution. Since we are already using separate losses
for each region we are not bound to use only a single style_image
: if required,
we can use a different style_image
for each region.
Guided image optimization with multiple styles¶
We load a second style image that has water in it.
229 second_style_image = images["cliff"].read(size=size, device=device)
230 show_image(second_style_image, "Second style image")
234 second_style_guides = images["cliff"].guides.read(size=size, device=device)
235 show_image(guides_to_segmentation(second_style_guides), "Second style segmentation")
We can reuse the previously defined criterion and only change the style_image
and
style_guides
in the "water"
region.
242 region = "water"
243 perceptual_loss.set_style_image(
244 second_style_image, guide=second_style_guides[region], region=region
245 )
Finally, we rerun the optimization again with the new constraints.
251 starting_point = "content"
252 input_image = get_input_image(starting_point, content_image=content_image)
253
254 output_image = optim.image_optimization(input_image, perceptual_loss, num_steps=500)
Out:
Image optimization: 0%| | 0/500 [00:00<?, ?it/s]
Image optimization: 0%| | 1/500 [00:00<02:49, 2.94it/s, loss=6.512e+03]
Image optimization: 0%| | 2/500 [00:00<02:48, 2.96it/s, loss=6.507e+03]
Image optimization: 1%| | 3/500 [00:01<02:53, 2.86it/s, loss=4.154e+03]
Image optimization: 1%| | 4/500 [00:01<02:50, 2.90it/s, loss=3.580e+03]
Image optimization: 1%|1 | 5/500 [00:01<02:48, 2.93it/s, loss=2.868e+03]
Image optimization: 1%|1 | 6/500 [00:02<02:50, 2.89it/s, loss=2.241e+03]
Image optimization: 1%|1 | 7/500 [00:02<02:49, 2.90it/s, loss=1.774e+03]
Image optimization: 2%|1 | 8/500 [00:02<02:49, 2.91it/s, loss=1.620e+03]
Image optimization: 2%|1 | 9/500 [00:03<02:49, 2.89it/s, loss=1.442e+03]
Image optimization: 2%|2 | 10/500 [00:03<02:49, 2.90it/s, loss=1.357e+03]
Image optimization: 2%|2 | 11/500 [00:03<02:48, 2.90it/s, loss=1.208e+03]
Image optimization: 2%|2 | 12/500 [00:04<02:48, 2.90it/s, loss=1.044e+03]
Image optimization: 3%|2 | 13/500 [00:04<02:47, 2.90it/s, loss=9.344e+02]
Image optimization: 3%|2 | 14/500 [00:04<02:47, 2.91it/s, loss=8.447e+02]
Image optimization: 3%|3 | 15/500 [00:05<02:46, 2.90it/s, loss=7.913e+02]
Image optimization: 3%|3 | 16/500 [00:05<02:46, 2.91it/s, loss=7.185e+02]
Image optimization: 3%|3 | 17/500 [00:05<02:46, 2.90it/s, loss=6.926e+02]
Image optimization: 4%|3 | 18/500 [00:06<02:46, 2.90it/s, loss=6.326e+02]
Image optimization: 4%|3 | 19/500 [00:06<02:45, 2.90it/s, loss=6.133e+02]
Image optimization: 4%|4 | 20/500 [00:06<02:45, 2.90it/s, loss=5.900e+02]
Image optimization: 4%|4 | 21/500 [00:07<02:45, 2.89it/s, loss=5.579e+02]
Image optimization: 4%|4 | 22/500 [00:07<02:45, 2.89it/s, loss=5.313e+02]
Image optimization: 5%|4 | 23/500 [00:07<02:44, 2.89it/s, loss=5.112e+02]
Image optimization: 5%|4 | 24/500 [00:08<02:44, 2.89it/s, loss=4.870e+02]
Image optimization: 5%|5 | 25/500 [00:08<02:44, 2.89it/s, loss=4.633e+02]
Image optimization: 5%|5 | 26/500 [00:08<02:44, 2.88it/s, loss=4.492e+02]
Image optimization: 5%|5 | 27/500 [00:09<02:44, 2.87it/s, loss=4.299e+02]
Image optimization: 6%|5 | 28/500 [00:09<02:44, 2.87it/s, loss=4.194e+02]
Image optimization: 6%|5 | 29/500 [00:10<02:43, 2.87it/s, loss=4.034e+02]
Image optimization: 6%|6 | 30/500 [00:10<02:43, 2.87it/s, loss=3.949e+02]
Image optimization: 6%|6 | 31/500 [00:10<02:43, 2.87it/s, loss=3.845e+02]
Image optimization: 6%|6 | 32/500 [00:11<02:43, 2.87it/s, loss=3.790e+02]
Image optimization: 7%|6 | 33/500 [00:11<02:43, 2.86it/s, loss=3.691e+02]
Image optimization: 7%|6 | 34/500 [00:11<02:42, 2.87it/s, loss=3.589e+02]
Image optimization: 7%|7 | 35/500 [00:12<02:42, 2.86it/s, loss=3.510e+02]
Image optimization: 7%|7 | 36/500 [00:12<02:42, 2.86it/s, loss=3.420e+02]
Image optimization: 7%|7 | 37/500 [00:12<02:42, 2.85it/s, loss=3.349e+02]
Image optimization: 8%|7 | 38/500 [00:13<02:41, 2.85it/s, loss=3.289e+02]
Image optimization: 8%|7 | 39/500 [00:13<02:41, 2.85it/s, loss=3.213e+02]
Image optimization: 8%|8 | 40/500 [00:13<02:41, 2.85it/s, loss=3.174e+02]
Image optimization: 8%|8 | 41/500 [00:14<02:41, 2.85it/s, loss=3.094e+02]
Image optimization: 8%|8 | 42/500 [00:14<02:40, 2.85it/s, loss=3.026e+02]
Image optimization: 9%|8 | 43/500 [00:14<02:40, 2.84it/s, loss=2.974e+02]
Image optimization: 9%|8 | 44/500 [00:15<02:40, 2.84it/s, loss=2.925e+02]
Image optimization: 9%|9 | 45/500 [00:15<02:40, 2.84it/s, loss=2.885e+02]
Image optimization: 9%|9 | 46/500 [00:15<02:39, 2.84it/s, loss=2.837e+02]
Image optimization: 9%|9 | 47/500 [00:16<02:39, 2.84it/s, loss=2.812e+02]
Image optimization: 10%|9 | 48/500 [00:16<02:39, 2.84it/s, loss=2.758e+02]
Image optimization: 10%|9 | 49/500 [00:17<02:38, 2.84it/s, loss=2.713e+02]
Image optimization: 10%|# | 50/500 [00:17<02:38, 2.83it/s, loss=2.676e+02]
Image optimization: 10%|# | 51/500 [00:17<02:38, 2.83it/s, loss=2.651e+02]
Image optimization: 10%|# | 52/500 [00:18<02:38, 2.83it/s, loss=2.607e+02]
Image optimization: 11%|# | 53/500 [00:18<02:38, 2.82it/s, loss=2.573e+02]
Image optimization: 11%|# | 54/500 [00:18<02:37, 2.83it/s, loss=2.540e+02]
Image optimization: 11%|#1 | 55/500 [00:19<02:37, 2.83it/s, loss=2.517e+02]
Image optimization: 11%|#1 | 56/500 [00:19<02:36, 2.83it/s, loss=2.490e+02]
Image optimization: 11%|#1 | 57/500 [00:19<02:36, 2.82it/s, loss=2.461e+02]
Image optimization: 12%|#1 | 58/500 [00:20<02:36, 2.82it/s, loss=2.438e+02]
Image optimization: 12%|#1 | 59/500 [00:20<02:36, 2.82it/s, loss=2.401e+02]
Image optimization: 12%|#2 | 60/500 [00:20<02:36, 2.81it/s, loss=2.365e+02]
Image optimization: 12%|#2 | 61/500 [00:21<02:36, 2.81it/s, loss=2.335e+02]
Image optimization: 12%|#2 | 62/500 [00:21<02:35, 2.81it/s, loss=2.321e+02]
Image optimization: 13%|#2 | 63/500 [00:22<02:35, 2.81it/s, loss=2.299e+02]
Image optimization: 13%|#2 | 64/500 [00:22<02:35, 2.81it/s, loss=2.281e+02]
Image optimization: 13%|#3 | 65/500 [00:22<02:35, 2.81it/s, loss=2.257e+02]
Image optimization: 13%|#3 | 66/500 [00:23<02:34, 2.81it/s, loss=2.224e+02]
Image optimization: 13%|#3 | 67/500 [00:23<02:34, 2.80it/s, loss=2.201e+02]
Image optimization: 14%|#3 | 68/500 [00:23<02:34, 2.80it/s, loss=2.179e+02]
Image optimization: 14%|#3 | 69/500 [00:24<02:34, 2.80it/s, loss=2.159e+02]
Image optimization: 14%|#4 | 70/500 [00:24<02:33, 2.80it/s, loss=2.141e+02]
Image optimization: 14%|#4 | 71/500 [00:24<02:33, 2.80it/s, loss=2.125e+02]
Image optimization: 14%|#4 | 72/500 [00:25<02:33, 2.79it/s, loss=2.108e+02]
Image optimization: 15%|#4 | 73/500 [00:25<02:32, 2.79it/s, loss=2.082e+02]
Image optimization: 15%|#4 | 74/500 [00:25<02:32, 2.79it/s, loss=2.066e+02]
Image optimization: 15%|#5 | 75/500 [00:26<02:32, 2.78it/s, loss=2.050e+02]
Image optimization: 15%|#5 | 76/500 [00:26<02:32, 2.78it/s, loss=2.035e+02]
Image optimization: 15%|#5 | 77/500 [00:27<02:31, 2.78it/s, loss=2.022e+02]
Image optimization: 16%|#5 | 78/500 [00:27<02:32, 2.78it/s, loss=2.005e+02]
Image optimization: 16%|#5 | 79/500 [00:27<02:31, 2.78it/s, loss=1.986e+02]
Image optimization: 16%|#6 | 80/500 [00:28<02:31, 2.77it/s, loss=1.976e+02]
Image optimization: 16%|#6 | 81/500 [00:28<02:31, 2.77it/s, loss=1.956e+02]
Image optimization: 16%|#6 | 82/500 [00:28<02:30, 2.78it/s, loss=1.943e+02]
Image optimization: 17%|#6 | 83/500 [00:29<02:30, 2.77it/s, loss=1.931e+02]
Image optimization: 17%|#6 | 84/500 [00:29<02:30, 2.77it/s, loss=1.912e+02]
Image optimization: 17%|#7 | 85/500 [00:29<02:29, 2.77it/s, loss=1.900e+02]
Image optimization: 17%|#7 | 86/500 [00:30<02:29, 2.77it/s, loss=1.883e+02]
Image optimization: 17%|#7 | 87/500 [00:30<02:29, 2.76it/s, loss=1.869e+02]
Image optimization: 18%|#7 | 88/500 [00:31<02:29, 2.76it/s, loss=1.856e+02]
Image optimization: 18%|#7 | 89/500 [00:31<02:29, 2.75it/s, loss=1.846e+02]
Image optimization: 18%|#8 | 90/500 [00:31<02:28, 2.75it/s, loss=1.834e+02]
Image optimization: 18%|#8 | 91/500 [00:32<02:28, 2.75it/s, loss=1.820e+02]
Image optimization: 18%|#8 | 92/500 [00:32<02:28, 2.75it/s, loss=1.811e+02]
Image optimization: 19%|#8 | 93/500 [00:32<02:27, 2.75it/s, loss=1.790e+02]
Image optimization: 19%|#8 | 94/500 [00:33<02:27, 2.75it/s, loss=1.779e+02]
Image optimization: 19%|#9 | 95/500 [00:33<02:27, 2.75it/s, loss=1.768e+02]
Image optimization: 19%|#9 | 96/500 [00:33<02:27, 2.74it/s, loss=1.755e+02]
Image optimization: 19%|#9 | 97/500 [00:34<02:26, 2.74it/s, loss=1.744e+02]
Image optimization: 20%|#9 | 98/500 [00:34<02:26, 2.74it/s, loss=1.732e+02]
Image optimization: 20%|#9 | 99/500 [00:35<02:26, 2.74it/s, loss=1.718e+02]
Image optimization: 20%|## | 100/500 [00:35<02:26, 2.74it/s, loss=1.705e+02]
Image optimization: 20%|## | 101/500 [00:35<02:26, 2.73it/s, loss=1.695e+02]
Image optimization: 20%|## | 102/500 [00:36<02:25, 2.73it/s, loss=1.684e+02]
Image optimization: 21%|## | 103/500 [00:36<02:25, 2.73it/s, loss=1.672e+02]
Image optimization: 21%|## | 104/500 [00:36<02:24, 2.73it/s, loss=1.663e+02]
Image optimization: 21%|##1 | 105/500 [00:37<02:24, 2.73it/s, loss=1.654e+02]
Image optimization: 21%|##1 | 106/500 [00:37<02:24, 2.73it/s, loss=1.644e+02]
Image optimization: 21%|##1 | 107/500 [00:37<02:24, 2.73it/s, loss=1.634e+02]
Image optimization: 22%|##1 | 108/500 [00:38<02:23, 2.73it/s, loss=1.621e+02]
Image optimization: 22%|##1 | 109/500 [00:38<02:23, 2.73it/s, loss=1.607e+02]
Image optimization: 22%|##2 | 110/500 [00:39<02:23, 2.73it/s, loss=1.597e+02]
Image optimization: 22%|##2 | 111/500 [00:39<02:22, 2.73it/s, loss=1.584e+02]
Image optimization: 22%|##2 | 112/500 [00:39<02:22, 2.73it/s, loss=1.573e+02]
Image optimization: 23%|##2 | 113/500 [00:40<02:21, 2.73it/s, loss=1.561e+02]
Image optimization: 23%|##2 | 114/500 [00:40<02:21, 2.73it/s, loss=1.552e+02]
Image optimization: 23%|##3 | 115/500 [00:40<02:21, 2.73it/s, loss=1.544e+02]
Image optimization: 23%|##3 | 116/500 [00:41<02:20, 2.73it/s, loss=1.539e+02]
Image optimization: 23%|##3 | 117/500 [00:41<02:20, 2.73it/s, loss=1.527e+02]
Image optimization: 24%|##3 | 118/500 [00:41<02:20, 2.73it/s, loss=1.520e+02]
Image optimization: 24%|##3 | 119/500 [00:42<02:19, 2.73it/s, loss=1.507e+02]
Image optimization: 24%|##4 | 120/500 [00:42<02:19, 2.73it/s, loss=1.493e+02]
Image optimization: 24%|##4 | 121/500 [00:43<02:18, 2.73it/s, loss=1.480e+02]
Image optimization: 24%|##4 | 122/500 [00:43<02:18, 2.73it/s, loss=1.472e+02]
Image optimization: 25%|##4 | 123/500 [00:43<02:18, 2.73it/s, loss=1.466e+02]
Image optimization: 25%|##4 | 124/500 [00:44<02:17, 2.73it/s, loss=1.455e+02]
Image optimization: 25%|##5 | 125/500 [00:44<02:17, 2.73it/s, loss=1.442e+02]
Image optimization: 25%|##5 | 126/500 [00:44<02:17, 2.73it/s, loss=1.431e+02]
Image optimization: 25%|##5 | 127/500 [00:45<02:16, 2.73it/s, loss=1.424e+02]
Image optimization: 26%|##5 | 128/500 [00:45<02:16, 2.73it/s, loss=1.415e+02]
Image optimization: 26%|##5 | 129/500 [00:46<02:15, 2.73it/s, loss=1.405e+02]
Image optimization: 26%|##6 | 130/500 [00:46<02:15, 2.73it/s, loss=1.392e+02]
Image optimization: 26%|##6 | 131/500 [00:46<02:15, 2.73it/s, loss=1.382e+02]
Image optimization: 26%|##6 | 132/500 [00:47<02:14, 2.73it/s, loss=1.374e+02]
Image optimization: 27%|##6 | 133/500 [00:47<02:14, 2.73it/s, loss=1.363e+02]
Image optimization: 27%|##6 | 134/500 [00:47<02:13, 2.73it/s, loss=1.351e+02]
Image optimization: 27%|##7 | 135/500 [00:48<02:13, 2.73it/s, loss=1.343e+02]
Image optimization: 27%|##7 | 136/500 [00:48<02:13, 2.73it/s, loss=1.330e+02]
Image optimization: 27%|##7 | 137/500 [00:48<02:12, 2.74it/s, loss=1.322e+02]
Image optimization: 28%|##7 | 138/500 [00:49<02:12, 2.73it/s, loss=1.314e+02]
Image optimization: 28%|##7 | 139/500 [00:49<02:11, 2.74it/s, loss=1.301e+02]
Image optimization: 28%|##8 | 140/500 [00:50<02:11, 2.73it/s, loss=1.292e+02]
Image optimization: 28%|##8 | 141/500 [00:50<02:11, 2.74it/s, loss=1.279e+02]
Image optimization: 28%|##8 | 142/500 [00:50<02:10, 2.73it/s, loss=1.271e+02]
Image optimization: 29%|##8 | 143/500 [00:51<02:10, 2.74it/s, loss=1.264e+02]
Image optimization: 29%|##8 | 144/500 [00:51<02:10, 2.73it/s, loss=1.255e+02]
Image optimization: 29%|##9 | 145/500 [00:51<02:09, 2.73it/s, loss=1.247e+02]
Image optimization: 29%|##9 | 146/500 [00:52<02:09, 2.73it/s, loss=1.235e+02]
Image optimization: 29%|##9 | 147/500 [00:52<02:09, 2.73it/s, loss=1.226e+02]
Image optimization: 30%|##9 | 148/500 [00:52<02:08, 2.73it/s, loss=1.217e+02]
Image optimization: 30%|##9 | 149/500 [00:53<02:08, 2.73it/s, loss=1.206e+02]
Image optimization: 30%|### | 150/500 [00:53<02:07, 2.73it/s, loss=1.198e+02]
Image optimization: 30%|### | 151/500 [00:54<02:07, 2.73it/s, loss=1.185e+02]
Image optimization: 30%|### | 152/500 [00:54<02:07, 2.73it/s, loss=1.176e+02]
Image optimization: 31%|### | 153/500 [00:54<02:07, 2.73it/s, loss=1.166e+02]
Image optimization: 31%|### | 154/500 [00:55<02:06, 2.73it/s, loss=1.157e+02]
Image optimization: 31%|###1 | 155/500 [00:55<02:06, 2.73it/s, loss=1.146e+02]
Image optimization: 31%|###1 | 156/500 [00:55<02:05, 2.74it/s, loss=1.139e+02]
Image optimization: 31%|###1 | 157/500 [00:56<02:05, 2.73it/s, loss=1.128e+02]
Image optimization: 32%|###1 | 158/500 [00:56<02:05, 2.73it/s, loss=1.121e+02]
Image optimization: 32%|###1 | 159/500 [00:56<02:04, 2.73it/s, loss=1.114e+02]
Image optimization: 32%|###2 | 160/500 [00:57<02:04, 2.73it/s, loss=1.107e+02]
Image optimization: 32%|###2 | 161/500 [00:57<02:04, 2.73it/s, loss=1.101e+02]
Image optimization: 32%|###2 | 162/500 [00:58<02:03, 2.73it/s, loss=1.092e+02]
Image optimization: 33%|###2 | 163/500 [00:58<02:03, 2.73it/s, loss=1.082e+02]
Image optimization: 33%|###2 | 164/500 [00:58<02:02, 2.73it/s, loss=1.072e+02]
Image optimization: 33%|###3 | 165/500 [00:59<02:02, 2.73it/s, loss=1.066e+02]
Image optimization: 33%|###3 | 166/500 [00:59<02:02, 2.73it/s, loss=1.058e+02]
Image optimization: 33%|###3 | 167/500 [00:59<02:01, 2.73it/s, loss=1.050e+02]
Image optimization: 34%|###3 | 168/500 [01:00<02:01, 2.73it/s, loss=1.040e+02]
Image optimization: 34%|###3 | 169/500 [01:00<02:00, 2.74it/s, loss=1.030e+02]
Image optimization: 34%|###4 | 170/500 [01:01<02:00, 2.73it/s, loss=1.021e+02]
Image optimization: 34%|###4 | 171/500 [01:01<02:00, 2.73it/s, loss=1.014e+02]
Image optimization: 34%|###4 | 172/500 [01:01<01:59, 2.73it/s, loss=1.003e+02]
Image optimization: 35%|###4 | 173/500 [01:02<01:59, 2.73it/s, loss=9.966e+01]
Image optimization: 35%|###4 | 174/500 [01:02<01:59, 2.73it/s, loss=9.905e+01]
Image optimization: 35%|###5 | 175/500 [01:02<01:59, 2.73it/s, loss=9.833e+01]
Image optimization: 35%|###5 | 176/500 [01:03<01:58, 2.73it/s, loss=9.779e+01]
Image optimization: 35%|###5 | 177/500 [01:03<01:58, 2.73it/s, loss=9.687e+01]
Image optimization: 36%|###5 | 178/500 [01:03<01:57, 2.73it/s, loss=9.627e+01]
Image optimization: 36%|###5 | 179/500 [01:04<01:57, 2.73it/s, loss=9.553e+01]
Image optimization: 36%|###6 | 180/500 [01:04<01:57, 2.73it/s, loss=9.501e+01]
Image optimization: 36%|###6 | 181/500 [01:05<01:56, 2.73it/s, loss=9.453e+01]
Image optimization: 36%|###6 | 182/500 [01:05<01:56, 2.73it/s, loss=9.366e+01]
Image optimization: 37%|###6 | 183/500 [01:05<01:55, 2.73it/s, loss=9.295e+01]
Image optimization: 37%|###6 | 184/500 [01:06<01:55, 2.73it/s, loss=9.221e+01]
Image optimization: 37%|###7 | 185/500 [01:06<01:55, 2.74it/s, loss=9.153e+01]
Image optimization: 37%|###7 | 186/500 [01:06<01:54, 2.73it/s, loss=9.080e+01]
Image optimization: 37%|###7 | 187/500 [01:07<01:54, 2.73it/s, loss=9.013e+01]
Image optimization: 38%|###7 | 188/500 [01:07<01:54, 2.73it/s, loss=8.947e+01]
Image optimization: 38%|###7 | 189/500 [01:07<01:53, 2.73it/s, loss=8.880e+01]
Image optimization: 38%|###8 | 190/500 [01:08<01:53, 2.73it/s, loss=8.823e+01]
Image optimization: 38%|###8 | 191/500 [01:08<01:52, 2.74it/s, loss=8.766e+01]
Image optimization: 38%|###8 | 192/500 [01:09<01:52, 2.74it/s, loss=8.712e+01]
Image optimization: 39%|###8 | 193/500 [01:09<01:52, 2.73it/s, loss=8.662e+01]
Image optimization: 39%|###8 | 194/500 [01:09<01:51, 2.74it/s, loss=8.589e+01]
Image optimization: 39%|###9 | 195/500 [01:10<01:51, 2.73it/s, loss=8.526e+01]
Image optimization: 39%|###9 | 196/500 [01:10<01:51, 2.73it/s, loss=8.480e+01]
Image optimization: 39%|###9 | 197/500 [01:10<01:50, 2.73it/s, loss=8.432e+01]
Image optimization: 40%|###9 | 198/500 [01:11<01:50, 2.73it/s, loss=8.385e+01]
Image optimization: 40%|###9 | 199/500 [01:11<01:50, 2.74it/s, loss=8.330e+01]
Image optimization: 40%|#### | 200/500 [01:11<01:49, 2.73it/s, loss=8.259e+01]
Image optimization: 40%|#### | 201/500 [01:12<01:49, 2.73it/s, loss=8.204e+01]
Image optimization: 40%|#### | 202/500 [01:12<01:49, 2.73it/s, loss=8.169e+01]
Image optimization: 41%|#### | 203/500 [01:13<01:48, 2.73it/s, loss=8.119e+01]
Image optimization: 41%|#### | 204/500 [01:13<01:48, 2.74it/s, loss=8.077e+01]
Image optimization: 41%|####1 | 205/500 [01:13<01:47, 2.74it/s, loss=8.039e+01]
Image optimization: 41%|####1 | 206/500 [01:14<01:47, 2.73it/s, loss=7.981e+01]
Image optimization: 41%|####1 | 207/500 [01:14<01:47, 2.73it/s, loss=7.938e+01]
Image optimization: 42%|####1 | 208/500 [01:14<01:46, 2.73it/s, loss=7.875e+01]
Image optimization: 42%|####1 | 209/500 [01:15<01:46, 2.74it/s, loss=7.812e+01]
Image optimization: 42%|####2 | 210/500 [01:15<01:45, 2.74it/s, loss=7.762e+01]
Image optimization: 42%|####2 | 211/500 [01:16<01:45, 2.73it/s, loss=7.729e+01]
Image optimization: 42%|####2 | 212/500 [01:16<01:45, 2.73it/s, loss=7.687e+01]
Image optimization: 43%|####2 | 213/500 [01:16<01:44, 2.73it/s, loss=7.650e+01]
Image optimization: 43%|####2 | 214/500 [01:17<01:44, 2.73it/s, loss=7.606e+01]
Image optimization: 43%|####3 | 215/500 [01:17<01:44, 2.73it/s, loss=7.553e+01]
Image optimization: 43%|####3 | 216/500 [01:17<01:43, 2.73it/s, loss=7.507e+01]
Image optimization: 43%|####3 | 217/500 [01:18<01:43, 2.74it/s, loss=7.457e+01]
Image optimization: 44%|####3 | 218/500 [01:18<01:43, 2.73it/s, loss=7.411e+01]
Image optimization: 44%|####3 | 219/500 [01:18<01:42, 2.73it/s, loss=7.364e+01]
Image optimization: 44%|####4 | 220/500 [01:19<01:42, 2.73it/s, loss=7.322e+01]
Image optimization: 44%|####4 | 221/500 [01:19<01:41, 2.74it/s, loss=7.296e+01]
Image optimization: 44%|####4 | 222/500 [01:20<01:41, 2.74it/s, loss=7.259e+01]
Image optimization: 45%|####4 | 223/500 [01:20<01:41, 2.73it/s, loss=7.222e+01]
Image optimization: 45%|####4 | 224/500 [01:20<01:40, 2.74it/s, loss=7.184e+01]
Image optimization: 45%|####5 | 225/500 [01:21<01:40, 2.74it/s, loss=7.145e+01]
Image optimization: 45%|####5 | 226/500 [01:21<01:40, 2.74it/s, loss=7.108e+01]
Image optimization: 45%|####5 | 227/500 [01:21<01:39, 2.73it/s, loss=7.076e+01]
Image optimization: 46%|####5 | 228/500 [01:22<01:39, 2.73it/s, loss=7.033e+01]
Image optimization: 46%|####5 | 229/500 [01:22<01:39, 2.73it/s, loss=6.995e+01]
Image optimization: 46%|####6 | 230/500 [01:22<01:38, 2.73it/s, loss=6.969e+01]
Image optimization: 46%|####6 | 231/500 [01:23<01:38, 2.74it/s, loss=6.925e+01]
Image optimization: 46%|####6 | 232/500 [01:23<01:38, 2.73it/s, loss=6.904e+01]
Image optimization: 47%|####6 | 233/500 [01:24<01:37, 2.74it/s, loss=6.869e+01]
Image optimization: 47%|####6 | 234/500 [01:24<01:37, 2.73it/s, loss=6.821e+01]
Image optimization: 47%|####6 | 235/500 [01:24<01:36, 2.73it/s, loss=6.784e+01]
Image optimization: 47%|####7 | 236/500 [01:25<01:36, 2.74it/s, loss=6.757e+01]
Image optimization: 47%|####7 | 237/500 [01:25<01:36, 2.74it/s, loss=6.724e+01]
Image optimization: 48%|####7 | 238/500 [01:25<01:35, 2.74it/s, loss=6.686e+01]
Image optimization: 48%|####7 | 239/500 [01:26<01:35, 2.73it/s, loss=6.654e+01]
Image optimization: 48%|####8 | 240/500 [01:26<01:35, 2.73it/s, loss=6.620e+01]
Image optimization: 48%|####8 | 241/500 [01:26<01:34, 2.74it/s, loss=6.592e+01]
Image optimization: 48%|####8 | 242/500 [01:27<01:34, 2.73it/s, loss=6.560e+01]
Image optimization: 49%|####8 | 243/500 [01:27<01:33, 2.74it/s, loss=6.533e+01]
Image optimization: 49%|####8 | 244/500 [01:28<01:33, 2.74it/s, loss=6.496e+01]
Image optimization: 49%|####9 | 245/500 [01:28<01:33, 2.74it/s, loss=6.463e+01]
Image optimization: 49%|####9 | 246/500 [01:28<01:32, 2.74it/s, loss=6.424e+01]
Image optimization: 49%|####9 | 247/500 [01:29<01:32, 2.73it/s, loss=6.390e+01]
Image optimization: 50%|####9 | 248/500 [01:29<01:32, 2.74it/s, loss=6.363e+01]
Image optimization: 50%|####9 | 249/500 [01:29<01:31, 2.74it/s, loss=6.340e+01]
Image optimization: 50%|##### | 250/500 [01:30<01:31, 2.73it/s, loss=6.311e+01]
Image optimization: 50%|##### | 251/500 [01:30<01:30, 2.74it/s, loss=6.278e+01]
Image optimization: 50%|##### | 252/500 [01:30<01:30, 2.74it/s, loss=6.251e+01]
Image optimization: 51%|##### | 253/500 [01:31<01:30, 2.73it/s, loss=6.229e+01]
Image optimization: 51%|##### | 254/500 [01:31<01:29, 2.73it/s, loss=6.196e+01]
Image optimization: 51%|#####1 | 255/500 [01:32<01:29, 2.74it/s, loss=6.160e+01]
Image optimization: 51%|#####1 | 256/500 [01:32<01:29, 2.73it/s, loss=6.132e+01]
Image optimization: 51%|#####1 | 257/500 [01:32<01:28, 2.73it/s, loss=6.105e+01]
Image optimization: 52%|#####1 | 258/500 [01:33<01:28, 2.73it/s, loss=6.078e+01]
Image optimization: 52%|#####1 | 259/500 [01:33<01:28, 2.73it/s, loss=6.049e+01]
Image optimization: 52%|#####2 | 260/500 [01:33<01:27, 2.74it/s, loss=6.021e+01]
Image optimization: 52%|#####2 | 261/500 [01:34<01:27, 2.73it/s, loss=5.992e+01]
Image optimization: 52%|#####2 | 262/500 [01:34<01:27, 2.73it/s, loss=5.965e+01]
Image optimization: 53%|#####2 | 263/500 [01:35<01:26, 2.74it/s, loss=5.941e+01]
Image optimization: 53%|#####2 | 264/500 [01:35<01:26, 2.73it/s, loss=5.921e+01]
Image optimization: 53%|#####3 | 265/500 [01:35<01:26, 2.73it/s, loss=5.898e+01]
Image optimization: 53%|#####3 | 266/500 [01:36<01:25, 2.73it/s, loss=5.874e+01]
Image optimization: 53%|#####3 | 267/500 [01:36<01:25, 2.73it/s, loss=5.840e+01]
Image optimization: 54%|#####3 | 268/500 [01:36<01:24, 2.73it/s, loss=5.818e+01]
Image optimization: 54%|#####3 | 269/500 [01:37<01:24, 2.73it/s, loss=5.797e+01]
Image optimization: 54%|#####4 | 270/500 [01:37<01:24, 2.73it/s, loss=5.775e+01]
Image optimization: 54%|#####4 | 271/500 [01:37<01:23, 2.73it/s, loss=5.756e+01]
Image optimization: 54%|#####4 | 272/500 [01:38<01:23, 2.73it/s, loss=5.728e+01]
Image optimization: 55%|#####4 | 273/500 [01:38<01:23, 2.73it/s, loss=5.701e+01]
Image optimization: 55%|#####4 | 274/500 [01:39<01:22, 2.73it/s, loss=5.678e+01]
Image optimization: 55%|#####5 | 275/500 [01:39<01:22, 2.73it/s, loss=5.653e+01]
Image optimization: 55%|#####5 | 276/500 [01:39<01:22, 2.73it/s, loss=5.636e+01]
Image optimization: 55%|#####5 | 277/500 [01:40<01:21, 2.73it/s, loss=5.613e+01]
Image optimization: 56%|#####5 | 278/500 [01:40<01:21, 2.73it/s, loss=5.590e+01]
Image optimization: 56%|#####5 | 279/500 [01:40<01:20, 2.73it/s, loss=5.570e+01]
Image optimization: 56%|#####6 | 280/500 [01:41<01:20, 2.73it/s, loss=5.549e+01]
Image optimization: 56%|#####6 | 281/500 [01:41<01:20, 2.73it/s, loss=5.531e+01]
Image optimization: 56%|#####6 | 282/500 [01:41<01:19, 2.73it/s, loss=5.504e+01]
Image optimization: 57%|#####6 | 283/500 [01:42<01:19, 2.73it/s, loss=5.482e+01]
Image optimization: 57%|#####6 | 284/500 [01:42<01:19, 2.73it/s, loss=5.464e+01]
Image optimization: 57%|#####6 | 285/500 [01:43<01:18, 2.73it/s, loss=5.449e+01]
Image optimization: 57%|#####7 | 286/500 [01:43<01:18, 2.73it/s, loss=5.429e+01]
Image optimization: 57%|#####7 | 287/500 [01:43<01:18, 2.73it/s, loss=5.405e+01]
Image optimization: 58%|#####7 | 288/500 [01:44<01:17, 2.73it/s, loss=5.383e+01]
Image optimization: 58%|#####7 | 289/500 [01:44<01:17, 2.73it/s, loss=5.371e+01]
Image optimization: 58%|#####8 | 290/500 [01:44<01:16, 2.73it/s, loss=5.346e+01]
Image optimization: 58%|#####8 | 291/500 [01:45<01:16, 2.73it/s, loss=5.333e+01]
Image optimization: 58%|#####8 | 292/500 [01:45<01:16, 2.72it/s, loss=5.312e+01]
Image optimization: 59%|#####8 | 293/500 [01:46<01:15, 2.72it/s, loss=5.299e+01]
Image optimization: 59%|#####8 | 294/500 [01:46<01:15, 2.72it/s, loss=5.287e+01]
Image optimization: 59%|#####8 | 295/500 [01:46<01:15, 2.72it/s, loss=5.262e+01]
Image optimization: 59%|#####9 | 296/500 [01:47<01:14, 2.72it/s, loss=5.243e+01]
Image optimization: 59%|#####9 | 297/500 [01:47<01:14, 2.72it/s, loss=5.231e+01]
Image optimization: 60%|#####9 | 298/500 [01:47<01:14, 2.73it/s, loss=5.215e+01]
Image optimization: 60%|#####9 | 299/500 [01:48<01:13, 2.73it/s, loss=5.197e+01]
Image optimization: 60%|###### | 300/500 [01:48<01:13, 2.73it/s, loss=5.176e+01]
Image optimization: 60%|###### | 301/500 [01:48<01:12, 2.73it/s, loss=5.158e+01]
Image optimization: 60%|###### | 302/500 [01:49<01:12, 2.73it/s, loss=5.147e+01]
Image optimization: 61%|###### | 303/500 [01:49<01:12, 2.73it/s, loss=5.133e+01]
Image optimization: 61%|###### | 304/500 [01:50<01:11, 2.73it/s, loss=5.118e+01]
Image optimization: 61%|######1 | 305/500 [01:50<01:11, 2.73it/s, loss=5.101e+01]
Image optimization: 61%|######1 | 306/500 [01:50<01:11, 2.73it/s, loss=5.084e+01]
Image optimization: 61%|######1 | 307/500 [01:51<01:10, 2.73it/s, loss=5.070e+01]
Image optimization: 62%|######1 | 308/500 [01:51<01:10, 2.73it/s, loss=5.056e+01]
Image optimization: 62%|######1 | 309/500 [01:51<01:10, 2.73it/s, loss=5.042e+01]
Image optimization: 62%|######2 | 310/500 [01:52<01:09, 2.73it/s, loss=5.025e+01]
Image optimization: 62%|######2 | 311/500 [01:52<01:09, 2.73it/s, loss=5.010e+01]
Image optimization: 62%|######2 | 312/500 [01:52<01:08, 2.73it/s, loss=5.000e+01]
Image optimization: 63%|######2 | 313/500 [01:53<01:08, 2.73it/s, loss=4.990e+01]
Image optimization: 63%|######2 | 314/500 [01:53<01:08, 2.73it/s, loss=4.980e+01]
Image optimization: 63%|######3 | 315/500 [01:54<01:07, 2.73it/s, loss=4.970e+01]
Image optimization: 63%|######3 | 316/500 [01:54<01:07, 2.73it/s, loss=4.956e+01]
Image optimization: 63%|######3 | 317/500 [01:54<01:06, 2.73it/s, loss=4.939e+01]
Image optimization: 64%|######3 | 318/500 [01:55<01:06, 2.74it/s, loss=4.925e+01]
Image optimization: 64%|######3 | 319/500 [01:55<01:06, 2.73it/s, loss=4.915e+01]
Image optimization: 64%|######4 | 320/500 [01:55<01:05, 2.73it/s, loss=4.904e+01]
Image optimization: 64%|######4 | 321/500 [01:56<01:05, 2.73it/s, loss=4.892e+01]
Image optimization: 64%|######4 | 322/500 [01:56<01:05, 2.73it/s, loss=4.880e+01]
Image optimization: 65%|######4 | 323/500 [01:57<01:04, 2.74it/s, loss=4.870e+01]
Image optimization: 65%|######4 | 324/500 [01:57<01:04, 2.73it/s, loss=4.860e+01]
Image optimization: 65%|######5 | 325/500 [01:57<01:04, 2.73it/s, loss=4.849e+01]
Image optimization: 65%|######5 | 326/500 [01:58<01:03, 2.73it/s, loss=4.838e+01]
Image optimization: 65%|######5 | 327/500 [01:58<01:03, 2.73it/s, loss=4.826e+01]
Image optimization: 66%|######5 | 328/500 [01:58<01:02, 2.73it/s, loss=4.816e+01]
Image optimization: 66%|######5 | 329/500 [01:59<01:02, 2.73it/s, loss=4.807e+01]
Image optimization: 66%|######6 | 330/500 [01:59<01:02, 2.73it/s, loss=4.792e+01]
Image optimization: 66%|######6 | 331/500 [01:59<01:01, 2.73it/s, loss=4.783e+01]
Image optimization: 66%|######6 | 332/500 [02:00<01:01, 2.74it/s, loss=4.775e+01]
Image optimization: 67%|######6 | 333/500 [02:00<01:01, 2.73it/s, loss=4.766e+01]
Image optimization: 67%|######6 | 334/500 [02:01<01:00, 2.73it/s, loss=4.761e+01]
Image optimization: 67%|######7 | 335/500 [02:01<01:00, 2.73it/s, loss=4.753e+01]
Image optimization: 67%|######7 | 336/500 [02:01<00:59, 2.73it/s, loss=4.741e+01]
Image optimization: 67%|######7 | 337/500 [02:02<00:59, 2.73it/s, loss=4.731e+01]
Image optimization: 68%|######7 | 338/500 [02:02<00:59, 2.74it/s, loss=4.721e+01]
Image optimization: 68%|######7 | 339/500 [02:02<00:58, 2.74it/s, loss=4.715e+01]
Image optimization: 68%|######8 | 340/500 [02:03<00:58, 2.73it/s, loss=4.703e+01]
Image optimization: 68%|######8 | 341/500 [02:03<00:58, 2.74it/s, loss=4.697e+01]
Image optimization: 68%|######8 | 342/500 [02:03<00:57, 2.73it/s, loss=4.689e+01]
Image optimization: 69%|######8 | 343/500 [02:04<00:57, 2.73it/s, loss=4.683e+01]
Image optimization: 69%|######8 | 344/500 [02:04<00:57, 2.73it/s, loss=4.678e+01]
Image optimization: 69%|######9 | 345/500 [02:05<00:56, 2.73it/s, loss=4.672e+01]
Image optimization: 69%|######9 | 346/500 [02:05<00:56, 2.73it/s, loss=4.662e+01]
Image optimization: 69%|######9 | 347/500 [02:05<00:55, 2.73it/s, loss=4.654e+01]
Image optimization: 70%|######9 | 348/500 [02:06<00:55, 2.73it/s, loss=4.645e+01]
Image optimization: 70%|######9 | 349/500 [02:06<00:55, 2.73it/s, loss=4.639e+01]
Image optimization: 70%|####### | 350/500 [02:06<00:54, 2.73it/s, loss=4.632e+01]
Image optimization: 70%|####### | 351/500 [02:07<00:54, 2.73it/s, loss=4.623e+01]
Image optimization: 70%|####### | 352/500 [02:07<00:54, 2.74it/s, loss=4.616e+01]
Image optimization: 71%|####### | 353/500 [02:07<00:53, 2.74it/s, loss=4.611e+01]
Image optimization: 71%|####### | 354/500 [02:08<00:53, 2.74it/s, loss=4.602e+01]
Image optimization: 71%|#######1 | 355/500 [02:08<00:53, 2.73it/s, loss=4.595e+01]
Image optimization: 71%|#######1 | 356/500 [02:09<00:52, 2.73it/s, loss=4.590e+01]
Image optimization: 71%|#######1 | 357/500 [02:09<00:52, 2.74it/s, loss=4.584e+01]
Image optimization: 72%|#######1 | 358/500 [02:09<00:51, 2.74it/s, loss=4.579e+01]
Image optimization: 72%|#######1 | 359/500 [02:10<00:51, 2.74it/s, loss=4.570e+01]
Image optimization: 72%|#######2 | 360/500 [02:10<00:51, 2.74it/s, loss=4.564e+01]
Image optimization: 72%|#######2 | 361/500 [02:10<00:50, 2.73it/s, loss=4.559e+01]
Image optimization: 72%|#######2 | 362/500 [02:11<00:50, 2.73it/s, loss=4.552e+01]
Image optimization: 73%|#######2 | 363/500 [02:11<00:50, 2.73it/s, loss=4.544e+01]
Image optimization: 73%|#######2 | 364/500 [02:12<00:49, 2.73it/s, loss=4.537e+01]
Image optimization: 73%|#######3 | 365/500 [02:12<00:49, 2.73it/s, loss=4.532e+01]
Image optimization: 73%|#######3 | 366/500 [02:12<00:49, 2.73it/s, loss=4.525e+01]
Image optimization: 73%|#######3 | 367/500 [02:13<00:48, 2.74it/s, loss=4.519e+01]
Image optimization: 74%|#######3 | 368/500 [02:13<00:48, 2.74it/s, loss=4.514e+01]
Image optimization: 74%|#######3 | 369/500 [02:13<00:47, 2.73it/s, loss=4.507e+01]
Image optimization: 74%|#######4 | 370/500 [02:14<00:47, 2.73it/s, loss=4.502e+01]
Image optimization: 74%|#######4 | 371/500 [02:14<00:47, 2.73it/s, loss=4.497e+01]
Image optimization: 74%|#######4 | 372/500 [02:14<00:46, 2.73it/s, loss=4.489e+01]
Image optimization: 75%|#######4 | 373/500 [02:15<00:46, 2.74it/s, loss=4.484e+01]
Image optimization: 75%|#######4 | 374/500 [02:15<00:46, 2.74it/s, loss=4.480e+01]
Image optimization: 75%|#######5 | 375/500 [02:16<00:45, 2.74it/s, loss=4.475e+01]
Image optimization: 75%|#######5 | 376/500 [02:16<00:45, 2.74it/s, loss=4.471e+01]
Image optimization: 75%|#######5 | 377/500 [02:16<00:45, 2.73it/s, loss=4.466e+01]
Image optimization: 76%|#######5 | 378/500 [02:17<00:44, 2.73it/s, loss=4.459e+01]
Image optimization: 76%|#######5 | 379/500 [02:17<00:44, 2.73it/s, loss=4.453e+01]
Image optimization: 76%|#######6 | 380/500 [02:17<00:43, 2.73it/s, loss=4.447e+01]
Image optimization: 76%|#######6 | 381/500 [02:18<00:43, 2.74it/s, loss=4.442e+01]
Image optimization: 76%|#######6 | 382/500 [02:18<00:43, 2.73it/s, loss=4.435e+01]
Image optimization: 77%|#######6 | 383/500 [02:18<00:42, 2.73it/s, loss=4.430e+01]
Image optimization: 77%|#######6 | 384/500 [02:19<00:42, 2.73it/s, loss=4.426e+01]
Image optimization: 77%|#######7 | 385/500 [02:19<00:42, 2.73it/s, loss=4.419e+01]
Image optimization: 77%|#######7 | 386/500 [02:20<00:41, 2.73it/s, loss=4.415e+01]
Image optimization: 77%|#######7 | 387/500 [02:20<00:41, 2.74it/s, loss=4.411e+01]
Image optimization: 78%|#######7 | 388/500 [02:20<00:40, 2.74it/s, loss=4.405e+01]
Image optimization: 78%|#######7 | 389/500 [02:21<00:40, 2.74it/s, loss=4.401e+01]
Image optimization: 78%|#######8 | 390/500 [02:21<00:40, 2.74it/s, loss=4.396e+01]
Image optimization: 78%|#######8 | 391/500 [02:21<00:39, 2.74it/s, loss=4.389e+01]
Image optimization: 78%|#######8 | 392/500 [02:22<00:39, 2.73it/s, loss=4.384e+01]
Image optimization: 79%|#######8 | 393/500 [02:22<00:39, 2.73it/s, loss=4.380e+01]
Image optimization: 79%|#######8 | 394/500 [02:22<00:38, 2.74it/s, loss=4.375e+01]
Image optimization: 79%|#######9 | 395/500 [02:23<00:38, 2.73it/s, loss=4.371e+01]
Image optimization: 79%|#######9 | 396/500 [02:23<00:38, 2.73it/s, loss=4.365e+01]
Image optimization: 79%|#######9 | 397/500 [02:24<00:37, 2.73it/s, loss=4.359e+01]
Image optimization: 80%|#######9 | 398/500 [02:24<00:37, 2.73it/s, loss=4.353e+01]
Image optimization: 80%|#######9 | 399/500 [02:24<00:36, 2.73it/s, loss=4.348e+01]
Image optimization: 80%|######## | 400/500 [02:25<00:36, 2.74it/s, loss=4.343e+01]
Image optimization: 80%|######## | 401/500 [02:25<00:36, 2.73it/s, loss=4.337e+01]
Image optimization: 80%|######## | 402/500 [02:25<00:35, 2.74it/s, loss=4.332e+01]
Image optimization: 81%|######## | 403/500 [02:26<00:35, 2.73it/s, loss=4.327e+01]
Image optimization: 81%|######## | 404/500 [02:26<00:35, 2.74it/s, loss=4.321e+01]
Image optimization: 81%|########1 | 405/500 [02:26<00:34, 2.74it/s, loss=4.316e+01]
Image optimization: 81%|########1 | 406/500 [02:27<00:34, 2.73it/s, loss=4.311e+01]
Image optimization: 81%|########1 | 407/500 [02:27<00:34, 2.74it/s, loss=4.307e+01]
Image optimization: 82%|########1 | 408/500 [02:28<00:33, 2.74it/s, loss=4.303e+01]
Image optimization: 82%|########1 | 409/500 [02:28<00:33, 2.73it/s, loss=4.299e+01]
Image optimization: 82%|########2 | 410/500 [02:28<00:32, 2.73it/s, loss=4.294e+01]
Image optimization: 82%|########2 | 411/500 [02:29<00:32, 2.73it/s, loss=4.290e+01]
Image optimization: 82%|########2 | 412/500 [02:29<00:32, 2.73it/s, loss=4.283e+01]
Image optimization: 83%|########2 | 413/500 [02:29<00:31, 2.73it/s, loss=4.278e+01]
Image optimization: 83%|########2 | 414/500 [02:30<00:31, 2.73it/s, loss=4.273e+01]
Image optimization: 83%|########2 | 415/500 [02:30<00:31, 2.73it/s, loss=4.268e+01]
Image optimization: 83%|########3 | 416/500 [02:31<00:30, 2.74it/s, loss=4.263e+01]
Image optimization: 83%|########3 | 417/500 [02:31<00:30, 2.74it/s, loss=4.258e+01]
Image optimization: 84%|########3 | 418/500 [02:31<00:30, 2.73it/s, loss=4.253e+01]
Image optimization: 84%|########3 | 419/500 [02:32<00:29, 2.73it/s, loss=4.248e+01]
Image optimization: 84%|########4 | 420/500 [02:32<00:29, 2.73it/s, loss=4.243e+01]
Image optimization: 84%|########4 | 421/500 [02:32<00:28, 2.73it/s, loss=4.238e+01]
Image optimization: 84%|########4 | 422/500 [02:33<00:28, 2.73it/s, loss=4.232e+01]
Image optimization: 85%|########4 | 423/500 [02:33<00:28, 2.73it/s, loss=4.228e+01]
Image optimization: 85%|########4 | 424/500 [02:33<00:27, 2.73it/s, loss=4.222e+01]
Image optimization: 85%|########5 | 425/500 [02:34<00:27, 2.73it/s, loss=4.217e+01]
Image optimization: 85%|########5 | 426/500 [02:34<00:27, 2.73it/s, loss=4.213e+01]
Image optimization: 85%|########5 | 427/500 [02:35<00:26, 2.74it/s, loss=4.208e+01]
Image optimization: 86%|########5 | 428/500 [02:35<00:26, 2.73it/s, loss=4.204e+01]
Image optimization: 86%|########5 | 429/500 [02:35<00:25, 2.73it/s, loss=4.198e+01]
Image optimization: 86%|########6 | 430/500 [02:36<00:25, 2.74it/s, loss=4.192e+01]
Image optimization: 86%|########6 | 431/500 [02:36<00:25, 2.73it/s, loss=4.187e+01]
Image optimization: 86%|########6 | 432/500 [02:36<00:24, 2.73it/s, loss=4.183e+01]
Image optimization: 87%|########6 | 433/500 [02:37<00:24, 2.73it/s, loss=4.177e+01]
Image optimization: 87%|########6 | 434/500 [02:37<00:24, 2.73it/s, loss=4.171e+01]
Image optimization: 87%|########7 | 435/500 [02:37<00:23, 2.73it/s, loss=4.166e+01]
Image optimization: 87%|########7 | 436/500 [02:38<00:23, 2.73it/s, loss=4.162e+01]
Image optimization: 87%|########7 | 437/500 [02:38<00:23, 2.73it/s, loss=4.157e+01]
Image optimization: 88%|########7 | 438/500 [02:39<00:22, 2.74it/s, loss=4.151e+01]
Image optimization: 88%|########7 | 439/500 [02:39<00:22, 2.73it/s, loss=4.147e+01]
Image optimization: 88%|########8 | 440/500 [02:39<00:21, 2.73it/s, loss=4.142e+01]
Image optimization: 88%|########8 | 441/500 [02:40<00:21, 2.73it/s, loss=4.137e+01]
Image optimization: 88%|########8 | 442/500 [02:40<00:21, 2.73it/s, loss=4.132e+01]
Image optimization: 89%|########8 | 443/500 [02:40<00:20, 2.73it/s, loss=4.126e+01]
Image optimization: 89%|########8 | 444/500 [02:41<00:20, 2.73it/s, loss=4.121e+01]
Image optimization: 89%|########9 | 445/500 [02:41<00:20, 2.73it/s, loss=4.117e+01]
Image optimization: 89%|########9 | 446/500 [02:41<00:19, 2.74it/s, loss=4.111e+01]
Image optimization: 89%|########9 | 447/500 [02:42<00:19, 2.74it/s, loss=4.107e+01]
Image optimization: 90%|########9 | 448/500 [02:42<00:19, 2.73it/s, loss=4.102e+01]
Image optimization: 90%|########9 | 449/500 [02:43<00:18, 2.74it/s, loss=4.097e+01]
Image optimization: 90%|######### | 450/500 [02:43<00:18, 2.74it/s, loss=4.094e+01]
Image optimization: 90%|######### | 451/500 [02:43<00:17, 2.74it/s, loss=4.089e+01]
Image optimization: 90%|######### | 452/500 [02:44<00:17, 2.74it/s, loss=4.084e+01]
Image optimization: 91%|######### | 453/500 [02:44<00:17, 2.74it/s, loss=4.079e+01]
Image optimization: 91%|######### | 454/500 [02:44<00:16, 2.73it/s, loss=4.072e+01]
Image optimization: 91%|#########1| 455/500 [02:45<00:16, 2.73it/s, loss=4.068e+01]
Image optimization: 91%|#########1| 456/500 [02:45<00:16, 2.74it/s, loss=4.063e+01]
Image optimization: 91%|#########1| 457/500 [02:46<00:15, 2.73it/s, loss=4.060e+01]
Image optimization: 92%|#########1| 458/500 [02:46<00:15, 2.73it/s, loss=4.056e+01]
Image optimization: 92%|#########1| 459/500 [02:46<00:14, 2.74it/s, loss=4.050e+01]
Image optimization: 92%|#########2| 460/500 [02:47<00:14, 2.73it/s, loss=4.044e+01]
Image optimization: 92%|#########2| 461/500 [02:47<00:14, 2.73it/s, loss=4.040e+01]
Image optimization: 92%|#########2| 462/500 [02:47<00:13, 2.73it/s, loss=4.035e+01]
Image optimization: 93%|#########2| 463/500 [02:48<00:13, 2.73it/s, loss=4.030e+01]
Image optimization: 93%|#########2| 464/500 [02:48<00:13, 2.73it/s, loss=4.025e+01]
Image optimization: 93%|#########3| 465/500 [02:48<00:12, 2.73it/s, loss=4.020e+01]
Image optimization: 93%|#########3| 466/500 [02:49<00:12, 2.73it/s, loss=4.016e+01]
Image optimization: 93%|#########3| 467/500 [02:49<00:12, 2.73it/s, loss=4.010e+01]
Image optimization: 94%|#########3| 468/500 [02:50<00:11, 2.74it/s, loss=4.005e+01]
Image optimization: 94%|#########3| 469/500 [02:50<00:11, 2.74it/s, loss=4.001e+01]
Image optimization: 94%|#########3| 470/500 [02:50<00:10, 2.74it/s, loss=3.997e+01]
Image optimization: 94%|#########4| 471/500 [02:51<00:10, 2.75it/s, loss=3.991e+01]
Image optimization: 94%|#########4| 472/500 [02:51<00:10, 2.75it/s, loss=3.984e+01]
Image optimization: 95%|#########4| 473/500 [02:51<00:09, 2.75it/s, loss=3.980e+01]
Image optimization: 95%|#########4| 474/500 [02:52<00:09, 2.74it/s, loss=3.976e+01]
Image optimization: 95%|#########5| 475/500 [02:52<00:09, 2.75it/s, loss=3.970e+01]
Image optimization: 95%|#########5| 476/500 [02:52<00:08, 2.75it/s, loss=3.964e+01]
Image optimization: 95%|#########5| 477/500 [02:53<00:08, 2.75it/s, loss=3.959e+01]
Image optimization: 96%|#########5| 478/500 [02:53<00:07, 2.75it/s, loss=3.955e+01]
Image optimization: 96%|#########5| 479/500 [02:54<00:07, 2.75it/s, loss=3.949e+01]
Image optimization: 96%|#########6| 480/500 [02:54<00:07, 2.75it/s, loss=3.944e+01]
Image optimization: 96%|#########6| 481/500 [02:54<00:06, 2.75it/s, loss=3.940e+01]
Image optimization: 96%|#########6| 482/500 [02:55<00:06, 2.75it/s, loss=3.936e+01]
Image optimization: 97%|#########6| 483/500 [02:55<00:06, 2.75it/s, loss=3.932e+01]
Image optimization: 97%|#########6| 484/500 [02:55<00:05, 2.76it/s, loss=3.925e+01]
Image optimization: 97%|#########7| 485/500 [02:56<00:05, 2.76it/s, loss=3.920e+01]
Image optimization: 97%|#########7| 486/500 [02:56<00:05, 2.75it/s, loss=3.915e+01]
Image optimization: 97%|#########7| 487/500 [02:56<00:04, 2.75it/s, loss=3.911e+01]
Image optimization: 98%|#########7| 488/500 [02:57<00:04, 2.75it/s, loss=3.907e+01]
Image optimization: 98%|#########7| 489/500 [02:57<00:03, 2.75it/s, loss=3.902e+01]
Image optimization: 98%|#########8| 490/500 [02:58<00:03, 2.75it/s, loss=3.897e+01]
Image optimization: 98%|#########8| 491/500 [02:58<00:03, 2.76it/s, loss=3.893e+01]
Image optimization: 98%|#########8| 492/500 [02:58<00:02, 2.76it/s, loss=3.889e+01]
Image optimization: 99%|#########8| 493/500 [02:59<00:02, 2.76it/s, loss=3.884e+01]
Image optimization: 99%|#########8| 494/500 [02:59<00:02, 2.76it/s, loss=3.879e+01]
Image optimization: 99%|#########9| 495/500 [02:59<00:01, 2.76it/s, loss=3.873e+01]
Image optimization: 99%|#########9| 496/500 [03:00<00:01, 2.76it/s, loss=3.869e+01]
Image optimization: 99%|#########9| 497/500 [03:00<00:01, 2.76it/s, loss=3.863e+01]
Image optimization: 100%|#########9| 498/500 [03:00<00:00, 2.76it/s, loss=3.858e+01]
Image optimization: 100%|#########9| 499/500 [03:01<00:00, 2.76it/s, loss=3.852e+01]
Image optimization: 100%|##########| 500/500 [03:01<00:00, 2.76it/s, loss=3.847e+01]
Image optimization: 100%|##########| 500/500 [03:01<00:00, 2.75it/s, loss=3.847e+01]
259 show_image(output_image)
Compared to the two previous results we now achieved the highest quality. Nevertheless, This approach has its downsides : since we are working with multiple images in multiple distinct regions, the memory requirement is higher compared to the other approaches. Furthermore, compared to the unguided NST, the guides have to be provided together with the for the content and style images.
Total running time of the script: ( 8 minutes 31.918 seconds)
Estimated memory usage: 3199 MB
Note
Click here to download the full example code
Image optimization with pyramid¶
This example showcases how an
image pyramid is
integrated in an NST with pystiche
.
With an image pyramid the optimization is not performed on a single but rather on multiple increasing resolutions. This procedure is often dubbed coarse-to-fine, since on the lower resolutions coarse structures are synthesized whereas on the higher levels the details are carved out.
This technique has the potential to reduce the convergence time as well as to enhance the overall result [GEB+17, LW16].
We start this example by importing everything we need and setting the device we will be working on.
23 import time
24
25 import pystiche
26 from pystiche import demo, enc, loss, optim, pyramid
27 from pystiche.image import show_image
28 from pystiche.misc import get_device, get_input_image
29
30 print(f"I'm working with pystiche=={pystiche.__version__}")
31
32 device = get_device()
33 print(f"I'm working with {device}")
Out:
I'm working with pystiche==1.1.0.dev44+gd9e3fd8
I'm working with cuda
At first we define a PerceptualLoss
that is used as
optimization criterion.
40 multi_layer_encoder = enc.vgg19_multi_layer_encoder()
41
42
43 content_layer = "relu4_2"
44 content_encoder = multi_layer_encoder.extract_encoder(content_layer)
45 content_weight = 1e0
46 content_loss = loss.FeatureReconstructionLoss(
47 content_encoder, score_weight=content_weight
48 )
49
50
51 style_layers = ("relu3_1", "relu4_1")
52 style_weight = 2e0
53
54
55 def get_style_op(encoder, layer_weight):
56 return loss.MRFLoss(encoder, patch_size=3, stride=2, score_weight=layer_weight)
57
58
59 style_loss = loss.MultiLayerEncodingLoss(
60 multi_layer_encoder, style_layers, get_style_op, score_weight=style_weight,
61 )
62
63 perceptual_loss = loss.PerceptualLoss(content_loss, style_loss).to(device)
64 print(perceptual_loss)
Out:
PerceptualLoss(
(content_loss): FeatureReconstructionLoss(
(encoder): VGGMultiLayerEncoder(layer=relu4_2, arch=vgg19, framework=torch)
)
(style_loss): MultiLayerEncodingLoss(
encoder=VGGMultiLayerEncoder(arch=vgg19, framework=torch), score_weight=2
(relu3_1): MRFLoss(score_weight=0.5, patch_size=(3, 3), stride=(2, 2))
(relu4_1): MRFLoss(score_weight=0.5, patch_size=(3, 3), stride=(2, 2))
)
)
Next up, we load and show the images that will be used in the NST.
70 images = demo.images()
71 images.download()
72 size = 500
77 content_image = images["bird2"].read(size=size, device=device)
78 show_image(content_image, title="Content image")
79 perceptual_loss.set_content_image(content_image)
84 style_image = images["mosaic"].read(size=size, device=device)
85 show_image(style_image, title="Style image")
86 perceptual_loss.set_style_image(style_image)
Image optimization without pyramid¶
As a baseline we use a standard image optimization without pyramid.
95 starting_point = "content"
96 input_image = get_input_image(starting_point, content_image=content_image)
97 show_image(input_image, title="Input image")
We time the NST performed by image_optimization()
and show the
result.
104 start_without_pyramid = time.time()
105 output_image = optim.image_optimization(input_image, perceptual_loss, num_steps=400)
106 stop_without_pyramid = time.time()
107
108 show_image(output_image, title="Output image without pyramid")
Out:
Image optimization: 0%| | 0/400 [00:00<?, ?it/s]
Image optimization: 0%| | 1/400 [00:00<01:20, 4.97it/s, loss=3.889e+01]
Image optimization: 0%| | 2/400 [00:00<01:11, 5.58it/s, loss=3.889e+01]
Image optimization: 1%| | 3/400 [00:00<01:07, 5.85it/s, loss=3.842e+01]
Image optimization: 1%|1 | 4/400 [00:00<01:06, 5.95it/s, loss=3.754e+01]
Image optimization: 1%|1 | 5/400 [00:00<01:06, 5.97it/s, loss=3.671e+01]
Image optimization: 2%|1 | 6/400 [00:01<01:05, 6.04it/s, loss=3.574e+01]
Image optimization: 2%|1 | 7/400 [00:01<01:06, 5.93it/s, loss=3.474e+01]
Image optimization: 2%|2 | 8/400 [00:01<01:05, 5.95it/s, loss=3.382e+01]
Image optimization: 2%|2 | 9/400 [00:01<01:05, 5.98it/s, loss=3.304e+01]
Image optimization: 2%|2 | 10/400 [00:01<01:04, 6.02it/s, loss=3.216e+01]
Image optimization: 3%|2 | 11/400 [00:01<01:04, 6.04it/s, loss=3.149e+01]
Image optimization: 3%|3 | 12/400 [00:02<01:03, 6.07it/s, loss=3.091e+01]
Image optimization: 3%|3 | 13/400 [00:02<01:04, 5.98it/s, loss=3.039e+01]
Image optimization: 4%|3 | 14/400 [00:02<01:05, 5.92it/s, loss=2.993e+01]
Image optimization: 4%|3 | 15/400 [00:02<01:04, 5.97it/s, loss=2.952e+01]
Image optimization: 4%|4 | 16/400 [00:02<01:04, 5.99it/s, loss=2.915e+01]
Image optimization: 4%|4 | 17/400 [00:02<01:03, 6.02it/s, loss=2.881e+01]
Image optimization: 4%|4 | 18/400 [00:03<01:03, 6.04it/s, loss=2.850e+01]
Image optimization: 5%|4 | 19/400 [00:03<01:03, 6.01it/s, loss=2.822e+01]
Image optimization: 5%|5 | 20/400 [00:03<01:04, 5.89it/s, loss=2.798e+01]
Image optimization: 5%|5 | 21/400 [00:03<01:04, 5.87it/s, loss=2.775e+01]
Image optimization: 6%|5 | 22/400 [00:03<01:03, 5.91it/s, loss=2.754e+01]
Image optimization: 6%|5 | 23/400 [00:03<01:03, 5.94it/s, loss=2.735e+01]
Image optimization: 6%|6 | 24/400 [00:04<01:02, 5.98it/s, loss=2.718e+01]
Image optimization: 6%|6 | 25/400 [00:04<01:03, 5.94it/s, loss=2.704e+01]
Image optimization: 6%|6 | 26/400 [00:04<01:03, 5.85it/s, loss=2.690e+01]
Image optimization: 7%|6 | 27/400 [00:04<01:04, 5.82it/s, loss=2.675e+01]
Image optimization: 7%|7 | 28/400 [00:04<01:03, 5.86it/s, loss=2.663e+01]
Image optimization: 7%|7 | 29/400 [00:04<01:03, 5.89it/s, loss=2.651e+01]
Image optimization: 8%|7 | 30/400 [00:05<01:03, 5.85it/s, loss=2.639e+01]
Image optimization: 8%|7 | 31/400 [00:05<01:02, 5.88it/s, loss=2.629e+01]
Image optimization: 8%|8 | 32/400 [00:05<01:02, 5.88it/s, loss=2.619e+01]
Image optimization: 8%|8 | 33/400 [00:05<01:03, 5.82it/s, loss=2.610e+01]
Image optimization: 8%|8 | 34/400 [00:05<01:02, 5.84it/s, loss=2.602e+01]
Image optimization: 9%|8 | 35/400 [00:05<01:02, 5.81it/s, loss=2.594e+01]
Image optimization: 9%|9 | 36/400 [00:06<01:02, 5.85it/s, loss=2.586e+01]
Image optimization: 9%|9 | 37/400 [00:06<01:02, 5.82it/s, loss=2.579e+01]
Image optimization: 10%|9 | 38/400 [00:06<01:02, 5.82it/s, loss=2.572e+01]
Image optimization: 10%|9 | 39/400 [00:06<01:02, 5.78it/s, loss=2.566e+01]
Image optimization: 10%|# | 40/400 [00:06<01:01, 5.82it/s, loss=2.559e+01]
Image optimization: 10%|# | 41/400 [00:06<01:02, 5.78it/s, loss=2.553e+01]
Image optimization: 10%|# | 42/400 [00:07<01:01, 5.82it/s, loss=2.547e+01]
Image optimization: 11%|# | 43/400 [00:07<01:01, 5.79it/s, loss=2.542e+01]
Image optimization: 11%|#1 | 44/400 [00:07<01:01, 5.79it/s, loss=2.536e+01]
Image optimization: 11%|#1 | 45/400 [00:07<01:01, 5.74it/s, loss=2.531e+01]
Image optimization: 12%|#1 | 46/400 [00:07<01:01, 5.76it/s, loss=2.526e+01]
Image optimization: 12%|#1 | 47/400 [00:08<01:01, 5.73it/s, loss=2.522e+01]
Image optimization: 12%|#2 | 48/400 [00:08<01:01, 5.74it/s, loss=2.518e+01]
Image optimization: 12%|#2 | 49/400 [00:08<01:01, 5.75it/s, loss=2.514e+01]
Image optimization: 12%|#2 | 50/400 [00:08<01:01, 5.71it/s, loss=2.509e+01]
Image optimization: 13%|#2 | 51/400 [00:08<01:01, 5.71it/s, loss=2.506e+01]
Image optimization: 13%|#3 | 52/400 [00:08<01:00, 5.74it/s, loss=2.502e+01]
Image optimization: 13%|#3 | 53/400 [00:09<01:00, 5.72it/s, loss=2.499e+01]
Image optimization: 14%|#3 | 54/400 [00:09<01:00, 5.75it/s, loss=2.496e+01]
Image optimization: 14%|#3 | 55/400 [00:09<01:00, 5.74it/s, loss=2.492e+01]
Image optimization: 14%|#4 | 56/400 [00:09<01:00, 5.72it/s, loss=2.489e+01]
Image optimization: 14%|#4 | 57/400 [00:09<00:59, 5.72it/s, loss=2.486e+01]
Image optimization: 14%|#4 | 58/400 [00:09<01:00, 5.68it/s, loss=2.483e+01]
Image optimization: 15%|#4 | 59/400 [00:10<00:59, 5.69it/s, loss=2.480e+01]
Image optimization: 15%|#5 | 60/400 [00:10<00:59, 5.69it/s, loss=2.477e+01]
Image optimization: 15%|#5 | 61/400 [00:10<00:59, 5.67it/s, loss=2.475e+01]
Image optimization: 16%|#5 | 62/400 [00:10<00:59, 5.66it/s, loss=2.472e+01]
Image optimization: 16%|#5 | 63/400 [00:10<00:59, 5.68it/s, loss=2.469e+01]
Image optimization: 16%|#6 | 64/400 [00:10<00:59, 5.64it/s, loss=2.467e+01]
Image optimization: 16%|#6 | 65/400 [00:11<00:59, 5.65it/s, loss=2.465e+01]
Image optimization: 16%|#6 | 66/400 [00:11<00:58, 5.67it/s, loss=2.462e+01]
Image optimization: 17%|#6 | 67/400 [00:11<00:59, 5.64it/s, loss=2.460e+01]
Image optimization: 17%|#7 | 68/400 [00:11<00:59, 5.62it/s, loss=2.457e+01]
Image optimization: 17%|#7 | 69/400 [00:11<00:59, 5.58it/s, loss=2.456e+01]
Image optimization: 18%|#7 | 70/400 [00:12<00:59, 5.57it/s, loss=2.454e+01]
Image optimization: 18%|#7 | 71/400 [00:12<00:58, 5.60it/s, loss=2.452e+01]
Image optimization: 18%|#8 | 72/400 [00:12<00:58, 5.62it/s, loss=2.450e+01]
Image optimization: 18%|#8 | 73/400 [00:12<00:58, 5.59it/s, loss=2.448e+01]
Image optimization: 18%|#8 | 74/400 [00:12<00:58, 5.56it/s, loss=2.446e+01]
Image optimization: 19%|#8 | 75/400 [00:12<00:58, 5.56it/s, loss=2.444e+01]
Image optimization: 19%|#9 | 76/400 [00:13<00:58, 5.54it/s, loss=2.442e+01]
Image optimization: 19%|#9 | 77/400 [00:13<00:58, 5.53it/s, loss=2.440e+01]
Image optimization: 20%|#9 | 78/400 [00:13<00:58, 5.55it/s, loss=2.439e+01]
Image optimization: 20%|#9 | 79/400 [00:13<00:57, 5.56it/s, loss=2.438e+01]
Image optimization: 20%|## | 80/400 [00:13<00:57, 5.54it/s, loss=2.436e+01]
Image optimization: 20%|## | 81/400 [00:14<00:57, 5.52it/s, loss=2.434e+01]
Image optimization: 20%|## | 82/400 [00:14<00:57, 5.50it/s, loss=2.433e+01]
Image optimization: 21%|## | 83/400 [00:14<00:57, 5.50it/s, loss=2.431e+01]
Image optimization: 21%|##1 | 84/400 [00:14<00:57, 5.48it/s, loss=2.430e+01]
Image optimization: 21%|##1 | 85/400 [00:14<00:57, 5.47it/s, loss=2.429e+01]
Image optimization: 22%|##1 | 86/400 [00:14<00:57, 5.47it/s, loss=2.427e+01]
Image optimization: 22%|##1 | 87/400 [00:15<00:57, 5.46it/s, loss=2.426e+01]
Image optimization: 22%|##2 | 88/400 [00:15<00:57, 5.47it/s, loss=2.424e+01]
Image optimization: 22%|##2 | 89/400 [00:15<00:56, 5.47it/s, loss=2.423e+01]
Image optimization: 22%|##2 | 90/400 [00:15<00:56, 5.46it/s, loss=2.422e+01]
Image optimization: 23%|##2 | 91/400 [00:15<00:56, 5.46it/s, loss=2.420e+01]
Image optimization: 23%|##3 | 92/400 [00:16<00:56, 5.47it/s, loss=2.419e+01]
Image optimization: 23%|##3 | 93/400 [00:16<00:56, 5.48it/s, loss=2.418e+01]
Image optimization: 24%|##3 | 94/400 [00:16<00:56, 5.45it/s, loss=2.416e+01]
Image optimization: 24%|##3 | 95/400 [00:16<00:55, 5.47it/s, loss=2.415e+01]
Image optimization: 24%|##4 | 96/400 [00:16<00:55, 5.47it/s, loss=2.414e+01]
Image optimization: 24%|##4 | 97/400 [00:16<00:55, 5.46it/s, loss=2.413e+01]
Image optimization: 24%|##4 | 98/400 [00:17<00:55, 5.47it/s, loss=2.412e+01]
Image optimization: 25%|##4 | 99/400 [00:17<00:55, 5.46it/s, loss=2.411e+01]
Image optimization: 25%|##5 | 100/400 [00:17<00:54, 5.47it/s, loss=2.410e+01]
Image optimization: 25%|##5 | 101/400 [00:17<00:54, 5.45it/s, loss=2.409e+01]
Image optimization: 26%|##5 | 102/400 [00:17<00:54, 5.45it/s, loss=2.408e+01]
Image optimization: 26%|##5 | 103/400 [00:18<00:54, 5.44it/s, loss=2.407e+01]
Image optimization: 26%|##6 | 104/400 [00:18<00:54, 5.40it/s, loss=2.406e+01]
Image optimization: 26%|##6 | 105/400 [00:18<00:54, 5.37it/s, loss=2.405e+01]
Image optimization: 26%|##6 | 106/400 [00:18<00:54, 5.36it/s, loss=2.404e+01]
Image optimization: 27%|##6 | 107/400 [00:18<00:54, 5.40it/s, loss=2.403e+01]
Image optimization: 27%|##7 | 108/400 [00:19<00:54, 5.40it/s, loss=2.402e+01]
Image optimization: 27%|##7 | 109/400 [00:19<00:53, 5.41it/s, loss=2.401e+01]
Image optimization: 28%|##7 | 110/400 [00:19<00:53, 5.42it/s, loss=2.400e+01]
Image optimization: 28%|##7 | 111/400 [00:19<00:53, 5.42it/s, loss=2.399e+01]
Image optimization: 28%|##8 | 112/400 [00:19<00:53, 5.40it/s, loss=2.398e+01]
Image optimization: 28%|##8 | 113/400 [00:19<00:53, 5.39it/s, loss=2.397e+01]
Image optimization: 28%|##8 | 114/400 [00:20<00:53, 5.38it/s, loss=2.396e+01]
Image optimization: 29%|##8 | 115/400 [00:20<00:53, 5.36it/s, loss=2.396e+01]
Image optimization: 29%|##9 | 116/400 [00:20<00:52, 5.38it/s, loss=2.395e+01]
Image optimization: 29%|##9 | 117/400 [00:20<00:52, 5.40it/s, loss=2.394e+01]
Image optimization: 30%|##9 | 118/400 [00:20<00:52, 5.42it/s, loss=2.393e+01]
Image optimization: 30%|##9 | 119/400 [00:21<00:51, 5.42it/s, loss=2.393e+01]
Image optimization: 30%|### | 120/400 [00:21<00:51, 5.42it/s, loss=2.392e+01]
Image optimization: 30%|### | 121/400 [00:21<00:51, 5.42it/s, loss=2.391e+01]
Image optimization: 30%|### | 122/400 [00:21<00:51, 5.39it/s, loss=2.390e+01]
Image optimization: 31%|### | 123/400 [00:21<00:51, 5.35it/s, loss=2.390e+01]
Image optimization: 31%|###1 | 124/400 [00:21<00:51, 5.35it/s, loss=2.389e+01]
Image optimization: 31%|###1 | 125/400 [00:22<00:51, 5.39it/s, loss=2.388e+01]
Image optimization: 32%|###1 | 126/400 [00:22<00:50, 5.41it/s, loss=2.387e+01]
Image optimization: 32%|###1 | 127/400 [00:22<00:50, 5.42it/s, loss=2.387e+01]
Image optimization: 32%|###2 | 128/400 [00:22<00:50, 5.42it/s, loss=2.386e+01]
Image optimization: 32%|###2 | 129/400 [00:22<00:50, 5.38it/s, loss=2.385e+01]
Image optimization: 32%|###2 | 130/400 [00:23<00:50, 5.33it/s, loss=2.384e+01]
Image optimization: 33%|###2 | 131/400 [00:23<00:50, 5.36it/s, loss=2.384e+01]
Image optimization: 33%|###3 | 132/400 [00:23<00:49, 5.38it/s, loss=2.383e+01]
Image optimization: 33%|###3 | 133/400 [00:23<00:49, 5.38it/s, loss=2.383e+01]
Image optimization: 34%|###3 | 134/400 [00:23<00:49, 5.38it/s, loss=2.382e+01]
Image optimization: 34%|###3 | 135/400 [00:24<00:49, 5.34it/s, loss=2.381e+01]
Image optimization: 34%|###4 | 136/400 [00:24<00:49, 5.34it/s, loss=2.381e+01]
Image optimization: 34%|###4 | 137/400 [00:24<00:49, 5.37it/s, loss=2.380e+01]
Image optimization: 34%|###4 | 138/400 [00:24<00:48, 5.39it/s, loss=2.379e+01]
Image optimization: 35%|###4 | 139/400 [00:24<00:48, 5.38it/s, loss=2.379e+01]
Image optimization: 35%|###5 | 140/400 [00:24<00:48, 5.35it/s, loss=2.379e+01]
Image optimization: 35%|###5 | 141/400 [00:25<00:48, 5.31it/s, loss=2.378e+01]
Image optimization: 36%|###5 | 142/400 [00:25<00:48, 5.34it/s, loss=2.378e+01]
Image optimization: 36%|###5 | 143/400 [00:25<00:47, 5.37it/s, loss=2.377e+01]
Image optimization: 36%|###6 | 144/400 [00:25<00:47, 5.39it/s, loss=2.377e+01]
Image optimization: 36%|###6 | 145/400 [00:25<00:47, 5.38it/s, loss=2.376e+01]
Image optimization: 36%|###6 | 146/400 [00:26<00:47, 5.36it/s, loss=2.376e+01]
Image optimization: 37%|###6 | 147/400 [00:26<00:47, 5.32it/s, loss=2.375e+01]
Image optimization: 37%|###7 | 148/400 [00:26<00:47, 5.35it/s, loss=2.374e+01]
Image optimization: 37%|###7 | 149/400 [00:26<00:46, 5.38it/s, loss=2.374e+01]
Image optimization: 38%|###7 | 150/400 [00:26<00:46, 5.39it/s, loss=2.373e+01]
Image optimization: 38%|###7 | 151/400 [00:27<00:46, 5.35it/s, loss=2.373e+01]
Image optimization: 38%|###8 | 152/400 [00:27<00:46, 5.31it/s, loss=2.372e+01]
Image optimization: 38%|###8 | 153/400 [00:27<00:46, 5.34it/s, loss=2.372e+01]
Image optimization: 38%|###8 | 154/400 [00:27<00:45, 5.37it/s, loss=2.371e+01]
Image optimization: 39%|###8 | 155/400 [00:27<00:45, 5.35it/s, loss=2.371e+01]
Image optimization: 39%|###9 | 156/400 [00:27<00:45, 5.33it/s, loss=2.370e+01]
Image optimization: 39%|###9 | 157/400 [00:28<00:45, 5.30it/s, loss=2.370e+01]
Image optimization: 40%|###9 | 158/400 [00:28<00:45, 5.31it/s, loss=2.369e+01]
Image optimization: 40%|###9 | 159/400 [00:28<00:45, 5.29it/s, loss=2.369e+01]
Image optimization: 40%|#### | 160/400 [00:28<00:45, 5.29it/s, loss=2.368e+01]
Image optimization: 40%|#### | 161/400 [00:28<00:44, 5.32it/s, loss=2.368e+01]
Image optimization: 40%|#### | 162/400 [00:29<00:44, 5.30it/s, loss=2.367e+01]
Image optimization: 41%|#### | 163/400 [00:29<00:44, 5.28it/s, loss=2.367e+01]
Image optimization: 41%|####1 | 164/400 [00:29<00:44, 5.31it/s, loss=2.366e+01]
Image optimization: 41%|####1 | 165/400 [00:29<00:44, 5.31it/s, loss=2.366e+01]
Image optimization: 42%|####1 | 166/400 [00:29<00:44, 5.31it/s, loss=2.366e+01]
Image optimization: 42%|####1 | 167/400 [00:30<00:44, 5.29it/s, loss=2.365e+01]
Image optimization: 42%|####2 | 168/400 [00:30<00:43, 5.31it/s, loss=2.365e+01]
Image optimization: 42%|####2 | 169/400 [00:30<00:43, 5.30it/s, loss=2.364e+01]
Image optimization: 42%|####2 | 170/400 [00:30<00:43, 5.27it/s, loss=2.364e+01]
Image optimization: 43%|####2 | 171/400 [00:30<00:43, 5.30it/s, loss=2.364e+01]
Image optimization: 43%|####3 | 172/400 [00:30<00:42, 5.31it/s, loss=2.363e+01]
Image optimization: 43%|####3 | 173/400 [00:31<00:42, 5.32it/s, loss=2.363e+01]
Image optimization: 44%|####3 | 174/400 [00:31<00:42, 5.29it/s, loss=2.362e+01]
Image optimization: 44%|####3 | 175/400 [00:31<00:42, 5.30it/s, loss=2.362e+01]
Image optimization: 44%|####4 | 176/400 [00:31<00:42, 5.31it/s, loss=2.362e+01]
Image optimization: 44%|####4 | 177/400 [00:31<00:42, 5.29it/s, loss=2.361e+01]
Image optimization: 44%|####4 | 178/400 [00:32<00:41, 5.29it/s, loss=2.361e+01]
Image optimization: 45%|####4 | 179/400 [00:32<00:41, 5.27it/s, loss=2.360e+01]
Image optimization: 45%|####5 | 180/400 [00:32<00:41, 5.25it/s, loss=2.360e+01]
Image optimization: 45%|####5 | 181/400 [00:32<00:41, 5.28it/s, loss=2.360e+01]
Image optimization: 46%|####5 | 182/400 [00:32<00:41, 5.31it/s, loss=2.359e+01]
Image optimization: 46%|####5 | 183/400 [00:33<00:41, 5.29it/s, loss=2.359e+01]
Image optimization: 46%|####6 | 184/400 [00:33<00:41, 5.26it/s, loss=2.358e+01]
Image optimization: 46%|####6 | 185/400 [00:33<00:40, 5.28it/s, loss=2.358e+01]
Image optimization: 46%|####6 | 186/400 [00:33<00:40, 5.27it/s, loss=2.358e+01]
Image optimization: 47%|####6 | 187/400 [00:33<00:40, 5.31it/s, loss=2.357e+01]
Image optimization: 47%|####6 | 188/400 [00:33<00:39, 5.34it/s, loss=2.357e+01]
Image optimization: 47%|####7 | 189/400 [00:34<00:39, 5.33it/s, loss=2.357e+01]
Image optimization: 48%|####7 | 190/400 [00:34<00:39, 5.29it/s, loss=2.356e+01]
Image optimization: 48%|####7 | 191/400 [00:34<00:39, 5.30it/s, loss=2.356e+01]
Image optimization: 48%|####8 | 192/400 [00:34<00:39, 5.32it/s, loss=2.355e+01]
Image optimization: 48%|####8 | 193/400 [00:34<00:38, 5.31it/s, loss=2.355e+01]
Image optimization: 48%|####8 | 194/400 [00:35<00:38, 5.30it/s, loss=2.355e+01]
Image optimization: 49%|####8 | 195/400 [00:35<00:38, 5.33it/s, loss=2.354e+01]
Image optimization: 49%|####9 | 196/400 [00:35<00:38, 5.33it/s, loss=2.354e+01]
Image optimization: 49%|####9 | 197/400 [00:35<00:38, 5.31it/s, loss=2.354e+01]
Image optimization: 50%|####9 | 198/400 [00:35<00:38, 5.31it/s, loss=2.353e+01]
Image optimization: 50%|####9 | 199/400 [00:36<00:37, 5.30it/s, loss=2.353e+01]
Image optimization: 50%|##### | 200/400 [00:36<00:37, 5.30it/s, loss=2.352e+01]
Image optimization: 50%|##### | 201/400 [00:36<00:37, 5.29it/s, loss=2.352e+01]
Image optimization: 50%|##### | 202/400 [00:36<00:37, 5.29it/s, loss=2.352e+01]
Image optimization: 51%|##### | 203/400 [00:36<00:37, 5.28it/s, loss=2.351e+01]
Image optimization: 51%|#####1 | 204/400 [00:37<00:37, 5.26it/s, loss=2.351e+01]
Image optimization: 51%|#####1 | 205/400 [00:37<00:36, 5.30it/s, loss=2.351e+01]
Image optimization: 52%|#####1 | 206/400 [00:37<00:36, 5.32it/s, loss=2.350e+01]
Image optimization: 52%|#####1 | 207/400 [00:37<00:36, 5.32it/s, loss=2.350e+01]
Image optimization: 52%|#####2 | 208/400 [00:37<00:36, 5.30it/s, loss=2.350e+01]
Image optimization: 52%|#####2 | 209/400 [00:37<00:36, 5.29it/s, loss=2.349e+01]
Image optimization: 52%|#####2 | 210/400 [00:38<00:35, 5.32it/s, loss=2.349e+01]
Image optimization: 53%|#####2 | 211/400 [00:38<00:35, 5.32it/s, loss=2.349e+01]
Image optimization: 53%|#####3 | 212/400 [00:38<00:35, 5.32it/s, loss=2.348e+01]
Image optimization: 53%|#####3 | 213/400 [00:38<00:35, 5.32it/s, loss=2.348e+01]
Image optimization: 54%|#####3 | 214/400 [00:38<00:34, 5.36it/s, loss=2.348e+01]
Image optimization: 54%|#####3 | 215/400 [00:39<00:34, 5.36it/s, loss=2.348e+01]
Image optimization: 54%|#####4 | 216/400 [00:39<00:34, 5.35it/s, loss=2.347e+01]
Image optimization: 54%|#####4 | 217/400 [00:39<00:34, 5.32it/s, loss=2.347e+01]
Image optimization: 55%|#####4 | 218/400 [00:39<00:34, 5.35it/s, loss=2.347e+01]
Image optimization: 55%|#####4 | 219/400 [00:39<00:33, 5.38it/s, loss=2.346e+01]
Image optimization: 55%|#####5 | 220/400 [00:39<00:33, 5.41it/s, loss=2.346e+01]
Image optimization: 55%|#####5 | 221/400 [00:40<00:33, 5.42it/s, loss=2.346e+01]
Image optimization: 56%|#####5 | 222/400 [00:40<00:32, 5.41it/s, loss=2.346e+01]
Image optimization: 56%|#####5 | 223/400 [00:40<00:32, 5.39it/s, loss=2.345e+01]
Image optimization: 56%|#####6 | 224/400 [00:40<00:32, 5.36it/s, loss=2.345e+01]
Image optimization: 56%|#####6 | 225/400 [00:40<00:32, 5.35it/s, loss=2.345e+01]
Image optimization: 56%|#####6 | 226/400 [00:41<00:32, 5.39it/s, loss=2.344e+01]
Image optimization: 57%|#####6 | 227/400 [00:41<00:32, 5.40it/s, loss=2.344e+01]
Image optimization: 57%|#####6 | 228/400 [00:41<00:31, 5.41it/s, loss=2.344e+01]
Image optimization: 57%|#####7 | 229/400 [00:41<00:31, 5.41it/s, loss=2.344e+01]
Image optimization: 57%|#####7 | 230/400 [00:41<00:31, 5.42it/s, loss=2.343e+01]
Image optimization: 58%|#####7 | 231/400 [00:42<00:31, 5.38it/s, loss=2.343e+01]
Image optimization: 58%|#####8 | 232/400 [00:42<00:31, 5.37it/s, loss=2.343e+01]
Image optimization: 58%|#####8 | 233/400 [00:42<00:31, 5.35it/s, loss=2.343e+01]
Image optimization: 58%|#####8 | 234/400 [00:42<00:30, 5.39it/s, loss=2.342e+01]
Image optimization: 59%|#####8 | 235/400 [00:42<00:30, 5.40it/s, loss=2.342e+01]
Image optimization: 59%|#####8 | 236/400 [00:42<00:30, 5.40it/s, loss=2.342e+01]
Image optimization: 59%|#####9 | 237/400 [00:43<00:30, 5.41it/s, loss=2.342e+01]
Image optimization: 60%|#####9 | 238/400 [00:43<00:30, 5.37it/s, loss=2.341e+01]
Image optimization: 60%|#####9 | 239/400 [00:43<00:30, 5.36it/s, loss=2.341e+01]
Image optimization: 60%|###### | 240/400 [00:43<00:29, 5.36it/s, loss=2.341e+01]
Image optimization: 60%|###### | 241/400 [00:43<00:29, 5.39it/s, loss=2.341e+01]
Image optimization: 60%|###### | 242/400 [00:44<00:29, 5.41it/s, loss=2.340e+01]
Image optimization: 61%|###### | 243/400 [00:44<00:28, 5.42it/s, loss=2.340e+01]
Image optimization: 61%|######1 | 244/400 [00:44<00:28, 5.44it/s, loss=2.340e+01]
Image optimization: 61%|######1 | 245/400 [00:44<00:28, 5.44it/s, loss=2.339e+01]
Image optimization: 62%|######1 | 246/400 [00:44<00:28, 5.45it/s, loss=2.339e+01]
Image optimization: 62%|######1 | 247/400 [00:44<00:28, 5.46it/s, loss=2.339e+01]
Image optimization: 62%|######2 | 248/400 [00:45<00:27, 5.45it/s, loss=2.339e+01]
Image optimization: 62%|######2 | 249/400 [00:45<00:27, 5.46it/s, loss=2.338e+01]
Image optimization: 62%|######2 | 250/400 [00:45<00:27, 5.46it/s, loss=2.338e+01]
Image optimization: 63%|######2 | 251/400 [00:45<00:27, 5.47it/s, loss=2.338e+01]
Image optimization: 63%|######3 | 252/400 [00:45<00:27, 5.46it/s, loss=2.338e+01]
Image optimization: 63%|######3 | 253/400 [00:46<00:26, 5.46it/s, loss=2.337e+01]
Image optimization: 64%|######3 | 254/400 [00:46<00:26, 5.46it/s, loss=2.337e+01]
Image optimization: 64%|######3 | 255/400 [00:46<00:26, 5.46it/s, loss=2.337e+01]
Image optimization: 64%|######4 | 256/400 [00:46<00:26, 5.46it/s, loss=2.337e+01]
Image optimization: 64%|######4 | 257/400 [00:46<00:26, 5.47it/s, loss=2.337e+01]
Image optimization: 64%|######4 | 258/400 [00:47<00:26, 5.42it/s, loss=2.336e+01]
Image optimization: 65%|######4 | 259/400 [00:47<00:26, 5.40it/s, loss=2.336e+01]
Image optimization: 65%|######5 | 260/400 [00:47<00:25, 5.40it/s, loss=2.336e+01]
Image optimization: 65%|######5 | 261/400 [00:47<00:25, 5.37it/s, loss=2.336e+01]
Image optimization: 66%|######5 | 262/400 [00:47<00:25, 5.38it/s, loss=2.336e+01]
Image optimization: 66%|######5 | 263/400 [00:47<00:25, 5.41it/s, loss=2.335e+01]
Image optimization: 66%|######6 | 264/400 [00:48<00:25, 5.40it/s, loss=2.335e+01]
Image optimization: 66%|######6 | 265/400 [00:48<00:24, 5.44it/s, loss=2.335e+01]
Image optimization: 66%|######6 | 266/400 [00:48<00:24, 5.44it/s, loss=2.335e+01]
Image optimization: 67%|######6 | 267/400 [00:48<00:24, 5.46it/s, loss=2.334e+01]
Image optimization: 67%|######7 | 268/400 [00:48<00:24, 5.46it/s, loss=2.334e+01]
Image optimization: 67%|######7 | 269/400 [00:49<00:24, 5.44it/s, loss=2.334e+01]
Image optimization: 68%|######7 | 270/400 [00:49<00:23, 5.45it/s, loss=2.334e+01]
Image optimization: 68%|######7 | 271/400 [00:49<00:23, 5.46it/s, loss=2.334e+01]
Image optimization: 68%|######8 | 272/400 [00:49<00:23, 5.46it/s, loss=2.333e+01]
Image optimization: 68%|######8 | 273/400 [00:49<00:23, 5.44it/s, loss=2.333e+01]
Image optimization: 68%|######8 | 274/400 [00:49<00:23, 5.44it/s, loss=2.333e+01]
Image optimization: 69%|######8 | 275/400 [00:50<00:23, 5.43it/s, loss=2.333e+01]
Image optimization: 69%|######9 | 276/400 [00:50<00:22, 5.42it/s, loss=2.333e+01]
Image optimization: 69%|######9 | 277/400 [00:50<00:22, 5.40it/s, loss=2.332e+01]
Image optimization: 70%|######9 | 278/400 [00:50<00:22, 5.39it/s, loss=2.332e+01]
Image optimization: 70%|######9 | 279/400 [00:50<00:22, 5.38it/s, loss=2.332e+01]
Image optimization: 70%|####### | 280/400 [00:51<00:22, 5.39it/s, loss=2.332e+01]
Image optimization: 70%|####### | 281/400 [00:51<00:21, 5.42it/s, loss=2.332e+01]
Image optimization: 70%|####### | 282/400 [00:51<00:21, 5.40it/s, loss=2.331e+01]
Image optimization: 71%|####### | 283/400 [00:51<00:21, 5.41it/s, loss=2.331e+01]
Image optimization: 71%|#######1 | 284/400 [00:51<00:21, 5.44it/s, loss=2.331e+01]
Image optimization: 71%|#######1 | 285/400 [00:51<00:21, 5.43it/s, loss=2.331e+01]
Image optimization: 72%|#######1 | 286/400 [00:52<00:20, 5.47it/s, loss=2.331e+01]
Image optimization: 72%|#######1 | 287/400 [00:52<00:20, 5.46it/s, loss=2.330e+01]
Image optimization: 72%|#######2 | 288/400 [00:52<00:20, 5.46it/s, loss=2.330e+01]
Image optimization: 72%|#######2 | 289/400 [00:52<00:20, 5.45it/s, loss=2.330e+01]
Image optimization: 72%|#######2 | 290/400 [00:52<00:20, 5.43it/s, loss=2.330e+01]
Image optimization: 73%|#######2 | 291/400 [00:53<00:19, 5.46it/s, loss=2.330e+01]
Image optimization: 73%|#######3 | 292/400 [00:53<00:19, 5.47it/s, loss=2.330e+01]
Image optimization: 73%|#######3 | 293/400 [00:53<00:19, 5.45it/s, loss=2.329e+01]
Image optimization: 74%|#######3 | 294/400 [00:53<00:19, 5.46it/s, loss=2.329e+01]
Image optimization: 74%|#######3 | 295/400 [00:53<00:19, 5.46it/s, loss=2.329e+01]
Image optimization: 74%|#######4 | 296/400 [00:54<00:18, 5.48it/s, loss=2.329e+01]
Image optimization: 74%|#######4 | 297/400 [00:54<00:18, 5.45it/s, loss=2.329e+01]
Image optimization: 74%|#######4 | 298/400 [00:54<00:18, 5.46it/s, loss=2.328e+01]
Image optimization: 75%|#######4 | 299/400 [00:54<00:18, 5.45it/s, loss=2.328e+01]
Image optimization: 75%|#######5 | 300/400 [00:54<00:18, 5.45it/s, loss=2.328e+01]
Image optimization: 75%|#######5 | 301/400 [00:54<00:18, 5.46it/s, loss=2.328e+01]
Image optimization: 76%|#######5 | 302/400 [00:55<00:17, 5.47it/s, loss=2.328e+01]
Image optimization: 76%|#######5 | 303/400 [00:55<00:17, 5.44it/s, loss=2.328e+01]
Image optimization: 76%|#######6 | 304/400 [00:55<00:17, 5.46it/s, loss=2.327e+01]
Image optimization: 76%|#######6 | 305/400 [00:55<00:17, 5.47it/s, loss=2.327e+01]
Image optimization: 76%|#######6 | 306/400 [00:55<00:17, 5.47it/s, loss=2.327e+01]
Image optimization: 77%|#######6 | 307/400 [00:56<00:17, 5.46it/s, loss=2.327e+01]
Image optimization: 77%|#######7 | 308/400 [00:56<00:16, 5.45it/s, loss=2.327e+01]
Image optimization: 77%|#######7 | 309/400 [00:56<00:16, 5.45it/s, loss=2.326e+01]
Image optimization: 78%|#######7 | 310/400 [00:56<00:16, 5.43it/s, loss=2.326e+01]
Image optimization: 78%|#######7 | 311/400 [00:56<00:16, 5.44it/s, loss=2.326e+01]
Image optimization: 78%|#######8 | 312/400 [00:56<00:16, 5.46it/s, loss=2.326e+01]
Image optimization: 78%|#######8 | 313/400 [00:57<00:15, 5.45it/s, loss=2.326e+01]
Image optimization: 78%|#######8 | 314/400 [00:57<00:15, 5.44it/s, loss=2.325e+01]
Image optimization: 79%|#######8 | 315/400 [00:57<00:15, 5.45it/s, loss=2.325e+01]
Image optimization: 79%|#######9 | 316/400 [00:57<00:15, 5.47it/s, loss=2.325e+01]
Image optimization: 79%|#######9 | 317/400 [00:57<00:15, 5.48it/s, loss=2.325e+01]
Image optimization: 80%|#######9 | 318/400 [00:58<00:15, 5.46it/s, loss=2.325e+01]
Image optimization: 80%|#######9 | 319/400 [00:58<00:14, 5.47it/s, loss=2.325e+01]
Image optimization: 80%|######## | 320/400 [00:58<00:14, 5.44it/s, loss=2.324e+01]
Image optimization: 80%|######## | 321/400 [00:58<00:14, 5.46it/s, loss=2.324e+01]
Image optimization: 80%|######## | 322/400 [00:58<00:14, 5.47it/s, loss=2.324e+01]
Image optimization: 81%|######## | 323/400 [00:58<00:14, 5.46it/s, loss=2.324e+01]
Image optimization: 81%|########1 | 324/400 [00:59<00:13, 5.46it/s, loss=2.324e+01]
Image optimization: 81%|########1 | 325/400 [00:59<00:13, 5.45it/s, loss=2.323e+01]
Image optimization: 82%|########1 | 326/400 [00:59<00:13, 5.45it/s, loss=2.323e+01]
Image optimization: 82%|########1 | 327/400 [00:59<00:13, 5.45it/s, loss=2.323e+01]
Image optimization: 82%|########2 | 328/400 [00:59<00:13, 5.45it/s, loss=2.323e+01]
Image optimization: 82%|########2 | 329/400 [01:00<00:12, 5.47it/s, loss=2.323e+01]
Image optimization: 82%|########2 | 330/400 [01:00<00:12, 5.45it/s, loss=2.323e+01]
Image optimization: 83%|########2 | 331/400 [01:00<00:12, 5.46it/s, loss=2.322e+01]
Image optimization: 83%|########2 | 332/400 [01:00<00:12, 5.46it/s, loss=2.322e+01]
Image optimization: 83%|########3 | 333/400 [01:00<00:12, 5.46it/s, loss=2.322e+01]
Image optimization: 84%|########3 | 334/400 [01:00<00:12, 5.48it/s, loss=2.322e+01]
Image optimization: 84%|########3 | 335/400 [01:01<00:11, 5.45it/s, loss=2.322e+01]
Image optimization: 84%|########4 | 336/400 [01:01<00:11, 5.47it/s, loss=2.322e+01]
Image optimization: 84%|########4 | 337/400 [01:01<00:11, 5.47it/s, loss=2.322e+01]
Image optimization: 84%|########4 | 338/400 [01:01<00:11, 5.46it/s, loss=2.321e+01]
Image optimization: 85%|########4 | 339/400 [01:01<00:11, 5.46it/s, loss=2.321e+01]
Image optimization: 85%|########5 | 340/400 [01:02<00:11, 5.44it/s, loss=2.321e+01]
Image optimization: 85%|########5 | 341/400 [01:02<00:10, 5.47it/s, loss=2.321e+01]
Image optimization: 86%|########5 | 342/400 [01:02<00:10, 5.47it/s, loss=2.321e+01]
Image optimization: 86%|########5 | 343/400 [01:02<00:10, 5.48it/s, loss=2.321e+01]
Image optimization: 86%|########6 | 344/400 [01:02<00:10, 5.45it/s, loss=2.320e+01]
Image optimization: 86%|########6 | 345/400 [01:02<00:10, 5.45it/s, loss=2.320e+01]
Image optimization: 86%|########6 | 346/400 [01:03<00:09, 5.47it/s, loss=2.320e+01]
Image optimization: 87%|########6 | 347/400 [01:03<00:09, 5.46it/s, loss=2.320e+01]
Image optimization: 87%|########7 | 348/400 [01:03<00:09, 5.47it/s, loss=2.320e+01]
Image optimization: 87%|########7 | 349/400 [01:03<00:09, 5.45it/s, loss=2.320e+01]
Image optimization: 88%|########7 | 350/400 [01:03<00:09, 5.44it/s, loss=2.320e+01]
Image optimization: 88%|########7 | 351/400 [01:04<00:08, 5.47it/s, loss=2.319e+01]
Image optimization: 88%|########8 | 352/400 [01:04<00:08, 5.48it/s, loss=2.319e+01]
Image optimization: 88%|########8 | 353/400 [01:04<00:08, 5.47it/s, loss=2.319e+01]
Image optimization: 88%|########8 | 354/400 [01:04<00:08, 5.46it/s, loss=2.319e+01]
Image optimization: 89%|########8 | 355/400 [01:04<00:08, 5.44it/s, loss=2.319e+01]
Image optimization: 89%|########9 | 356/400 [01:04<00:08, 5.46it/s, loss=2.319e+01]
Image optimization: 89%|########9 | 357/400 [01:05<00:07, 5.48it/s, loss=2.318e+01]
Image optimization: 90%|########9 | 358/400 [01:05<00:07, 5.49it/s, loss=2.318e+01]
Image optimization: 90%|########9 | 359/400 [01:05<00:07, 5.47it/s, loss=2.318e+01]
Image optimization: 90%|######### | 360/400 [01:05<00:07, 5.44it/s, loss=2.318e+01]
Image optimization: 90%|######### | 361/400 [01:05<00:07, 5.45it/s, loss=2.318e+01]
Image optimization: 90%|######### | 362/400 [01:06<00:06, 5.48it/s, loss=2.318e+01]
Image optimization: 91%|######### | 363/400 [01:06<00:06, 5.49it/s, loss=2.318e+01]
Image optimization: 91%|#########1| 364/400 [01:06<00:06, 5.47it/s, loss=2.317e+01]
Image optimization: 91%|#########1| 365/400 [01:06<00:06, 5.45it/s, loss=2.317e+01]
Image optimization: 92%|#########1| 366/400 [01:06<00:06, 5.45it/s, loss=2.317e+01]
Image optimization: 92%|#########1| 367/400 [01:07<00:06, 5.48it/s, loss=2.317e+01]
Image optimization: 92%|#########2| 368/400 [01:07<00:05, 5.48it/s, loss=2.317e+01]
Image optimization: 92%|#########2| 369/400 [01:07<00:05, 5.49it/s, loss=2.317e+01]
Image optimization: 92%|#########2| 370/400 [01:07<00:05, 5.46it/s, loss=2.316e+01]
Image optimization: 93%|#########2| 371/400 [01:07<00:05, 5.47it/s, loss=2.316e+01]
Image optimization: 93%|#########3| 372/400 [01:07<00:05, 5.48it/s, loss=2.316e+01]
Image optimization: 93%|#########3| 373/400 [01:08<00:04, 5.47it/s, loss=2.316e+01]
Image optimization: 94%|#########3| 374/400 [01:08<00:04, 5.48it/s, loss=2.316e+01]
Image optimization: 94%|#########3| 375/400 [01:08<00:04, 5.45it/s, loss=2.316e+01]
Image optimization: 94%|#########3| 376/400 [01:08<00:04, 5.47it/s, loss=2.316e+01]
Image optimization: 94%|#########4| 377/400 [01:08<00:04, 5.48it/s, loss=2.316e+01]
Image optimization: 94%|#########4| 378/400 [01:09<00:04, 5.45it/s, loss=2.315e+01]
Image optimization: 95%|#########4| 379/400 [01:09<00:03, 5.46it/s, loss=2.315e+01]
Image optimization: 95%|#########5| 380/400 [01:09<00:03, 5.45it/s, loss=2.315e+01]
Image optimization: 95%|#########5| 381/400 [01:09<00:03, 5.47it/s, loss=2.315e+01]
Image optimization: 96%|#########5| 382/400 [01:09<00:03, 5.48it/s, loss=2.315e+01]
Image optimization: 96%|#########5| 383/400 [01:09<00:03, 5.49it/s, loss=2.315e+01]
Image optimization: 96%|#########6| 384/400 [01:10<00:02, 5.46it/s, loss=2.315e+01]
Image optimization: 96%|#########6| 385/400 [01:10<00:02, 5.47it/s, loss=2.314e+01]
Image optimization: 96%|#########6| 386/400 [01:10<00:02, 5.49it/s, loss=2.314e+01]
Image optimization: 97%|#########6| 387/400 [01:10<00:02, 5.47it/s, loss=2.314e+01]
Image optimization: 97%|#########7| 388/400 [01:10<00:02, 5.47it/s, loss=2.314e+01]
Image optimization: 97%|#########7| 389/400 [01:11<00:02, 5.46it/s, loss=2.314e+01]
Image optimization: 98%|#########7| 390/400 [01:11<00:01, 5.47it/s, loss=2.314e+01]
Image optimization: 98%|#########7| 391/400 [01:11<00:01, 5.45it/s, loss=2.314e+01]
Image optimization: 98%|#########8| 392/400 [01:11<00:01, 5.47it/s, loss=2.313e+01]
Image optimization: 98%|#########8| 393/400 [01:11<00:01, 5.47it/s, loss=2.313e+01]
Image optimization: 98%|#########8| 394/400 [01:11<00:01, 5.46it/s, loss=2.313e+01]
Image optimization: 99%|#########8| 395/400 [01:12<00:00, 5.48it/s, loss=2.313e+01]
Image optimization: 99%|#########9| 396/400 [01:12<00:00, 5.45it/s, loss=2.313e+01]
Image optimization: 99%|#########9| 397/400 [01:12<00:00, 5.46it/s, loss=2.313e+01]
Image optimization: 100%|#########9| 398/400 [01:12<00:00, 5.47it/s, loss=2.313e+01]
Image optimization: 100%|#########9| 399/400 [01:12<00:00, 5.49it/s, loss=2.312e+01]
Image optimization: 100%|##########| 400/400 [01:13<00:00, 5.48it/s, loss=2.312e+01]
Image optimization: 100%|##########| 400/400 [01:13<00:00, 5.48it/s, loss=2.312e+01]
112 elapsed_time_without_pyramid = stop_without_pyramid - start_without_pyramid
113 print(
114 f"Without pyramid the optimization took {elapsed_time_without_pyramid:.0f} seconds."
115 )
Out:
Without pyramid the optimization took 73 seconds.
As you can see the small blurry branches on the left side of the image were picked up by the style transfer. They distort the mosaic pattern, which minders the quality of the result. In the next section we tackle this by focusing on coarse elements first and add the details afterwards.
Image optimization with pyramid¶
Opposed to the prior examples we now want to perform an NST on multiple resolutions.
In pystiche
this handled by an ImagePyramid
. The
resolutions are selected by specifying the edge_sizes
of the images on each level
. The optimization is performed for num_steps
on the different levels.
The resizing of all images, i.e. input_image
and target images (content_image
and style_image
) is handled by the pyramid
. For that we need to register the
perceptual loss (criterion
) as one of the resize_targets
.
Note
By default the edge_sizes
correspond to the shorter edge
of the images. To
change that you can pass edge="long"
. For fine-grained control you can also
pass a sequence comprising "short"
and "long"
to select the edge
for
each level separately. Its length has to match the length of edge_sizes
.
Note
For a fine-grained control over the number of steps on each level you can pass a
sequence to select the num_steps
for each level separately. Its length has to
match the length of edge_sizes
.
150 edge_sizes = (250, 500)
151 num_steps = 200
152 image_pyramid = pyramid.ImagePyramid(
153 edge_sizes, num_steps, resize_targets=(perceptual_loss,)
154 )
155 print(image_pyramid)
Out:
ImagePyramid(
(0): PyramidLevel(edge_size=250, num_steps=200, edge=short)
(1): PyramidLevel(edge_size=500, num_steps=200, edge=short)
)
With a pyramid the NST is performed by
pyramid_image_optimization()
. We time the execution and show
the result afterwards.
Note
We regenerate the input_image
since it was changed inplace during the first
optimization.
168 input_image = get_input_image(starting_point, content_image=content_image)
169
170 start_with_pyramid = time.time()
171 output_image = optim.pyramid_image_optimization(
172 input_image, perceptual_loss, image_pyramid
173 )
174 stop_with_pyramid = time.time()
175
176 show_image(output_image, title="Output image with pyramid")
Out:
Pyramid: 0%| | 0/2 [00:00<?, ?it/s]
Image optimization: 0%| | 0/200 [00:00<?, ?it/s]
Image optimization: 2%|1 | 3/200 [00:00<00:07, 26.26it/s, loss=4.393e+01]
Image optimization: 3%|3 | 6/200 [00:00<00:07, 25.92it/s, loss=4.115e+01]
Image optimization: 4%|4 | 9/200 [00:00<00:07, 25.63it/s, loss=3.837e+01]
Image optimization: 6%|6 | 12/200 [00:00<00:07, 25.42it/s, loss=3.644e+01]
Image optimization: 8%|7 | 15/200 [00:00<00:07, 25.18it/s, loss=3.482e+01]
Image optimization: 9%|9 | 18/200 [00:00<00:07, 25.00it/s, loss=3.373e+01]
Image optimization: 10%|# | 21/200 [00:00<00:07, 24.80it/s, loss=3.305e+01]
Image optimization: 12%|#2 | 24/200 [00:00<00:07, 23.27it/s, loss=3.245e+01]
Image optimization: 14%|#3 | 27/200 [00:01<00:07, 23.64it/s, loss=3.201e+01]
Image optimization: 15%|#5 | 30/200 [00:01<00:07, 23.88it/s, loss=3.169e+01]
Image optimization: 16%|#6 | 33/200 [00:01<00:06, 24.11it/s, loss=3.142e+01]
Image optimization: 18%|#8 | 36/200 [00:01<00:06, 24.25it/s, loss=3.114e+01]
Image optimization: 20%|#9 | 39/200 [00:01<00:06, 24.31it/s, loss=3.095e+01]
Image optimization: 21%|##1 | 42/200 [00:01<00:06, 24.41it/s, loss=3.078e+01]
Image optimization: 22%|##2 | 45/200 [00:01<00:06, 24.40it/s, loss=3.061e+01]
Image optimization: 24%|##4 | 48/200 [00:01<00:06, 24.34it/s, loss=3.046e+01]
Image optimization: 26%|##5 | 51/200 [00:02<00:06, 24.19it/s, loss=3.032e+01]
Image optimization: 27%|##7 | 54/200 [00:02<00:06, 23.91it/s, loss=3.021e+01]
Image optimization: 28%|##8 | 57/200 [00:02<00:06, 23.77it/s, loss=3.010e+01]
Image optimization: 30%|### | 60/200 [00:02<00:05, 23.79it/s, loss=3.000e+01]
Image optimization: 32%|###1 | 63/200 [00:02<00:05, 23.61it/s, loss=2.991e+01]
Image optimization: 33%|###3 | 66/200 [00:02<00:05, 23.45it/s, loss=2.983e+01]
Image optimization: 34%|###4 | 69/200 [00:02<00:05, 23.45it/s, loss=2.976e+01]
Image optimization: 36%|###6 | 72/200 [00:02<00:05, 23.19it/s, loss=2.970e+01]
Image optimization: 38%|###7 | 75/200 [00:03<00:05, 23.09it/s, loss=2.964e+01]
Image optimization: 39%|###9 | 78/200 [00:03<00:05, 22.90it/s, loss=2.959e+01]
Image optimization: 40%|#### | 81/200 [00:03<00:05, 22.90it/s, loss=2.953e+01]
Image optimization: 42%|####2 | 84/200 [00:03<00:05, 22.75it/s, loss=2.949e+01]
Image optimization: 44%|####3 | 87/200 [00:03<00:04, 22.76it/s, loss=2.944e+01]
Image optimization: 45%|####5 | 90/200 [00:03<00:04, 22.52it/s, loss=2.940e+01]
Image optimization: 46%|####6 | 93/200 [00:03<00:04, 22.51it/s, loss=2.935e+01]
Image optimization: 48%|####8 | 96/200 [00:04<00:04, 22.30it/s, loss=2.932e+01]
Image optimization: 50%|####9 | 99/200 [00:04<00:04, 22.17it/s, loss=2.927e+01]
Image optimization: 51%|#####1 | 102/200 [00:04<00:04, 22.18it/s, loss=2.923e+01]
Image optimization: 52%|#####2 | 105/200 [00:04<00:04, 22.20it/s, loss=2.919e+01]
Image optimization: 54%|#####4 | 108/200 [00:04<00:04, 22.07it/s, loss=2.916e+01]
Image optimization: 56%|#####5 | 111/200 [00:04<00:04, 22.01it/s, loss=2.913e+01]
Image optimization: 57%|#####6 | 114/200 [00:04<00:03, 22.07it/s, loss=2.910e+01]
Image optimization: 58%|#####8 | 117/200 [00:05<00:03, 22.03it/s, loss=2.906e+01]
Image optimization: 60%|###### | 120/200 [00:05<00:03, 21.99it/s, loss=2.904e+01]
Image optimization: 62%|######1 | 123/200 [00:05<00:03, 22.05it/s, loss=2.901e+01]
Image optimization: 63%|######3 | 126/200 [00:05<00:03, 22.07it/s, loss=2.899e+01]
Image optimization: 64%|######4 | 129/200 [00:05<00:03, 22.01it/s, loss=2.897e+01]
Image optimization: 66%|######6 | 132/200 [00:05<00:03, 21.96it/s, loss=2.895e+01]
Image optimization: 68%|######7 | 135/200 [00:05<00:02, 21.99it/s, loss=2.892e+01]
Image optimization: 69%|######9 | 138/200 [00:05<00:02, 21.97it/s, loss=2.890e+01]
Image optimization: 70%|####### | 141/200 [00:06<00:02, 21.88it/s, loss=2.888e+01]
Image optimization: 72%|#######2 | 144/200 [00:06<00:02, 21.89it/s, loss=2.886e+01]
Image optimization: 74%|#######3 | 147/200 [00:06<00:02, 21.92it/s, loss=2.885e+01]
Image optimization: 75%|#######5 | 150/200 [00:06<00:02, 21.94it/s, loss=2.882e+01]
Image optimization: 76%|#######6 | 153/200 [00:06<00:02, 21.90it/s, loss=2.880e+01]
Image optimization: 78%|#######8 | 156/200 [00:06<00:02, 21.95it/s, loss=2.878e+01]
Image optimization: 80%|#######9 | 159/200 [00:06<00:01, 21.97it/s, loss=2.877e+01]
Image optimization: 81%|########1 | 162/200 [00:07<00:01, 21.96it/s, loss=2.875e+01]
Image optimization: 82%|########2 | 165/200 [00:07<00:01, 21.93it/s, loss=2.874e+01]
Image optimization: 84%|########4 | 168/200 [00:07<00:01, 21.94it/s, loss=2.872e+01]
Image optimization: 86%|########5 | 171/200 [00:07<00:01, 22.07it/s, loss=2.871e+01]
Image optimization: 87%|########7 | 174/200 [00:07<00:01, 22.00it/s, loss=2.869e+01]
Image optimization: 88%|########8 | 177/200 [00:07<00:01, 22.00it/s, loss=2.868e+01]
Image optimization: 90%|######### | 180/200 [00:07<00:00, 22.12it/s, loss=2.867e+01]
Image optimization: 92%|#########1| 183/200 [00:08<00:00, 21.99it/s, loss=2.865e+01]
Image optimization: 93%|#########3| 186/200 [00:08<00:00, 21.98it/s, loss=2.864e+01]
Image optimization: 94%|#########4| 189/200 [00:08<00:00, 21.99it/s, loss=2.863e+01]
Image optimization: 96%|#########6| 192/200 [00:08<00:00, 22.01it/s, loss=2.861e+01]
Image optimization: 98%|#########7| 195/200 [00:08<00:00, 21.96it/s, loss=2.860e+01]
Image optimization: 99%|#########9| 198/200 [00:08<00:00, 21.92it/s, loss=2.859e+01]
Image optimization: 100%|##########| 200/200 [00:08<00:00, 22.75it/s, loss=2.858e+01]
Pyramid: 50%|##### | 1/2 [00:08<00:08, 8.80s/it]
Image optimization: 0%| | 0/200 [00:00<?, ?it/s]
Image optimization: 0%| | 1/200 [00:00<00:42, 4.73it/s, loss=4.052e+01]
Image optimization: 1%|1 | 2/200 [00:00<00:36, 5.41it/s, loss=4.052e+01]
Image optimization: 2%|1 | 3/200 [00:00<00:34, 5.66it/s, loss=3.762e+01]
Image optimization: 2%|2 | 4/200 [00:00<00:34, 5.75it/s, loss=3.573e+01]
Image optimization: 2%|2 | 5/200 [00:00<00:33, 5.86it/s, loss=3.424e+01]
Image optimization: 3%|3 | 6/200 [00:01<00:32, 5.97it/s, loss=3.307e+01]
Image optimization: 4%|3 | 7/200 [00:01<00:32, 6.02it/s, loss=3.206e+01]
Image optimization: 4%|4 | 8/200 [00:01<00:31, 6.04it/s, loss=3.126e+01]
Image optimization: 4%|4 | 9/200 [00:01<00:31, 6.03it/s, loss=3.056e+01]
Image optimization: 5%|5 | 10/200 [00:01<00:31, 6.00it/s, loss=2.999e+01]
Image optimization: 6%|5 | 11/200 [00:01<00:31, 5.94it/s, loss=2.953e+01]
Image optimization: 6%|6 | 12/200 [00:02<00:31, 5.98it/s, loss=2.915e+01]
Image optimization: 6%|6 | 13/200 [00:02<00:31, 6.02it/s, loss=2.880e+01]
Image optimization: 7%|7 | 14/200 [00:02<00:30, 6.05it/s, loss=2.847e+01]
Image optimization: 8%|7 | 15/200 [00:02<00:30, 6.04it/s, loss=2.820e+01]
Image optimization: 8%|8 | 16/200 [00:02<00:30, 5.97it/s, loss=2.796e+01]
Image optimization: 8%|8 | 17/200 [00:02<00:30, 5.93it/s, loss=2.774e+01]
Image optimization: 9%|9 | 18/200 [00:03<00:30, 5.96it/s, loss=2.754e+01]
Image optimization: 10%|9 | 19/200 [00:03<00:30, 5.94it/s, loss=2.736e+01]
Image optimization: 10%|# | 20/200 [00:03<00:30, 5.97it/s, loss=2.719e+01]
Image optimization: 10%|# | 21/200 [00:03<00:29, 5.98it/s, loss=2.704e+01]
Image optimization: 11%|#1 | 22/200 [00:03<00:29, 5.96it/s, loss=2.691e+01]
Image optimization: 12%|#1 | 23/200 [00:03<00:30, 5.89it/s, loss=2.678e+01]
Image optimization: 12%|#2 | 24/200 [00:04<00:29, 5.91it/s, loss=2.666e+01]
Image optimization: 12%|#2 | 25/200 [00:04<00:29, 5.91it/s, loss=2.655e+01]
Image optimization: 13%|#3 | 26/200 [00:04<00:29, 5.92it/s, loss=2.644e+01]
Image optimization: 14%|#3 | 27/200 [00:04<00:29, 5.94it/s, loss=2.633e+01]
Image optimization: 14%|#4 | 28/200 [00:04<00:28, 5.94it/s, loss=2.624e+01]
Image optimization: 14%|#4 | 29/200 [00:04<00:28, 5.91it/s, loss=2.615e+01]
Image optimization: 15%|#5 | 30/200 [00:05<00:28, 5.90it/s, loss=2.607e+01]
Image optimization: 16%|#5 | 31/200 [00:05<00:28, 5.90it/s, loss=2.600e+01]
Image optimization: 16%|#6 | 32/200 [00:05<00:28, 5.87it/s, loss=2.593e+01]
Image optimization: 16%|#6 | 33/200 [00:05<00:28, 5.91it/s, loss=2.586e+01]
Image optimization: 17%|#7 | 34/200 [00:05<00:27, 5.93it/s, loss=2.580e+01]
Image optimization: 18%|#7 | 35/200 [00:05<00:28, 5.87it/s, loss=2.574e+01]
Image optimization: 18%|#8 | 36/200 [00:06<00:27, 5.86it/s, loss=2.568e+01]
Image optimization: 18%|#8 | 37/200 [00:06<00:27, 5.83it/s, loss=2.562e+01]
Image optimization: 19%|#9 | 38/200 [00:06<00:27, 5.85it/s, loss=2.557e+01]
Image optimization: 20%|#9 | 39/200 [00:06<00:27, 5.85it/s, loss=2.552e+01]
Image optimization: 20%|## | 40/200 [00:06<00:27, 5.84it/s, loss=2.548e+01]
Image optimization: 20%|## | 41/200 [00:06<00:27, 5.86it/s, loss=2.544e+01]
Image optimization: 21%|##1 | 42/200 [00:07<00:27, 5.82it/s, loss=2.540e+01]
Image optimization: 22%|##1 | 43/200 [00:07<00:26, 5.84it/s, loss=2.536e+01]
Image optimization: 22%|##2 | 44/200 [00:07<00:26, 5.80it/s, loss=2.532e+01]
Image optimization: 22%|##2 | 45/200 [00:07<00:26, 5.81it/s, loss=2.528e+01]
Image optimization: 23%|##3 | 46/200 [00:07<00:26, 5.79it/s, loss=2.524e+01]
Image optimization: 24%|##3 | 47/200 [00:07<00:26, 5.81it/s, loss=2.521e+01]
Image optimization: 24%|##4 | 48/200 [00:08<00:26, 5.79it/s, loss=2.518e+01]
Image optimization: 24%|##4 | 49/200 [00:08<00:25, 5.81it/s, loss=2.514e+01]
Image optimization: 25%|##5 | 50/200 [00:08<00:25, 5.77it/s, loss=2.511e+01]
Image optimization: 26%|##5 | 51/200 [00:08<00:25, 5.79it/s, loss=2.508e+01]
Image optimization: 26%|##6 | 52/200 [00:08<00:25, 5.76it/s, loss=2.505e+01]
Image optimization: 26%|##6 | 53/200 [00:09<00:25, 5.78it/s, loss=2.502e+01]
Image optimization: 27%|##7 | 54/200 [00:09<00:25, 5.74it/s, loss=2.499e+01]
Image optimization: 28%|##7 | 55/200 [00:09<00:25, 5.74it/s, loss=2.497e+01]
Image optimization: 28%|##8 | 56/200 [00:09<00:25, 5.76it/s, loss=2.494e+01]
Image optimization: 28%|##8 | 57/200 [00:09<00:24, 5.74it/s, loss=2.492e+01]
Image optimization: 29%|##9 | 58/200 [00:09<00:24, 5.76it/s, loss=2.489e+01]
Image optimization: 30%|##9 | 59/200 [00:10<00:24, 5.74it/s, loss=2.487e+01]
Image optimization: 30%|### | 60/200 [00:10<00:24, 5.75it/s, loss=2.484e+01]
Image optimization: 30%|### | 61/200 [00:10<00:24, 5.70it/s, loss=2.482e+01]
Image optimization: 31%|###1 | 62/200 [00:10<00:24, 5.69it/s, loss=2.480e+01]
Image optimization: 32%|###1 | 63/200 [00:10<00:24, 5.67it/s, loss=2.478e+01]
Image optimization: 32%|###2 | 64/200 [00:10<00:23, 5.71it/s, loss=2.476e+01]
Image optimization: 32%|###2 | 65/200 [00:11<00:23, 5.69it/s, loss=2.474e+01]
Image optimization: 33%|###3 | 66/200 [00:11<00:23, 5.67it/s, loss=2.472e+01]
Image optimization: 34%|###3 | 67/200 [00:11<00:23, 5.69it/s, loss=2.470e+01]
Image optimization: 34%|###4 | 68/200 [00:11<00:23, 5.68it/s, loss=2.468e+01]
Image optimization: 34%|###4 | 69/200 [00:11<00:23, 5.65it/s, loss=2.466e+01]
Image optimization: 35%|###5 | 70/200 [00:12<00:22, 5.67it/s, loss=2.465e+01]
Image optimization: 36%|###5 | 71/200 [00:12<00:22, 5.67it/s, loss=2.463e+01]
Image optimization: 36%|###6 | 72/200 [00:12<00:22, 5.64it/s, loss=2.461e+01]
Image optimization: 36%|###6 | 73/200 [00:12<00:22, 5.65it/s, loss=2.460e+01]
Image optimization: 37%|###7 | 74/200 [00:12<00:22, 5.62it/s, loss=2.459e+01]
Image optimization: 38%|###7 | 75/200 [00:12<00:22, 5.60it/s, loss=2.457e+01]
Image optimization: 38%|###8 | 76/200 [00:13<00:22, 5.61it/s, loss=2.456e+01]
Image optimization: 38%|###8 | 77/200 [00:13<00:21, 5.60it/s, loss=2.454e+01]
Image optimization: 39%|###9 | 78/200 [00:13<00:21, 5.61it/s, loss=2.453e+01]
Image optimization: 40%|###9 | 79/200 [00:13<00:21, 5.59it/s, loss=2.451e+01]
Image optimization: 40%|#### | 80/200 [00:13<00:21, 5.57it/s, loss=2.450e+01]
Image optimization: 40%|#### | 81/200 [00:13<00:21, 5.56it/s, loss=2.449e+01]
Image optimization: 41%|####1 | 82/200 [00:14<00:21, 5.55it/s, loss=2.447e+01]
Image optimization: 42%|####1 | 83/200 [00:14<00:21, 5.57it/s, loss=2.446e+01]
Image optimization: 42%|####2 | 84/200 [00:14<00:20, 5.57it/s, loss=2.445e+01]
Image optimization: 42%|####2 | 85/200 [00:14<00:20, 5.57it/s, loss=2.444e+01]
Image optimization: 43%|####3 | 86/200 [00:14<00:20, 5.54it/s, loss=2.443e+01]
Image optimization: 44%|####3 | 87/200 [00:15<00:20, 5.53it/s, loss=2.442e+01]
Image optimization: 44%|####4 | 88/200 [00:15<00:20, 5.53it/s, loss=2.441e+01]
Image optimization: 44%|####4 | 89/200 [00:15<00:20, 5.54it/s, loss=2.439e+01]
Image optimization: 45%|####5 | 90/200 [00:15<00:19, 5.53it/s, loss=2.438e+01]
Image optimization: 46%|####5 | 91/200 [00:15<00:19, 5.52it/s, loss=2.437e+01]
Image optimization: 46%|####6 | 92/200 [00:15<00:19, 5.52it/s, loss=2.436e+01]
Image optimization: 46%|####6 | 93/200 [00:16<00:19, 5.52it/s, loss=2.435e+01]
Image optimization: 47%|####6 | 94/200 [00:16<00:19, 5.51it/s, loss=2.434e+01]
Image optimization: 48%|####7 | 95/200 [00:16<00:19, 5.51it/s, loss=2.433e+01]
Image optimization: 48%|####8 | 96/200 [00:16<00:18, 5.52it/s, loss=2.432e+01]
Image optimization: 48%|####8 | 97/200 [00:16<00:18, 5.53it/s, loss=2.431e+01]
Image optimization: 49%|####9 | 98/200 [00:17<00:18, 5.49it/s, loss=2.430e+01]
Image optimization: 50%|####9 | 99/200 [00:17<00:18, 5.50it/s, loss=2.429e+01]
Image optimization: 50%|##### | 100/200 [00:17<00:18, 5.48it/s, loss=2.428e+01]
Image optimization: 50%|##### | 101/200 [00:17<00:18, 5.48it/s, loss=2.427e+01]
Image optimization: 51%|#####1 | 102/200 [00:17<00:17, 5.48it/s, loss=2.427e+01]
Image optimization: 52%|#####1 | 103/200 [00:17<00:17, 5.46it/s, loss=2.426e+01]
Image optimization: 52%|#####2 | 104/200 [00:18<00:17, 5.48it/s, loss=2.425e+01]
Image optimization: 52%|#####2 | 105/200 [00:18<00:17, 5.46it/s, loss=2.424e+01]
Image optimization: 53%|#####3 | 106/200 [00:18<00:17, 5.48it/s, loss=2.423e+01]
Image optimization: 54%|#####3 | 107/200 [00:18<00:16, 5.47it/s, loss=2.423e+01]
Image optimization: 54%|#####4 | 108/200 [00:18<00:16, 5.46it/s, loss=2.422e+01]
Image optimization: 55%|#####4 | 109/200 [00:19<00:16, 5.47it/s, loss=2.421e+01]
Image optimization: 55%|#####5 | 110/200 [00:19<00:16, 5.47it/s, loss=2.421e+01]
Image optimization: 56%|#####5 | 111/200 [00:19<00:16, 5.45it/s, loss=2.420e+01]
Image optimization: 56%|#####6 | 112/200 [00:19<00:16, 5.46it/s, loss=2.419e+01]
Image optimization: 56%|#####6 | 113/200 [00:19<00:15, 5.48it/s, loss=2.419e+01]
Image optimization: 57%|#####6 | 114/200 [00:19<00:15, 5.49it/s, loss=2.418e+01]
Image optimization: 57%|#####7 | 115/200 [00:20<00:15, 5.45it/s, loss=2.417e+01]
Image optimization: 58%|#####8 | 116/200 [00:20<00:15, 5.48it/s, loss=2.416e+01]
Image optimization: 58%|#####8 | 117/200 [00:20<00:15, 5.46it/s, loss=2.416e+01]
Image optimization: 59%|#####8 | 118/200 [00:20<00:14, 5.49it/s, loss=2.415e+01]
Image optimization: 60%|#####9 | 119/200 [00:20<00:14, 5.47it/s, loss=2.414e+01]
Image optimization: 60%|###### | 120/200 [00:21<00:14, 5.44it/s, loss=2.414e+01]
Image optimization: 60%|###### | 121/200 [00:21<00:14, 5.44it/s, loss=2.413e+01]
Image optimization: 61%|######1 | 122/200 [00:21<00:14, 5.47it/s, loss=2.412e+01]
Image optimization: 62%|######1 | 123/200 [00:21<00:14, 5.47it/s, loss=2.412e+01]
Image optimization: 62%|######2 | 124/200 [00:21<00:13, 5.48it/s, loss=2.411e+01]
Image optimization: 62%|######2 | 125/200 [00:21<00:13, 5.49it/s, loss=2.411e+01]
Image optimization: 63%|######3 | 126/200 [00:22<00:13, 5.45it/s, loss=2.410e+01]
Image optimization: 64%|######3 | 127/200 [00:22<00:13, 5.47it/s, loss=2.409e+01]
Image optimization: 64%|######4 | 128/200 [00:22<00:13, 5.46it/s, loss=2.409e+01]
Image optimization: 64%|######4 | 129/200 [00:22<00:13, 5.46it/s, loss=2.408e+01]
Image optimization: 65%|######5 | 130/200 [00:22<00:12, 5.48it/s, loss=2.408e+01]
Image optimization: 66%|######5 | 131/200 [00:23<00:12, 5.46it/s, loss=2.407e+01]
Image optimization: 66%|######6 | 132/200 [00:23<00:12, 5.47it/s, loss=2.406e+01]
Image optimization: 66%|######6 | 133/200 [00:23<00:12, 5.44it/s, loss=2.406e+01]
Image optimization: 67%|######7 | 134/200 [00:23<00:12, 5.46it/s, loss=2.405e+01]
Image optimization: 68%|######7 | 135/200 [00:23<00:11, 5.45it/s, loss=2.405e+01]
Image optimization: 68%|######8 | 136/200 [00:24<00:11, 5.47it/s, loss=2.404e+01]
Image optimization: 68%|######8 | 137/200 [00:24<00:11, 5.49it/s, loss=2.404e+01]
Image optimization: 69%|######9 | 138/200 [00:24<00:11, 5.48it/s, loss=2.403e+01]
Image optimization: 70%|######9 | 139/200 [00:24<00:11, 5.45it/s, loss=2.403e+01]
Image optimization: 70%|####### | 140/200 [00:24<00:11, 5.45it/s, loss=2.402e+01]
Image optimization: 70%|####### | 141/200 [00:24<00:10, 5.45it/s, loss=2.402e+01]
Image optimization: 71%|#######1 | 142/200 [00:25<00:10, 5.47it/s, loss=2.401e+01]
Image optimization: 72%|#######1 | 143/200 [00:25<00:10, 5.48it/s, loss=2.401e+01]
Image optimization: 72%|#######2 | 144/200 [00:25<00:10, 5.47it/s, loss=2.400e+01]
Image optimization: 72%|#######2 | 145/200 [00:25<00:10, 5.46it/s, loss=2.400e+01]
Image optimization: 73%|#######3 | 146/200 [00:25<00:09, 5.47it/s, loss=2.399e+01]
Image optimization: 74%|#######3 | 147/200 [00:26<00:09, 5.48it/s, loss=2.399e+01]
Image optimization: 74%|#######4 | 148/200 [00:26<00:09, 5.46it/s, loss=2.398e+01]
Image optimization: 74%|#######4 | 149/200 [00:26<00:09, 5.46it/s, loss=2.398e+01]
Image optimization: 75%|#######5 | 150/200 [00:26<00:09, 5.48it/s, loss=2.398e+01]
Image optimization: 76%|#######5 | 151/200 [00:26<00:08, 5.47it/s, loss=2.397e+01]
Image optimization: 76%|#######6 | 152/200 [00:26<00:08, 5.47it/s, loss=2.397e+01]
Image optimization: 76%|#######6 | 153/200 [00:27<00:08, 5.47it/s, loss=2.396e+01]
Image optimization: 77%|#######7 | 154/200 [00:27<00:08, 5.47it/s, loss=2.396e+01]
Image optimization: 78%|#######7 | 155/200 [00:27<00:08, 5.46it/s, loss=2.395e+01]
Image optimization: 78%|#######8 | 156/200 [00:27<00:08, 5.47it/s, loss=2.395e+01]
Image optimization: 78%|#######8 | 157/200 [00:27<00:07, 5.50it/s, loss=2.395e+01]
Image optimization: 79%|#######9 | 158/200 [00:28<00:07, 5.46it/s, loss=2.394e+01]
Image optimization: 80%|#######9 | 159/200 [00:28<00:07, 5.49it/s, loss=2.394e+01]
Image optimization: 80%|######## | 160/200 [00:28<00:07, 5.47it/s, loss=2.393e+01]
Image optimization: 80%|######## | 161/200 [00:28<00:07, 5.47it/s, loss=2.393e+01]
Image optimization: 81%|########1 | 162/200 [00:28<00:06, 5.47it/s, loss=2.393e+01]
Image optimization: 82%|########1 | 163/200 [00:28<00:06, 5.48it/s, loss=2.392e+01]
Image optimization: 82%|########2 | 164/200 [00:29<00:06, 5.47it/s, loss=2.392e+01]
Image optimization: 82%|########2 | 165/200 [00:29<00:06, 5.48it/s, loss=2.392e+01]
Image optimization: 83%|########2 | 166/200 [00:29<00:06, 5.45it/s, loss=2.391e+01]
Image optimization: 84%|########3 | 167/200 [00:29<00:06, 5.46it/s, loss=2.391e+01]
Image optimization: 84%|########4 | 168/200 [00:29<00:05, 5.46it/s, loss=2.391e+01]
Image optimization: 84%|########4 | 169/200 [00:30<00:05, 5.47it/s, loss=2.390e+01]
Image optimization: 85%|########5 | 170/200 [00:30<00:05, 5.46it/s, loss=2.390e+01]
Image optimization: 86%|########5 | 171/200 [00:30<00:05, 5.46it/s, loss=2.390e+01]
Image optimization: 86%|########6 | 172/200 [00:30<00:05, 5.47it/s, loss=2.389e+01]
Image optimization: 86%|########6 | 173/200 [00:30<00:04, 5.44it/s, loss=2.389e+01]
Image optimization: 87%|########7 | 174/200 [00:30<00:04, 5.46it/s, loss=2.388e+01]
Image optimization: 88%|########7 | 175/200 [00:31<00:04, 5.46it/s, loss=2.388e+01]
Image optimization: 88%|########8 | 176/200 [00:31<00:04, 5.45it/s, loss=2.388e+01]
Image optimization: 88%|########8 | 177/200 [00:31<00:04, 5.47it/s, loss=2.387e+01]
Image optimization: 89%|########9 | 178/200 [00:31<00:04, 5.48it/s, loss=2.387e+01]
Image optimization: 90%|########9 | 179/200 [00:31<00:03, 5.48it/s, loss=2.386e+01]
Image optimization: 90%|######### | 180/200 [00:32<00:03, 5.46it/s, loss=2.386e+01]
Image optimization: 90%|######### | 181/200 [00:32<00:03, 5.46it/s, loss=2.386e+01]
Image optimization: 91%|#########1| 182/200 [00:32<00:03, 5.45it/s, loss=2.385e+01]
Image optimization: 92%|#########1| 183/200 [00:32<00:03, 5.48it/s, loss=2.385e+01]
Image optimization: 92%|#########2| 184/200 [00:32<00:02, 5.46it/s, loss=2.385e+01]
Image optimization: 92%|#########2| 185/200 [00:32<00:02, 5.44it/s, loss=2.384e+01]
Image optimization: 93%|#########3| 186/200 [00:33<00:02, 5.44it/s, loss=2.384e+01]
Image optimization: 94%|#########3| 187/200 [00:33<00:02, 5.45it/s, loss=2.384e+01]
Image optimization: 94%|#########3| 188/200 [00:33<00:02, 5.46it/s, loss=2.383e+01]
Image optimization: 94%|#########4| 189/200 [00:33<00:02, 5.48it/s, loss=2.383e+01]
Image optimization: 95%|#########5| 190/200 [00:33<00:01, 5.47it/s, loss=2.383e+01]
Image optimization: 96%|#########5| 191/200 [00:34<00:01, 5.46it/s, loss=2.382e+01]
Image optimization: 96%|#########6| 192/200 [00:34<00:01, 5.49it/s, loss=2.382e+01]
Image optimization: 96%|#########6| 193/200 [00:34<00:01, 5.48it/s, loss=2.382e+01]
Image optimization: 97%|#########7| 194/200 [00:34<00:01, 5.47it/s, loss=2.381e+01]
Image optimization: 98%|#########7| 195/200 [00:34<00:00, 5.45it/s, loss=2.381e+01]
Image optimization: 98%|#########8| 196/200 [00:34<00:00, 5.44it/s, loss=2.381e+01]
Image optimization: 98%|#########8| 197/200 [00:35<00:00, 5.47it/s, loss=2.381e+01]
Image optimization: 99%|#########9| 198/200 [00:35<00:00, 5.44it/s, loss=2.380e+01]
Image optimization: 100%|#########9| 199/200 [00:35<00:00, 5.45it/s, loss=2.380e+01]
Image optimization: 100%|##########| 200/200 [00:35<00:00, 5.44it/s, loss=2.380e+01]
Image optimization: 100%|##########| 200/200 [00:35<00:00, 5.60it/s, loss=2.380e+01]
Pyramid: 100%|##########| 2/2 [00:44<00:00, 24.65s/it]
Pyramid: 100%|##########| 2/2 [00:44<00:00, 22.28s/it]
182 elapsed_time_with_pyramid = stop_with_pyramid - start_with_pyramid
183 relative_decrease = 1.0 - elapsed_time_with_pyramid / elapsed_time_without_pyramid
184 print(
185 f"With pyramid the optimization took {elapsed_time_with_pyramid:.0f} seconds. "
186 f"This is a {relative_decrease:.0%} decrease."
187 )
Out:
With pyramid the optimization took 45 seconds. This is a 39% decrease.
With the coarse-to-fine architecture of the image pyramid, the stylization of the blurry background branches is reduced leaving the mosaic pattern mostly intact. On top of this quality improvement the execution time is significantly lower while performing the same number of steps.
Total running time of the script: ( 2 minutes 0.953 seconds)
Estimated memory usage: 1976 MB
Note
Click here to download the full example code
Model optimization¶
This example showcases how an NST based on model optimization can be performed in
pystiche
. It closely follows the
official PyTorch example
which in turn is based on [JAL16].
We start this example by importing everything we need and setting the device we will be working on.
16 import contextlib
17 import os
18 import time
19 from collections import OrderedDict
20 from os import path
21
22 import torch
23 from torch import hub, nn
24 from torch.nn.functional import interpolate
25
26 import pystiche
27 from pystiche import demo, enc, loss, optim
28 from pystiche.image import show_image
29 from pystiche.misc import get_device
30
31 print(f"I'm working with pystiche=={pystiche.__version__}")
32
33 device = get_device()
34 print(f"I'm working with {device}")
Out:
I'm working with pystiche==1.1.0.dev44+gd9e3fd8
I'm working with cuda
Transformer¶
In contrast to image optimization, for model optimization we need to define a transformer that, after it is trained, performs the stylization. In general different architectures are possible ([JAL16, ULVL16]). For this example we use an encoder-decoder architecture.
Before we define the transformer, we create some helper modules to reduce the clutter.
In the decoder we need to upsample the image. While it is possible to achieve this
with a ConvTranspose2d
, it was found that traditional upsampling
followed by a standard convolution
produces fewer artifacts. Thus,
we create an module that wraps torch.nn.functional.interpolate()
.
57 class Interpolate(nn.Module):
58 def __init__(self, scale_factor=1.0, mode="nearest"):
59 super().__init__()
60 self.scale_factor = scale_factor
61 self.mode = mode
62
63 def forward(self, input):
64 return interpolate(input, scale_factor=self.scale_factor, mode=self.mode,)
65
66 def extra_repr(self):
67 extras = []
68 if self.scale_factor:
69 extras.append(f"scale_factor={self.scale_factor}")
70 if self.mode != "nearest":
71 extras.append(f"mode={self.mode}")
72 return ", ".join(extras)
For the transformer architecture we will be using, we need to define a convolution module with some additional capabilities. In particular, it needs to be able to
optionally upsample the input,
pad the input in order for the convolution to be size-preserving,
optionally normalize the output, and
optionally pass the output through an activation function.
Note
Instead of BatchNorm2d
we use InstanceNorm2d
to normalize the output since it gives better results for NST [UVL16].
90 class Conv(nn.Module):
91 def __init__(
92 self,
93 in_channels,
94 out_channels,
95 kernel_size,
96 stride=1,
97 upsample=False,
98 norm=True,
99 activation=True,
100 ):
101 super().__init__()
102 self.upsample = Interpolate(scale_factor=stride) if upsample else None
103 self.pad = nn.ReflectionPad2d(kernel_size // 2)
104 self.conv = nn.Conv2d(
105 in_channels, out_channels, kernel_size, stride=1 if upsample else stride
106 )
107 self.norm = nn.InstanceNorm2d(out_channels, affine=True) if norm else None
108 self.activation = nn.ReLU() if activation else None
109
110 def forward(self, input):
111 if self.upsample:
112 input = self.upsample(input)
113
114 output = self.conv(self.pad(input))
115
116 if self.norm:
117 output = self.norm(output)
118 if self.activation:
119 output = self.activation(output)
120
121 return output
It is common practice to append a few residual blocks after the initial convolutions to the encoder to enable it to learn more descriptive features.
129 class Residual(nn.Module):
130 def __init__(self, channels):
131 super().__init__()
132 self.conv1 = Conv(channels, channels, kernel_size=3)
133 self.conv2 = Conv(channels, channels, kernel_size=3, activation=False)
134
135 def forward(self, input):
136 output = self.conv2(self.conv1(input))
137 return output + input
It can be useful for the training to transform the input into another value range, for example from \(\newcommand{\parentheses}[1]{\left( #1 \right)} \newcommand{\brackets}[1]{\left[ #1 \right]} \newcommand{\mean}[1][]{\overline{\sum #1}} \newcommand{\fun}[2]{\text{#1}\of{#2}} \newcommand{\of}[1]{\parentheses{#1}} \newcommand{\dotproduct}[2]{\left\langle #1 , #2 \right\rangle} \newcommand{\openinterval}[2]{\parentheses{#1, #2}} \newcommand{\closedinterval}[2]{\brackets{#1, #2}} \closedinterval{0}{1}\) to \(\newcommand{\parentheses}[1]{\left( #1 \right)} \newcommand{\brackets}[1]{\left[ #1 \right]} \newcommand{\mean}[1][]{\overline{\sum #1}} \newcommand{\fun}[2]{\text{#1}\of{#2}} \newcommand{\of}[1]{\parentheses{#1}} \newcommand{\dotproduct}[2]{\left\langle #1 , #2 \right\rangle} \newcommand{\openinterval}[2]{\parentheses{#1, #2}} \newcommand{\closedinterval}[2]{\brackets{#1, #2}} \closedinterval{0}{255}\).
145 class FloatToUint8Range(nn.Module):
146 def forward(self, input):
147 return input * 255.0
148
149
150 class Uint8ToFloatRange(nn.Module):
151 def forward(self, input):
152 return input / 255.0
Finally, we can put all pieces together.
Note
You can access this transformer through pystiche.demo.transformer()
.
163 class Transformer(nn.Module):
164 def __init__(self):
165 super().__init__()
166 self.encoder = nn.Sequential(
167 Conv(3, 32, kernel_size=9),
168 Conv(32, 64, kernel_size=3, stride=2),
169 Conv(64, 128, kernel_size=3, stride=2),
170 Residual(128),
171 Residual(128),
172 Residual(128),
173 Residual(128),
174 Residual(128),
175 )
176 self.decoder = nn.Sequential(
177 Conv(128, 64, kernel_size=3, stride=2, upsample=True),
178 Conv(64, 32, kernel_size=3, stride=2, upsample=True),
179 Conv(32, 3, kernel_size=9, norm=False, activation=False),
180 )
181
182 self.preprocessor = FloatToUint8Range()
183 self.postprocessor = Uint8ToFloatRange()
184
185 def forward(self, input):
186 input = self.preprocessor(input)
187 output = self.decoder(self.encoder(input))
188 return self.postprocessor(output)
189
190
191 transformer = Transformer().to(device)
192 print(transformer)
Out:
Transformer(
(encoder): Sequential(
(0): Conv(
(pad): ReflectionPad2d((4, 4, 4, 4))
(conv): Conv2d(3, 32, kernel_size=(9, 9), stride=(1, 1))
(norm): InstanceNorm2d(32, eps=1e-05, momentum=0.1, affine=True, track_running_stats=False)
(activation): ReLU()
)
(1): Conv(
(pad): ReflectionPad2d((1, 1, 1, 1))
(conv): Conv2d(32, 64, kernel_size=(3, 3), stride=(2, 2))
(norm): InstanceNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=False)
(activation): ReLU()
)
(2): Conv(
(pad): ReflectionPad2d((1, 1, 1, 1))
(conv): Conv2d(64, 128, kernel_size=(3, 3), stride=(2, 2))
(norm): InstanceNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=False)
(activation): ReLU()
)
(3): Residual(
(conv1): Conv(
(pad): ReflectionPad2d((1, 1, 1, 1))
(conv): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1))
(norm): InstanceNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=False)
(activation): ReLU()
)
(conv2): Conv(
(pad): ReflectionPad2d((1, 1, 1, 1))
(conv): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1))
(norm): InstanceNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=False)
)
)
(4): Residual(
(conv1): Conv(
(pad): ReflectionPad2d((1, 1, 1, 1))
(conv): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1))
(norm): InstanceNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=False)
(activation): ReLU()
)
(conv2): Conv(
(pad): ReflectionPad2d((1, 1, 1, 1))
(conv): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1))
(norm): InstanceNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=False)
)
)
(5): Residual(
(conv1): Conv(
(pad): ReflectionPad2d((1, 1, 1, 1))
(conv): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1))
(norm): InstanceNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=False)
(activation): ReLU()
)
(conv2): Conv(
(pad): ReflectionPad2d((1, 1, 1, 1))
(conv): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1))
(norm): InstanceNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=False)
)
)
(6): Residual(
(conv1): Conv(
(pad): ReflectionPad2d((1, 1, 1, 1))
(conv): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1))
(norm): InstanceNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=False)
(activation): ReLU()
)
(conv2): Conv(
(pad): ReflectionPad2d((1, 1, 1, 1))
(conv): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1))
(norm): InstanceNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=False)
)
)
(7): Residual(
(conv1): Conv(
(pad): ReflectionPad2d((1, 1, 1, 1))
(conv): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1))
(norm): InstanceNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=False)
(activation): ReLU()
)
(conv2): Conv(
(pad): ReflectionPad2d((1, 1, 1, 1))
(conv): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1))
(norm): InstanceNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=False)
)
)
)
(decoder): Sequential(
(0): Conv(
(upsample): Interpolate(scale_factor=2)
(pad): ReflectionPad2d((1, 1, 1, 1))
(conv): Conv2d(128, 64, kernel_size=(3, 3), stride=(1, 1))
(norm): InstanceNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=False)
(activation): ReLU()
)
(1): Conv(
(upsample): Interpolate(scale_factor=2)
(pad): ReflectionPad2d((1, 1, 1, 1))
(conv): Conv2d(64, 32, kernel_size=(3, 3), stride=(1, 1))
(norm): InstanceNorm2d(32, eps=1e-05, momentum=0.1, affine=True, track_running_stats=False)
(activation): ReLU()
)
(2): Conv(
(pad): ReflectionPad2d((4, 4, 4, 4))
(conv): Conv2d(32, 3, kernel_size=(9, 9), stride=(1, 1))
)
)
(preprocessor): FloatToUint8Range()
(postprocessor): Uint8ToFloatRange()
)
Perceptual loss¶
Although model optimization is a different paradigm, the perceptual_loss
is the
same as for image optimization.
Note
In some implementations, such as the PyTorch example and [JAL16], one can
observe that the gram_matrix()
, used as style representation, is not
only normalized by the height and width of the feature map, but also by the number
of channels. If used together with a mse_loss()
, the
normalization is performed twice. While this is unintended, it affects the training.
In order to keep the other hyper parameters on par with the PyTorch example, we also
adopt this change here.
212 multi_layer_encoder = enc.vgg16_multi_layer_encoder()
213
214 content_layer = "relu2_2"
215 content_encoder = multi_layer_encoder.extract_encoder(content_layer)
216 content_weight = 1e5
217 content_loss = loss.FeatureReconstructionLoss(
218 content_encoder, score_weight=content_weight
219 )
220
221
222 class GramOperator(loss.GramLoss):
223 def enc_to_repr(self, enc: torch.Tensor) -> torch.Tensor:
224 repr = super().enc_to_repr(enc)
225 num_channels = repr.size()[1]
226 return repr / num_channels
227
228
229 style_layers = ("relu1_2", "relu2_2", "relu3_3", "relu4_3")
230 style_weight = 1e10
231 style_loss = loss.MultiLayerEncodingLoss(
232 multi_layer_encoder,
233 style_layers,
234 lambda encoder, layer_weight: GramOperator(encoder, score_weight=layer_weight),
235 layer_weights="sum",
236 score_weight=style_weight,
237 )
238
239 perceptual_loss = loss.PerceptualLoss(content_loss, style_loss)
240 perceptual_loss = perceptual_loss.to(device)
241 print(perceptual_loss)
Out:
Downloading: "https://download.pytorch.org/models/vgg16-397923af.pth" to /home/runnerx/.cache/torch/hub/checkpoints/vgg16-397923af.pth
0%| | 0.00/528M [00:00<?, ?B/s]
3%|2 | 14.6M/528M [00:00<00:03, 153MB/s]
6%|5 | 30.3M/528M [00:00<00:03, 160MB/s]
9%|8 | 45.8M/528M [00:00<00:03, 161MB/s]
12%|#1 | 61.5M/528M [00:00<00:03, 162MB/s]
15%|#4 | 77.1M/528M [00:00<00:02, 163MB/s]
18%|#7 | 92.7M/528M [00:00<00:02, 163MB/s]
21%|## | 108M/528M [00:00<00:02, 163MB/s]
23%|##3 | 124M/528M [00:00<00:02, 163MB/s]
26%|##6 | 140M/528M [00:00<00:02, 163MB/s]
29%|##9 | 155M/528M [00:01<00:02, 164MB/s]
32%|###2 | 171M/528M [00:01<00:02, 164MB/s]
35%|###5 | 186M/528M [00:01<00:02, 164MB/s]
38%|###8 | 202M/528M [00:01<00:02, 164MB/s]
41%|####1 | 218M/528M [00:01<00:01, 164MB/s]
44%|####4 | 233M/528M [00:01<00:01, 164MB/s]
47%|####7 | 249M/528M [00:01<00:01, 163MB/s]
50%|##### | 264M/528M [00:01<00:01, 163MB/s]
53%|#####3 | 280M/528M [00:01<00:01, 163MB/s]
56%|#####6 | 296M/528M [00:01<00:01, 163MB/s]
59%|#####8 | 311M/528M [00:02<00:01, 163MB/s]
62%|######1 | 327M/528M [00:02<00:01, 163MB/s]
65%|######4 | 342M/528M [00:02<00:01, 163MB/s]
68%|######7 | 358M/528M [00:02<00:01, 163MB/s]
71%|####### | 374M/528M [00:02<00:01, 157MB/s]
74%|#######3 | 389M/528M [00:02<00:00, 160MB/s]
77%|#######6 | 405M/528M [00:02<00:00, 162MB/s]
80%|#######9 | 421M/528M [00:02<00:00, 163MB/s]
83%|########2 | 437M/528M [00:02<00:00, 164MB/s]
86%|########5 | 453M/528M [00:02<00:00, 165MB/s]
89%|########8 | 469M/528M [00:03<00:00, 166MB/s]
92%|#########1| 485M/528M [00:03<00:00, 166MB/s]
95%|#########4| 501M/528M [00:03<00:00, 166MB/s]
98%|#########7| 517M/528M [00:03<00:00, 166MB/s]
100%|##########| 528M/528M [00:03<00:00, 164MB/s]
PerceptualLoss(
(content_loss): FeatureReconstructionLoss(
score_weight=100000
(encoder): VGGMultiLayerEncoder(layer=relu2_2, arch=vgg16, framework=torch)
)
(style_loss): MultiLayerEncodingLoss(
encoder=VGGMultiLayerEncoder(arch=vgg16, framework=torch), score_weight=1e+10
(relu1_2): GramOperator()
(relu2_2): GramOperator()
(relu3_3): GramOperator()
(relu4_3): GramOperator()
)
)
Training¶
In a first step we load the style image that will be used to train the
transformer
.
251 images = demo.images()
252 size = 500
253
254 style_image = images["paint"].read(size=size, device=device)
255 show_image(style_image)
The training of the transformer
is performed similar to other models in PyTorch.
In every optimization step a batch of content images is drawn from a dataset, which
serve as input for the transformer as well as content_image
for the
perceptual_loss
. While the style_image
only has to be set once, the
content_image
has to be reset in every iteration step.
While this can be done with a boilerplate optimization loop, pystiche
provides
multi_epoch_model_optimization()
that handles the above for you.
Note
If the perceptual_loss
is a PerceptualLoss
, as is the
case here, the update of the content_image
is performed automatically. If that
is not the case or you need more complex update behavior, you need to specify a
criterion_update_fn
.
Note
If you do not specify an optimizer
, the
default_model_optimizer()
, i.e. Adam
is
used.
282 def train(
283 transformer, dataset, batch_size=4, epochs=2,
284 ):
285 if dataset is None:
286 raise RuntimeError(
287 "You forgot to define a dataset. For example, "
288 "you can use any image dataset from torchvision.datasets."
289 )
290
291 from torch.utils.data import DataLoader
292
293 image_loader = DataLoader(dataset, batch_size=batch_size)
294
295 perceptual_loss.set_style_image(style_image)
296
297 return optim.multi_epoch_model_optimization(
298 image_loader, transformer.train(), perceptual_loss, epochs=epochs,
299 )
Depending on the dataset and your setup the training can take a couple of hours. To avoid this, we provide transformer weights that were trained with the scheme above.
Note
If you want to perform the training yourself, set
use_pretrained_transformer=False
. If you do, you also need to replace
dataset = None
below with the dataset you want to train on.
Note
The weights of the provided transformer were trained with the
2014 training images of the
COCO dataset. The training was performed for
num_epochs=2
and batch_size=4
. Each image was center-cropped to
256 x 256
pixels.
320 use_pretrained_transformer = True
321 checkpoint = "example_transformer.pth"
322
323 if use_pretrained_transformer:
324 if path.exists(checkpoint):
325 state_dict = torch.load(checkpoint)
326 else:
327 # Unfortunately, torch.hub.load_state_dict_from_url has no option to disable
328 # printing the downloading process. Since this would clutter the output, we
329 # suppress it completely.
330 @contextlib.contextmanager
331 def suppress_output():
332 with open(os.devnull, "w") as devnull:
333 with contextlib.redirect_stdout(devnull), contextlib.redirect_stderr(
334 devnull
335 ):
336 yield
337
338 url = "https://download.pystiche.org/models/example_transformer.pth"
339
340 with suppress_output():
341 state_dict = hub.load_state_dict_from_url(url)
342
343 transformer.load_state_dict(state_dict)
344 else:
345 dataset = None
346 transformer = train(transformer, dataset)
347
348 state_dict = OrderedDict(
349 [
350 (name, parameter.detach().cpu())
351 for name, parameter in transformer.state_dict().items()
352 ]
353 )
354 torch.save(state_dict, checkpoint)
Neural Style Transfer¶
In order to perform the NST, we load an image we want to stylize.
363 input_image = images["bird1"].read(size=size, device=device)
364 show_image(input_image)
After the transformer is trained we can now perform an NST with a single forward pass.
To do this, the transformer
is simply called with the input_image
.
371 transformer.eval()
372
373 start = time.time()
374
375 with torch.no_grad():
376 output_image = transformer(input_image)
377
378 stop = time.time()
379
380 show_image(output_image, title="Output image")
Compared to NST via image optimization, the stylization is performed multiple orders of magnitudes faster. Given capable hardware, NST via model optimization enables real-time stylization for example of a video feed.
389 print(f"The stylization took {(stop - start) * 1e3:.0f} milliseconds.")
Out:
The stylization took 6 milliseconds.
Total running time of the script: ( 0 minutes 6.538 seconds)
Estimated memory usage: 340 MB
Command-line interface¶
For simple tasks pystiche
provides a command-line interface (CLI). For example, a
simple NST with the builtin demo images can be performed with:
$pystiche bird1 paint
In version
$pystiche --version
1.1.0.dev45+g4ce30cb
the CLI looks like this:
$pystiche --help
usage: pystiche [-h] [-V] [-v] [-o OUTPUT_IMAGE] [-n NUM_STEPS] [-d DEVICE]
[-s STARTING_POINT]
[--multi-layer-encoder MULTI_LAYER_ENCODER]
[--content-loss CONTENT_LOSS]
[--content-layers CONTENT_LAYERS]
[--content-size CONTENT_SIZE]
[--content-weight CONTENT_WEIGHT] [--style-loss STYLE_LOSS]
[--style-layers STYLE_LAYERS] [--style-size STYLE_SIZE]
[--style-weight STYLE_WEIGHT]
content_image style_image
Performs simple Neural Style Transfers (NSTs) with image optimization. For
more complex tasks, have a look at the Python API at
https://docs.pystiche.org.
positional arguments:
content_image Image containing the content for the style transfer.
Can be a path to an image file or the name of a
pystiche.demo image.
style_image Image containing the style for the style transfer. Can
be a path to an image file or the name of a
pystiche.demo image.
optional arguments:
-h, --help Show this message and exit.
-V, --version Show pystiche's version and exit.
-v, --verbose Print additional information to STDOUT.
-o OUTPUT_IMAGE, --output-image OUTPUT_IMAGE
Path, the output image will be saved to. If omitted,
the output image will be saved to
'pystiche_{timestamp}.jpg' in the current directory.
-n NUM_STEPS, --num-steps NUM_STEPS
Number of optimization steps. Defaults to '500'.
-d DEVICE, --device DEVICE
Device, the optimization is performed on. If
available, defaults to 'cuda' and falls back to 'cpu'
otherwise.
-s STARTING_POINT, --starting-point STARTING_POINT
Starting point of the optimization. Can be 'content'
(default) to start from the content image, 'random' to
start from a white noise image, a path to an image
file, or a name of a pystiche.demo image.
--multi-layer-encoder MULTI_LAYER_ENCODER, --mle MULTI_LAYER_ENCODER
Can be any pretrained multi-layer encoder from
pystiche.enc, e.g. 'vgg19' (default) or 'alexnet'.
Content options:
--content-loss CONTENT_LOSS, --cl CONTENT_LOSS
Can be any comparison loss from pystiche.loss, e.g.
'FeatureReconstruction' (default).
--content-layers CONTENT_LAYERS, --cla CONTENT_LAYERS
Layers of the MULTI_LAYER_ENCODER used to encode the
content representation, e.g. 'relu4_2' (default).
Multiple layers can be given as a comma separated
list.
--content-size CONTENT_SIZE, --cs CONTENT_SIZE
Size in pixels the CONTENT_IMAGE will be resized to
before the optimization, e.g. '500' (default).
--content-weight CONTENT_WEIGHT, --cw CONTENT_WEIGHT
Optimization weight for the CONTENT_LOSS, e.g. '1e0'
(default). Higher values lead to more focus on the
content.
Style options:
--style-loss STYLE_LOSS, --sl STYLE_LOSS
Can be any comparison loss from pystiche.loss, e.g.
'Gram' (default) or 'MRF'.
--style-layers STYLE_LAYERS, --sla STYLE_LAYERS
Layers of the MULTI_LAYER_ENCODER used to encode the
content representation. Multiple layers can be given
as a comma separated list, e.g.
'relu1_1,relu2_1,relu3_1,relu4_1,relu5_1' (default).
--style-size STYLE_SIZE, --ss STYLE_SIZE
Size in pixels the STYLE_IMAGE will be resized to
before the optimization, e.g. '500' (default).
--style-weight STYLE_WEIGHT, --sw STYLE_WEIGHT
Optimization weight for the STYLE_LOSS, e.g. '1e3'
(default). Higher values lead to more focus on the
style.
Package reference¶
pystiche
¶
- pystiche.home()¶
Local directory to save downloaded images and guides. Defaults to
~/.cache/pystiche
but can be overwritten with thePYSTICHE_HOME
environment variable.- Return type
Objects¶
- class pystiche.ComplexObject¶
Object with a complex representation. See
pystiche.misc.build_complex_obj_repr()
for details.- _named_children()¶
- Yields
Internal named children.
Note
If subclassed, this method should yield the named children of the superclass alongside yielding the new named children.
- _properties()¶
-
Note
If subclassed, this method should integrate the new properties in the properties of the superclass.
- class pystiche.LossDict(losses=())¶
Hierarchic dictionary of scalar
torch.Tensor
losses. Levels are seperated by"."
in the names.- __mul__(other)¶
Multiplies all entries with a scalar.
- Parameters
other (
SupportsFloat
) – Scalar multiplier.- Return type
- __setitem__(name, loss)¶
Add a named loss to the entries.
- Parameters
- Raises
TypeError – If loss is
torch.Tensor
but isn’t scalar.- Return type
- aggregate(max_depth)¶
Aggregate all entries up to a given maximum depth.
- Parameters
max_depth (
int
) – If0
returns sum of all entries as scalartorch.Tensor
.- Return type
- backward(*args, **kwargs)¶
Computes the gradient of all entries with respect to the graph leaves. See
torch.Tensor.backward()
for details.- Return type
- class pystiche.Module(named_children=None, indexed_children=None)¶
torch.nn.Module
with the enhanced representation options ofpystiche.ComplexObject
.- Parameters
Note
named_children
andindexed_children
are mutually exclusive parameters.
Math¶
- pystiche.nonnegsqrt(x)¶
Safely calculates the square-root of a non-negative input
\[\newcommand{\parentheses}[1]{\left( #1 \right)} \newcommand{\brackets}[1]{\left[ #1 \right]} \newcommand{\mean}[1][]{\overline{\sum #1}} \newcommand{\fun}[2]{\text{#1}\of{#2}} \newcommand{\of}[1]{\parentheses{#1}} \newcommand{\dotproduct}[2]{\left\langle #1 , #2 \right\rangle} \newcommand{\openinterval}[2]{\parentheses{#1, #2}} \newcommand{\closedinterval}[2]{\brackets{#1, #2}} \begin{split}\fun{nonnegsqrt}{x} = \begin{cases} \sqrt{x} &\quad\text{if } x \ge 0 \\ 0 &\quad\text{otherwise} \end{cases}\end{split}\]Note
This operation is useful in situations where the input tensor is strictly non-negative from a theoretical standpoint, but might be negative due to numerical instabilities.
- pystiche.gram_matrix(x, normalize=False)¶
Calculates the channel-wise Gram matrix of a batched input tensor.
Given a tensor \(\newcommand{\parentheses}[1]{\left( #1 \right)} \newcommand{\brackets}[1]{\left[ #1 \right]} \newcommand{\mean}[1][]{\overline{\sum #1}} \newcommand{\fun}[2]{\text{#1}\of{#2}} \newcommand{\of}[1]{\parentheses{#1}} \newcommand{\dotproduct}[2]{\left\langle #1 , #2 \right\rangle} \newcommand{\openinterval}[2]{\parentheses{#1, #2}} \newcommand{\closedinterval}[2]{\brackets{#1, #2}} x\) of shape \(\newcommand{\parentheses}[1]{\left( #1 \right)} \newcommand{\brackets}[1]{\left[ #1 \right]} \newcommand{\mean}[1][]{\overline{\sum #1}} \newcommand{\fun}[2]{\text{#1}\of{#2}} \newcommand{\of}[1]{\parentheses{#1}} \newcommand{\dotproduct}[2]{\left\langle #1 , #2 \right\rangle} \newcommand{\openinterval}[2]{\parentheses{#1, #2}} \newcommand{\closedinterval}[2]{\brackets{#1, #2}} B \times C \times N_1 \times \dots \times N_D\) each element of the single-sample Gram matrix \(\newcommand{\parentheses}[1]{\left( #1 \right)} \newcommand{\brackets}[1]{\left[ #1 \right]} \newcommand{\mean}[1][]{\overline{\sum #1}} \newcommand{\fun}[2]{\text{#1}\of{#2}} \newcommand{\of}[1]{\parentheses{#1}} \newcommand{\dotproduct}[2]{\left\langle #1 , #2 \right\rangle} \newcommand{\openinterval}[2]{\parentheses{#1, #2}} \newcommand{\closedinterval}[2]{\brackets{#1, #2}} G_{b,c_1 c_2}\) with \(\newcommand{\parentheses}[1]{\left( #1 \right)} \newcommand{\brackets}[1]{\left[ #1 \right]} \newcommand{\mean}[1][]{\overline{\sum #1}} \newcommand{\fun}[2]{\text{#1}\of{#2}} \newcommand{\of}[1]{\parentheses{#1}} \newcommand{\dotproduct}[2]{\left\langle #1 , #2 \right\rangle} \newcommand{\openinterval}[2]{\parentheses{#1, #2}} \newcommand{\closedinterval}[2]{\brackets{#1, #2}} b \in 1,\dots,B\) and \(\newcommand{\parentheses}[1]{\left( #1 \right)} \newcommand{\brackets}[1]{\left[ #1 \right]} \newcommand{\mean}[1][]{\overline{\sum #1}} \newcommand{\fun}[2]{\text{#1}\of{#2}} \newcommand{\of}[1]{\parentheses{#1}} \newcommand{\dotproduct}[2]{\left\langle #1 , #2 \right\rangle} \newcommand{\openinterval}[2]{\parentheses{#1, #2}} \newcommand{\closedinterval}[2]{\brackets{#1, #2}} c_1,\,c_2 \in 1,\dots,C\) is calculated by
\[\newcommand{\parentheses}[1]{\left( #1 \right)} \newcommand{\brackets}[1]{\left[ #1 \right]} \newcommand{\mean}[1][]{\overline{\sum #1}} \newcommand{\fun}[2]{\text{#1}\of{#2}} \newcommand{\of}[1]{\parentheses{#1}} \newcommand{\dotproduct}[2]{\left\langle #1 , #2 \right\rangle} \newcommand{\openinterval}[2]{\parentheses{#1, #2}} \newcommand{\closedinterval}[2]{\brackets{#1, #2}} G_{b,c_1 c_2} = \dotproduct{\fun{vec}{x_{b, c_1}}}{\fun{vec}{x_{b, c_2}}}\]where \(\newcommand{\parentheses}[1]{\left( #1 \right)} \newcommand{\brackets}[1]{\left[ #1 \right]} \newcommand{\mean}[1][]{\overline{\sum #1}} \newcommand{\fun}[2]{\text{#1}\of{#2}} \newcommand{\of}[1]{\parentheses{#1}} \newcommand{\dotproduct}[2]{\left\langle #1 , #2 \right\rangle} \newcommand{\openinterval}[2]{\parentheses{#1, #2}} \newcommand{\closedinterval}[2]{\brackets{#1, #2}} \dotproduct{\cdot}{\cdot}\) denotes the dot product and \(\newcommand{\parentheses}[1]{\left( #1 \right)} \newcommand{\brackets}[1]{\left[ #1 \right]} \newcommand{\mean}[1][]{\overline{\sum #1}} \newcommand{\fun}[2]{\text{#1}\of{#2}} \newcommand{\of}[1]{\parentheses{#1}} \newcommand{\dotproduct}[2]{\left\langle #1 , #2 \right\rangle} \newcommand{\openinterval}[2]{\parentheses{#1, #2}} \newcommand{\closedinterval}[2]{\brackets{#1, #2}} \fun{vec}{\cdot}\) denotes the vectorization function .
- Parameters
x (
Tensor
) – Input tensor of shape \(\newcommand{\parentheses}[1]{\left( #1 \right)} \newcommand{\brackets}[1]{\left[ #1 \right]} \newcommand{\mean}[1][]{\overline{\sum #1}} \newcommand{\fun}[2]{\text{#1}\of{#2}} \newcommand{\of}[1]{\parentheses{#1}} \newcommand{\dotproduct}[2]{\left\langle #1 , #2 \right\rangle} \newcommand{\openinterval}[2]{\parentheses{#1, #2}} \newcommand{\closedinterval}[2]{\brackets{#1, #2}} B \times C \times N_1 \times \dots \times N_D\)normalize (
bool
) – If True, normalizes the Gram matrix \(\newcommand{\parentheses}[1]{\left( #1 \right)} \newcommand{\brackets}[1]{\left[ #1 \right]} \newcommand{\mean}[1][]{\overline{\sum #1}} \newcommand{\fun}[2]{\text{#1}\of{#2}} \newcommand{\of}[1]{\parentheses{#1}} \newcommand{\dotproduct}[2]{\left\langle #1 , #2 \right\rangle} \newcommand{\openinterval}[2]{\parentheses{#1, #2}} \newcommand{\closedinterval}[2]{\brackets{#1, #2}} G\) by \(\newcommand{\parentheses}[1]{\left( #1 \right)} \newcommand{\brackets}[1]{\left[ #1 \right]} \newcommand{\mean}[1][]{\overline{\sum #1}} \newcommand{\fun}[2]{\text{#1}\of{#2}} \newcommand{\of}[1]{\parentheses{#1}} \newcommand{\dotproduct}[2]{\left\langle #1 , #2 \right\rangle} \newcommand{\openinterval}[2]{\parentheses{#1, #2}} \newcommand{\closedinterval}[2]{\brackets{#1, #2}} \prod\limits_{d=1}^{D} N_d\) to keep the value range similar for different sized inputs. Defaults toFalse
.
- Return type
- Returns
Channel-wise Gram matrix G of shape \(\newcommand{\parentheses}[1]{\left( #1 \right)} \newcommand{\brackets}[1]{\left[ #1 \right]} \newcommand{\mean}[1][]{\overline{\sum #1}} \newcommand{\fun}[2]{\text{#1}\of{#2}} \newcommand{\of}[1]{\parentheses{#1}} \newcommand{\dotproduct}[2]{\left\langle #1 , #2 \right\rangle} \newcommand{\openinterval}[2]{\parentheses{#1, #2}} \newcommand{\closedinterval}[2]{\brackets{#1, #2}} B \times C \times C\).
- pystiche.cosine_similarity(x1, x2, eps=1e-08, batched_input=None)¶
Calculates the cosine similarity between the samples of
x1
andx2
.- Parameters
x1 (
Tensor
) – First input of shape \(\newcommand{\parentheses}[1]{\left( #1 \right)} \newcommand{\brackets}[1]{\left[ #1 \right]} \newcommand{\mean}[1][]{\overline{\sum #1}} \newcommand{\fun}[2]{\text{#1}\of{#2}} \newcommand{\of}[1]{\parentheses{#1}} \newcommand{\dotproduct}[2]{\left\langle #1 , #2 \right\rangle} \newcommand{\openinterval}[2]{\parentheses{#1, #2}} \newcommand{\closedinterval}[2]{\brackets{#1, #2}} B \times S_1 \times N_1 \times \dots \times N_D\).x2 (
Tensor
) – Second input of shape \(\newcommand{\parentheses}[1]{\left( #1 \right)} \newcommand{\brackets}[1]{\left[ #1 \right]} \newcommand{\mean}[1][]{\overline{\sum #1}} \newcommand{\fun}[2]{\text{#1}\of{#2}} \newcommand{\of}[1]{\parentheses{#1}} \newcommand{\dotproduct}[2]{\left\langle #1 , #2 \right\rangle} \newcommand{\openinterval}[2]{\parentheses{#1, #2}} \newcommand{\closedinterval}[2]{\brackets{#1, #2}} B \times S_2 \times N_1 \times \dots \times N_D\).eps (
float
) – Small value to avoid zero division. Defaults to1e-8
.batched_input (
Optional
[bool
]) – IfFalse
, treat the first dimension of the inputs as sample dimension, i.e. \(\newcommand{\parentheses}[1]{\left( #1 \right)} \newcommand{\brackets}[1]{\left[ #1 \right]} \newcommand{\mean}[1][]{\overline{\sum #1}} \newcommand{\fun}[2]{\text{#1}\of{#2}} \newcommand{\of}[1]{\parentheses{#1}} \newcommand{\dotproduct}[2]{\left\langle #1 , #2 \right\rangle} \newcommand{\openinterval}[2]{\parentheses{#1, #2}} \newcommand{\closedinterval}[2]{\brackets{#1, #2}} S \times N_1 \times \dots \times N_D\). Defaults toTrue
.
- Return type
- Returns
Similarity matrix of shape \(\newcommand{\parentheses}[1]{\left( #1 \right)} \newcommand{\brackets}[1]{\left[ #1 \right]} \newcommand{\mean}[1][]{\overline{\sum #1}} \newcommand{\fun}[2]{\text{#1}\of{#2}} \newcommand{\of}[1]{\parentheses{#1}} \newcommand{\dotproduct}[2]{\left\langle #1 , #2 \right\rangle} \newcommand{\openinterval}[2]{\parentheses{#1, #2}} \newcommand{\closedinterval}[2]{\brackets{#1, #2}} B \times S_1 \times S_2\) in which every element represents the cosine similarity between the corresponding samples \(\newcommand{\parentheses}[1]{\left( #1 \right)} \newcommand{\brackets}[1]{\left[ #1 \right]} \newcommand{\mean}[1][]{\overline{\sum #1}} \newcommand{\fun}[2]{\text{#1}\of{#2}} \newcommand{\of}[1]{\parentheses{#1}} \newcommand{\dotproduct}[2]{\left\langle #1 , #2 \right\rangle} \newcommand{\openinterval}[2]{\parentheses{#1, #2}} \newcommand{\closedinterval}[2]{\brackets{#1, #2}} S\) of
x1
andx2
. Ifbatched_input is False
, the output shape is \(\newcommand{\parentheses}[1]{\left( #1 \right)} \newcommand{\brackets}[1]{\left[ #1 \right]} \newcommand{\mean}[1][]{\overline{\sum #1}} \newcommand{\fun}[2]{\text{#1}\of{#2}} \newcommand{\of}[1]{\parentheses{#1}} \newcommand{\dotproduct}[2]{\left\langle #1 , #2 \right\rangle} \newcommand{\openinterval}[2]{\parentheses{#1, #2}} \newcommand{\closedinterval}[2]{\brackets{#1, #2}} S_1 \times S_2\)
pystiche.data
¶
- class pystiche.data.LocalImage(file, collect_local_guides=True, guides=None, transform=None, note=None)¶
- read(root=None, **read_image_kwargs)¶
Read the image from file with
pystiche.image.read_image()
and optionally applytransform
.- Parameters
root (
Optional
[str
]) – Optional root directory if the file is a relative path.**read_image_kwargs – Optional parameters passed to
pystiche.image.read_image()
.
- Return type
- class pystiche.data.LocalImageCollection(images)¶
- read(root=None, **read_image_kwargs)¶
Read the images from file.
- class pystiche.data.DownloadableImage(url, title=None, author=None, date=None, license=None, md5=None, file=None, guides=None, prefix_guide_files=True, transform=None, note=None)¶
- download(root=None, overwrite=False)¶
Download the image and if applicable the guides from their URL. If the correct MD5 checksum is known, it is verified first. If it checks out the file not re-downloaded.
- Parameters
root (
Optional
[str
]) – Optional root directory for the download if the file is a relative path. Defaults topystiche.home()
.overwrite (
bool
) – Overwrites files if they already exists or the MD5 checksum does not match. Defaults toFalse
.
- Return type
- static generate_file(url, title, author)¶
Generate a filename from the supplied information from the following scheme:
If
title
andauthor
areNone
, the ending ofurl
is used.If one of
title
orauthor
is notNone
, it is used as filename where spaces are replaced by underscores.If
title
andauthor
are not None, the filename is generated as above separating both path with double underscores.
- read(root=None, download=None, overwrite=False, **read_image_kwargs)¶
Read the image from file with
pystiche.image.read_image()
. If available thetransform
is applied afterwards.- Parameters
root (
Optional
[str
]) – Optional root directory if the file is a relative path. Defaults topystiche.home()
.download (
Optional
[bool
]) – IfTrue
, downloads the image first. Defaults toFalse
if the file already exists and the MD5 checksum is not known. Otherwise defaults toTrue
.overwrite (
bool
) – If downloaded, overwrites files if they already exists or the MD5 checksum does not match. Defaults toFalse
.**read_image_kwargs – Optional parameters passed to
pystiche.image.read_image()
.
- Return type
- class pystiche.data.DownloadableImageCollection(images)¶
- download(root=None, overwrite=False)¶
Download all images and if applicable their guides from their URLs. See
pystiche.data.DownloadableImage.download()
for details.- Parameters
root (
Optional
[str
]) – Optional root directory for the download if the file is a relative path. Defaults topystiche.home()
.overwrite (
bool
) – Overwrites files if they already exists or the MD5 checksum does not match. Defaults toFalse
.
- Return type
- read(root=None, download=None, overwrite=False, **read_image_kwargs)¶
Read the images from file. See
pystiche.data.DownloadableImage.read()
for details.- Parameters
root (
Optional
[str
]) – Optional root directory if the file is a relative path. Defaults topystiche.home()
.download (
Optional
[bool
]) – IfTrue
, downloads the image first. Defaults toFalse
if the file already exists and the MD5 checksum is not known. Otherwise defaults toTrue
.overwrite (
bool
) – If downloaded, overwrites files if they already exists or the MD5 checksum does not match. Defaults toFalse
.**read_image_kwargs – Optional parameters passed to
pystiche.image.read_image()
.
- Return type
- Returns
Dictionary with the name image pairs.
pystiche.demo
¶
- pystiche.demo.images()¶
Collection of images used in the usage examples.
- Return type
name |
image |
---|---|
bird1 |
|
bird2 |
|
castle |
|
church |
|
cliff |
|
mosaic |
|
paint |
- pystiche.demo.transformer()¶
Basic transformer for model-based optimization.
The transformer is compatible with the official PyTorch example which in turn is based on [JAL16]
- Return type
pystiche.enc
¶
- class pystiche.enc.Encoder(named_children=None, indexed_children=None)¶
ABC for all encoders. Invokes
Encoder.forward()
if called.- abstract forward(input)¶
Encodes the given input.
Note
This method has to be overwritten in every subclass.
- Return type
- class pystiche.enc.SequentialEncoder(modules)¶
Encoder that operates in sequential manner. Invokes
Encoder.forward()
if called.
- class pystiche.enc.MultiLayerEncoder(modules)¶
Sequential encoder with convenient access to intermediate layers.
- Parameters
modules (
Sequence
[Tuple
[str
,Module
]]) – Named modules that serve as basis for the encoding.
- __contains__(layer)¶
Is the layer part of the multi-layer encoder?
- encode(input, layers)¶
Encode the input on layers.
- extract_encoder(layer)¶
Extract a
SingleLayerEncoder
for the layer and register it.- Parameters
layer (
str
) – Layer.- Return type
- forward(input, layer=None, cache=None, to_cache=None)¶
Encode the input.
- Parameters
input (
Tensor
) – Input to be encoded.layer (
Optional
[str
]) – Layer on which theinput
should be encoded. If omitted, defaults to the last layer in the multi-layer encoder.cache (
Optional
[Dict
[str
,Tensor
]]) – Encoding cache. If omitted, defaults to the the internal cache.to_cache (
Optional
[Collection
[str
]]) – Layers, of which the encodings should be cached. If omitted, defaults toregistered_layers
.
Examples
>>> modules = [("conv", nn.Conv2d(3, 3, 3)), ("pool", nn.MaxPool2d(2))] >>> mle = pystiche.enc.MultiLayerEncoder(modules) >>> input = torch.rand(1, 3, 128, 128) >>> output = mle(input, "conv")
- Return type
- propagate_guide(guide, layers, method='simple', allow_empty=False)¶
Propagate the guide on the given layers.
- verify(layer)¶
Verifies that a layer is part of the multi-layer encoder.
- Parameters
layer (
str
) – Layer to be checked.- Raises
ValueError – If
layer
is not part of the multi-layer encoder.- Return type
- class pystiche.enc.SingleLayerEncoder(multi_layer_encoder, layer)¶
Encoder extracted from a
MultiLayerEncoder
that operates on a single layer. InvokesSingleLayerEncoder.forward()
if called.- multi_layer_encoder¶
Corresponding multi-layer encoder.
- layer¶
Encoding layer.
- forward(input)¶
Encode the given input on
SingleLayerEncoder.layer
ofSingleLayerEncoder.multi_layer_encoder
.- Parameters
input_image – Input image.
- Return type
- propagate_guide(guide)¶
Propagate the given guide on
SingleLayerEncoder.layer
ofSingleLayerEncoder.multi_layer_encoder
.
Models¶
- class pystiche.enc.ModelMultiLayerEncoder(pretrained=True, framework='torch', internal_preprocessing=True, allow_inplace=False)¶
Multi-layer encoder based on a pre-defined model.
- Parameters
pretrained (
bool
) – IfTrue
, loads builtin weights. Defaults toTrue
.framework (
str
) – Name of the framework that was used to train the builtin weights. Defaults to"torch"
.internal_preprocessing (
bool
) – IfTrue
, adds a preprocessing layer for the selectedframework
as first layer. Defaults toTrue
.allow_inplace (
bool
) –If
True
, allows inplace operations to reduce the memory requirement during the forward pass. Defaults toFalse
.Warning
After performing an inplace operation the encodings of the previous layer is no longer accessible. Only use this if you are sure that you do not need these encodings.
- abstract collect_modules(inplace)¶
Collect modules of a base model with more descriptive names.
- load_state_dict(state_dict, strict=True, map_names=True, framework='unknown')¶
Loads parameters and buffers from the
state_dict
.- Parameters
strict (
bool
) – Enforce matching keys instate_dict
and the internal states.map_names (
bool
) – IfTrue
, maps the names names instate_dict
of the underlying model to the more descriptive names generated bycollect_modules()
. Defaults toTrue
.framework (
str
) –Name of the framework that was used to train the weights in
state_dict
. Defaults to"unknown"
.Note
This has no effect on the behavior, but makes the representation of the
ModelMultiLayerEncoder
more descriptive.
- Return type
_IncompatibleKeys
- Returns
Named tuple with
missing_keys
andunexpected_keys
fields.
See also
- load_state_dict_from_url(framework, strict=True, map_names=True, check_hash=True, **kwargs)¶
Downloads and loads parameters and buffers trained with
framework
.- Parameters
framework (
str
) – Name of the framework that was used to train the weights of thestate_dict
.strict (
bool
) – Enforce matching keys instate_dict
and the internal states.map_names (
bool
) – IfTrue
, maps the names names instate_dict
of the underlying model to the more descriptive names generated bycollect_modules()
. Defaults toTrue
.check_hash (
bool
) – IfTrue
, checks if the hash postfix of the URL matches the SHA256 hash of the downloadedstate_dict
. Defaults toTrue
.kwargs (
Any
) – Optional arguments fortorch.hub.load_state_dict_from_url()
.
- Return type
- abstract state_dict_url(framework)¶
Select URL of a downloadable
state_dict
.- Parameters
framework (
str
) – Name of the framework that was used to train the weights.- Raises
RuntimeError – If no
state_dict
is available.- Return type
VGG¶
- class pystiche.enc.VGGMultiLayerEncoder(arch, **kwargs)¶
Multi-layer encoder based on
VGG
.The
VGG
architecture was introduced by Krizhevsky, Sutskever, and Hinton in [KSH12]- Parameters
arch (
str
) –VGG
architecture. Has to match"vgg(11|13|16|19)(_bn)?"
.pretrained – If
True
, loads builtin weights. Defaults toTrue
.framework – Name of the framework that was used to train the builtin weights. Defaults to
"torch"
.kwargs (
Any
) – Optional arguments ofModelMultiLayerEncoder
.
- Raises
RuntimeError – If
pretrained is True
and no weights are available for the combination ofarch
andframework
.
- pystiche.enc.vgg11_multi_layer_encoder(**kwargs)¶
Multi-layer encoder based on
VGG
11.The
VGG
architecture was introduced by Krizhevsky, Sutskever, and Hinton in [KSH12]. VGG11 corresponds to configurationA
in the paper.- Parameters
kwargs (
Any
) – Optional arguments ofVGGMultiLayerEncoder
.- Return type
- pystiche.enc.vgg11_bn_multi_layer_encoder(**kwargs)¶
Multi-layer encoder based on
VGG
11 with batch normalization.The
VGG
architecture was introduced by Krizhevsky, Sutskever, and Hinton in [KSH12]. VGG11 corresponds to configurationA
in the paper.- Parameters
kwargs (
Any
) – Optional arguments ofVGGMultiLayerEncoder
.- Return type
- pystiche.enc.vgg13_multi_layer_encoder(**kwargs)¶
Multi-layer encoder based on
VGG
13.The
VGG
architecture was introduced by Krizhevsky, Sutskever, and Hinton in [KSH12]. VGG13 corresponds to configurationB
in the paper.- Parameters
kwargs (
Any
) – Optional arguments ofVGGMultiLayerEncoder
.- Return type
- pystiche.enc.vgg13_bn_multi_layer_encoder(**kwargs)¶
Multi-layer encoder based on
VGG
13 with batch normalization.The
VGG
architecture was introduced by Krizhevsky, Sutskever, and Hinton in [KSH12]. VGG13 corresponds to configurationB
in the paper.- Parameters
kwargs (
Any
) – Optional arguments ofVGGMultiLayerEncoder
.- Return type
- pystiche.enc.vgg16_multi_layer_encoder(**kwargs)¶
Multi-layer encoder based on
VGG
16.The
VGG
architecture was introduced by Krizhevsky, Sutskever, and Hinton in [KSH12]. VGG16 corresponds to configurationD
in the paper.- Parameters
kwargs (
Any
) – Optional arguments ofVGGMultiLayerEncoder
.- Return type
- pystiche.enc.vgg16_bn_multi_layer_encoder(**kwargs)¶
Multi-layer encoder based on
VGG
16 with batch normalization.The
VGG
architecture was introduced by Krizhevsky, Sutskever, and Hinton in [KSH12]. VGG16 corresponds to configurationD
in the paper.- Parameters
kwargs (
Any
) – Optional arguments ofVGGMultiLayerEncoder
.- Return type
- pystiche.enc.vgg19_multi_layer_encoder(**kwargs)¶
Multi-layer encoder based on
VGG
19.The
VGG
architecture was introduced by Krizhevsky, Sutskever, and Hinton in [KSH12]. VGG19 corresponds to configurationE
in the paper.- Parameters
kwargs (
Any
) – Optional arguments ofVGGMultiLayerEncoder
.- Return type
- pystiche.enc.vgg19_bn_multi_layer_encoder(**kwargs)¶
Multi-layer encoder based on
VGG
19 with batch normalization.The
VGG
architecture was introduced by Krizhevsky, Sutskever, and Hinton in [KSH12]. VGG19 corresponds to configurationE
in the paper.- Parameters
kwargs (
Any
) – Optional arguments ofVGGMultiLayerEncoder
.- Return type
AlexNet¶
- class pystiche.enc.AlexNetMultiLayerEncoder(pretrained=True, framework='torch', internal_preprocessing=True, allow_inplace=False)¶
Multi-layer encoder based on
AlexNet
.The
AlexNet
architecture was introduced by Krizhevsky, Sutskever, and Hinton in [KSH12].- Parameters
pretrained (
bool
) – IfTrue
, loads builtin weights. Defaults toTrue
.framework (
str
) – Name of the framework that was used to train the builtin weights. Defaults to"torch"
.kwargs – Optional arguments of
ModelMultiLayerEncoder
.
- Raises
RuntimeError – If
pretrained
and no weights are available for theframework` –
- pystiche.enc.alexnet_multi_layer_encoder(**kwargs)¶
Multi-layer encoder based on
AlexNet
.The
AlexNet
architecture was introduced by Krizhevsky, Sutskever, and Hinton in [KSH12].- Parameters
kwargs (
Any
) – Optional arguments ofAlexNetMultiLayerEncoder
.- Return type
pystiche.image
¶
Utilities¶
- pystiche.image.edge_to_image_size(edge_size, aspect_ratio, edge='short')¶
I/O¶
- pystiche.image.read_image(file, device='cpu', make_batched=True, size=None, interpolation_mode='bilinear')¶
Read an image from file with
PIL.Image
and return it asTensor
.- Parameters
file (
str
) – Path to image file to be read.device (
Union
[device
,str
]) – Device that the image is transferred to. Defaults to CPU.make_batched (
bool
) – IfTrue
, a fake batch dimension is added to the image.size (
Optional
[Union
[int
]]) – Optional size the image is resized to.interpolation_mode (
str
) – Interpolation mode that is used to perform the optional resizing. Valid modes are"nearest"
,"bilinear"
, and"bicubic"
. Defaults to"bilinear"
.
- Return type
- pystiche.image.write_image(image, file, mode=None, **save_kwargs)¶
Write a
Tensor
image to a file withPIL.Image
.- Parameters
image (
Tensor
) – Image to be written.file (
str
) – Path to image file.mode (
Optional
[str
]) – Optional image mode. See the Pillow documentation for details.**save_kwargs – Other parameters that are passed to
PIL.Image.Image.save()
.
- Return type
- pystiche.image.show_image(image, title=None, mode=None, size=None, interpolation_mode='bilinear')¶
Show an image and optionally read it from file first.
Note
show_image
usesmatplotlib.pyplot.imshow()
as primary means to show images. If that is not available the nativePIL.Image.Image.show()
is used as a fallback.- Parameters
image (
Union
[Tensor
,str
]) – Image to be shown. Ifstr
this is treated as a path to an image and is read byread_image()
.Optional image mode. See the Pillow documentation for details.
size (
Optional
[Union
[int
]]) – Optional size the image is resized to.interpolation_mode (
str
) – Interpolation mode that is used to perform the optional resizing. Valid modes are"nearest"
,"bilinear"
, and"bicubic"
. Defaults to"bilinear"
.
- Return type
Guides¶
- pystiche.image.verify_guides(guides, verify_coverage=True, verify_overlap=True)¶
Verify if guides cover the whole canvas and if they do not overlap with each other.
- Parameters
- Raises
RuntimeError – If at least on check is not successful.
- Return type
- pystiche.image.read_guides(dir, device='cpu', make_batched=True, size=None, interpolation_mode='nearest')¶
Read all guides from a directory using
read_image()
and return them as dictionary. The filename without extensions is used as region key.- Parameters
dir (
str
) – Path to root directory of the guide files.device (
Union
[device
,str
]) – Device that the guides are transferred to. Defaults to CPU.make_batched (
bool
) – IfTrue
, a fake batch dimension is added to every guide.size (
Optional
[Union
[int
]]) – Optional size the guides are resized to.interpolation_mode (
str
) – Interpolation mode that is used to perform the optional resizing. Valid modes are"nearest"
,"bilinear"
, and"bicubic"
. Defaults to"nearest"
.
- Return type
- pystiche.image.write_guides(guides, dir, ext='.png', mode='L', **save_kwargs)¶
Write guides to directory using
write_image()
. The region key is used as filename.- Parameters
dir (
str
) – Path to root directory of the guide files.ext (
str
) – Extension that is appended to the filename. Defaults to".png"
.mode (
str
) –Optional image mode. See the Pillow documentation for details. Defaults to
"L"
.**save_kwargs – Other parameters that are passed to
PIL.Image.Image.save()
.
- Return type
- pystiche.image.guides_to_segmentation(guides, color_map=None)¶
Combines multiple guides into one segmentation image.
- pystiche.image.segmentation_to_guides(seg, region_map=None)¶
Splits a segmentation image in multiple guides.
pystiche.loss
¶
- class pystiche.loss.Loss(*, encoder=None, input_guide=None, score_weight=1.0)¶
Bases:
pystiche.core._modules.Module
,abc.ABC
Abstract base class for all losses.
- abstract forward(input_image)¶
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.
- class pystiche.loss.RegularizationLoss(*, encoder=None, input_guide=None, score_weight=1.0)¶
Bases:
pystiche.loss._loss.Loss
Abstract base class for all regularization losses.
- class pystiche.loss.ComparisonLoss(*, encoder=None, input_guide=None, target_image=None, target_guide=None, score_weight=1.0)¶
Bases:
pystiche.loss._loss.Loss
Abstract base class for all comparison losses.
Container¶
- class pystiche.loss.LossContainer(named_losses, *, input_guide=None, target_image=None, target_guide=None, score_weight=1.0)¶
Generic container for
Loss
’es.If called with an image, it will be passes it to all immediate losses and returns a
pystiche.LossDict
scaled withscore_weight
.
- class pystiche.loss.MultiLayerEncodingLoss(mle, layers, encoding_loss_fn, *, layer_weights='mean', input_guide=None, target_image=None, target_guide=None, score_weight=1.0)¶
Convenience container for multiple
Loss
’es operating on differentlayers
of the samepystiche.enc.MultiLayerEncoder
.- Parameters
mle (
MultiLayerEncoder
) – Multi-layer encoder.layers (
Sequence
[str
]) – Layers of themle
that the children losses operate on.encoding_loss_fn (
Callable
[[Encoder
,float
],Loss
]) – Callable that returns a loss given apystiche.enc.SingleLayerEncoder
extracted from themle
and its corresponding layer weight.layer_weights (
Union
[str
,Sequence
[float
]]) – Weights passed toencoding_loss_fn
. If"sum"
, each layer weight is set to1.0
. If"mean"
, each layer weight is set to1.0 / len(layers)
. If sequence offloat``s its length has to match ``layers
’ length. Defaults to"mean"
.score_weight (
float
) – Score weight of the loss. Defaults to1.0
.
Examples
>>> mle = pystiche.enc.vgg19_multi_layer_encoder() >>> layers = ("relu1_1", "relu2_1", "relu3_1", "relu4_1", "relu5_1") >>> loss = pystiche.loss.MultiLayerEncodingLoss( ... mle, ... layers, ... lambda encoder, layer_weight: pystiche.loss.GramLoss( ... encoder, score_weight=layer_weight ... ), ... ) >>> input = torch.rand(2, 3, 256, 256) >>> target = torch.rand(2, 3, 256, 256) >>> loss.set_target_image(target) >>> score = loss(input)
- class pystiche.loss.MultiRegionLoss(regions, region_loss_fn, *, region_weights='sum', input_guide=None, target_image=None, target_guide=None, score_weight=1.0)¶
Convenience container for multiple
Loss
’es operating in differentregions
.- Parameters
region_loss_fn (
Callable
[[str
,float
],Loss
]) – Callable that returns a children loss given a region and its corresponding weight.region_weights (
Union
[str
,Sequence
[float
]]) – Weights passed toregion_loss_fn
. If"sum"
, each region weight is set to1.0
. If"mean"
, each region weight is set to1.0 / len(layers)
. If sequence offloat``s its length has to match ``regions
’ length. Defaults to"mean"
.score_weight (
float
) – Score weight of the loss. Defaults to1.0
.
Examples
>>> mle = pystiche.enc.vgg19_multi_layer_encoder() >>> layers = ("relu1_1", "relu2_1", "relu3_1", "relu4_1", "relu5_1") >>> def encoding_loss_fn(encoder, layer_weight): ... return pystiche.loss.GramLoss(encoder, score_weight=layer_weight) >>> regions = ("sky", "landscape") >>> def region_loss_fn(region, region_weight): ... return pystiche.loss.MultiLayerEncodingLoss( ... mle, ... layers, ... encoding_loss_fn, ... score_weight=region_weight, ... ) >>> loss = pystiche.loss.MultiRegionLoss(regions, region_loss_fn) >>> loss.set_regional_target_image("sky", torch.rand(2, 3, 256, 256)) >>> loss.set_regional_target_image("landscape", torch.rand(2, 3, 256, 256)) >>> input = torch.rand(2, 3, 256, 256) >>> score = loss(input)
- set_regional_input_guide(region, guide)¶
Invokes
set_input_guide()
on the operator of the givenregion
.- Parameters
region (
str
) – Region.guide (
Tensor
) – Input guide of shape \(\newcommand{\parentheses}[1]{\left( #1 \right)} \newcommand{\brackets}[1]{\left[ #1 \right]} \newcommand{\mean}[1][]{\overline{\sum #1}} \newcommand{\fun}[2]{\text{#1}\of{#2}} \newcommand{\of}[1]{\parentheses{#1}} \newcommand{\dotproduct}[2]{\left\langle #1 , #2 \right\rangle} \newcommand{\openinterval}[2]{\parentheses{#1, #2}} \newcommand{\closedinterval}[2]{\brackets{#1, #2}} 1 \times 1 \times H \times W\).
- Return type
- set_regional_target_image(region, image, guide=None)¶
Invokes
set_target_image()
on the operator of the givenregion
.- Parameters
region (
str
) – Region.image (
Tensor
) – Input guide of shape \(\newcommand{\parentheses}[1]{\left( #1 \right)} \newcommand{\brackets}[1]{\left[ #1 \right]} \newcommand{\mean}[1][]{\overline{\sum #1}} \newcommand{\fun}[2]{\text{#1}\of{#2}} \newcommand{\of}[1]{\parentheses{#1}} \newcommand{\dotproduct}[2]{\left\langle #1 , #2 \right\rangle} \newcommand{\openinterval}[2]{\parentheses{#1, #2}} \newcommand{\closedinterval}[2]{\brackets{#1, #2}} B \times C \times H \times W\).
- Return type
- class pystiche.loss.PerceptualLoss(content_loss, style_loss, regularization=None, *, content_image=None, content_guide=None, style_image=None, style_guide=None)¶
Perceptual loss comprising content and style loss as well as optionally a regularization.
- Parameters
content_loss (
Union
[ComparisonLoss
,LossContainer
]) – Content loss.style_loss (
Union
[ComparisonLoss
,LossContainer
]) – Guided style loss.regularization (
Optional
[RegularizationLoss
]) – Optional regularization.content_image (
Optional
[Tensor
]) – Content image applied as target image to thecontent_loss
.content_guide (
Optional
[Tensor
]) – Content guide applied as input guide to thestyle_loss
.style_image (
Optional
[Tensor
]) – Style image applied as target image tostyle_loss
.style_guide (
Optional
[Tensor
]) – Style guide applied as target image tostyle_loss
.
- regional_content_guide(region=None)¶
Regional content guide.
- regional_style_image(region=None)¶
Regional style image.
- set_content_guide(guide, *, region=None)¶
Sets the content guide.
- set_style_image(image, *, guide=None, region=None)¶
Sets the style image and guide.
Regularization¶
- class pystiche.loss.TotalVariationLoss(*, exponent=2.0, input_guide=None, score_weight=1.0)¶
Bases:
pystiche.loss._loss.RegularizationLoss
The total variation loss is a regularizer used to suppress checkerboard artifacts by penalizing the gradient of the image. It is calculated by
\[\newcommand{\parentheses}[1]{\left( #1 \right)} \newcommand{\brackets}[1]{\left[ #1 \right]} \newcommand{\mean}[1][]{\overline{\sum #1}} \newcommand{\fun}[2]{\text{#1}\of{#2}} \newcommand{\of}[1]{\parentheses{#1}} \newcommand{\dotproduct}[2]{\left\langle #1 , #2 \right\rangle} \newcommand{\openinterval}[2]{\parentheses{#1, #2}} \newcommand{\closedinterval}[2]{\brackets{#1, #2}} \mean[\limits_{i,j}] \parentheses{\parentheses{x_{i,j+1} - x_{i,j}}^2 + \parentheses{x_{i+1,j} - x_{i,j}}^2}^{\frac{\beta}{2}}\]where \(\newcommand{\parentheses}[1]{\left( #1 \right)} \newcommand{\brackets}[1]{\left[ #1 \right]} \newcommand{\mean}[1][]{\overline{\sum #1}} \newcommand{\fun}[2]{\text{#1}\of{#2}} \newcommand{\of}[1]{\parentheses{#1}} \newcommand{\dotproduct}[2]{\left\langle #1 , #2 \right\rangle} \newcommand{\openinterval}[2]{\parentheses{#1, #2}} \newcommand{\closedinterval}[2]{\brackets{#1, #2}} x\) denotes the image and \(\newcommand{\parentheses}[1]{\left( #1 \right)} \newcommand{\brackets}[1]{\left[ #1 \right]} \newcommand{\mean}[1][]{\overline{\sum #1}} \newcommand{\fun}[2]{\text{#1}\of{#2}} \newcommand{\of}[1]{\parentheses{#1}} \newcommand{\dotproduct}[2]{\left\langle #1 , #2 \right\rangle} \newcommand{\openinterval}[2]{\parentheses{#1, #2}} \newcommand{\closedinterval}[2]{\brackets{#1, #2}} i,j\) index a specific pixel.
Note
Opposed to the paper, the implementation calculates the grand average \(\newcommand{\parentheses}[1]{\left( #1 \right)} \newcommand{\brackets}[1]{\left[ #1 \right]} \newcommand{\mean}[1][]{\overline{\sum #1}} \newcommand{\fun}[2]{\text{#1}\of{#2}} \newcommand{\of}[1]{\parentheses{#1}} \newcommand{\dotproduct}[2]{\left\langle #1 , #2 \right\rangle} \newcommand{\openinterval}[2]{\parentheses{#1, #2}} \newcommand{\closedinterval}[2]{\brackets{#1, #2}} \mean\) opposed to the grand sum \(\newcommand{\parentheses}[1]{\left( #1 \right)} \newcommand{\brackets}[1]{\left[ #1 \right]} \newcommand{\mean}[1][]{\overline{\sum #1}} \newcommand{\fun}[2]{\text{#1}\of{#2}} \newcommand{\of}[1]{\parentheses{#1}} \newcommand{\dotproduct}[2]{\left\langle #1 , #2 \right\rangle} \newcommand{\openinterval}[2]{\parentheses{#1, #2}} \newcommand{\closedinterval}[2]{\brackets{#1, #2}} \sum\) to account for different sized images.
- Parameters
exponent (
float
) – Parameter \(\newcommand{\parentheses}[1]{\left( #1 \right)} \newcommand{\brackets}[1]{\left[ #1 \right]} \newcommand{\mean}[1][]{\overline{\sum #1}} \newcommand{\fun}[2]{\text{#1}\of{#2}} \newcommand{\of}[1]{\parentheses{#1}} \newcommand{\dotproduct}[2]{\left\langle #1 , #2 \right\rangle} \newcommand{\openinterval}[2]{\parentheses{#1, #2}} \newcommand{\closedinterval}[2]{\brackets{#1, #2}} \beta\) . A higher value leads to more smoothed results. Defaults to2.0
.score_weight (
float
) – Score weight of the operator. Defaults to1.0
.
Examples
>>> loss = pystiche.loss.TotalVariationLoss() >>> input = torch.rand(2, 3, 256, 256) >>> score = loss(input)
See also
The total variation loss was introduced by Mahendran and Vedaldi in [MV15] .
Comparison¶
- class pystiche.loss.FeatureReconstructionLoss(encoder, *, input_guide=None, target_image=None, target_guide=None, score_weight=1.0)¶
Bases:
pystiche.loss._loss.ComparisonLoss
The feature reconstruction loss is the de facto standard content loss. It measures the mean squared error (MSE) between the encodings of an
input_image
\(\newcommand{\parentheses}[1]{\left( #1 \right)} \newcommand{\brackets}[1]{\left[ #1 \right]} \newcommand{\mean}[1][]{\overline{\sum #1}} \newcommand{\fun}[2]{\text{#1}\of{#2}} \newcommand{\of}[1]{\parentheses{#1}} \newcommand{\dotproduct}[2]{\left\langle #1 , #2 \right\rangle} \newcommand{\openinterval}[2]{\parentheses{#1, #2}} \newcommand{\closedinterval}[2]{\brackets{#1, #2}} \hat{I}\) and atarget_image
\(\newcommand{\parentheses}[1]{\left( #1 \right)} \newcommand{\brackets}[1]{\left[ #1 \right]} \newcommand{\mean}[1][]{\overline{\sum #1}} \newcommand{\fun}[2]{\text{#1}\of{#2}} \newcommand{\of}[1]{\parentheses{#1}} \newcommand{\dotproduct}[2]{\left\langle #1 , #2 \right\rangle} \newcommand{\openinterval}[2]{\parentheses{#1, #2}} \newcommand{\closedinterval}[2]{\brackets{#1, #2}} I\) :\[\newcommand{\parentheses}[1]{\left( #1 \right)} \newcommand{\brackets}[1]{\left[ #1 \right]} \newcommand{\mean}[1][]{\overline{\sum #1}} \newcommand{\fun}[2]{\text{#1}\of{#2}} \newcommand{\of}[1]{\parentheses{#1}} \newcommand{\dotproduct}[2]{\left\langle #1 , #2 \right\rangle} \newcommand{\openinterval}[2]{\parentheses{#1, #2}} \newcommand{\closedinterval}[2]{\brackets{#1, #2}} \mean \parentheses{\Phi\of{\hat{I}} - \Phi\of{I}}^2\]Here \(\newcommand{\parentheses}[1]{\left( #1 \right)} \newcommand{\brackets}[1]{\left[ #1 \right]} \newcommand{\mean}[1][]{\overline{\sum #1}} \newcommand{\fun}[2]{\text{#1}\of{#2}} \newcommand{\of}[1]{\parentheses{#1}} \newcommand{\dotproduct}[2]{\left\langle #1 , #2 \right\rangle} \newcommand{\openinterval}[2]{\parentheses{#1, #2}} \newcommand{\closedinterval}[2]{\brackets{#1, #2}} \Phi\of{\cdot}\) denotes the
encoder
.Note
Opposed to the paper, the implementation calculates the grand average \(\newcommand{\parentheses}[1]{\left( #1 \right)} \newcommand{\brackets}[1]{\left[ #1 \right]} \newcommand{\mean}[1][]{\overline{\sum #1}} \newcommand{\fun}[2]{\text{#1}\of{#2}} \newcommand{\of}[1]{\parentheses{#1}} \newcommand{\dotproduct}[2]{\left\langle #1 , #2 \right\rangle} \newcommand{\openinterval}[2]{\parentheses{#1, #2}} \newcommand{\closedinterval}[2]{\brackets{#1, #2}} \mean\) opposed to the grand sum \(\newcommand{\parentheses}[1]{\left( #1 \right)} \newcommand{\brackets}[1]{\left[ #1 \right]} \newcommand{\mean}[1][]{\overline{\sum #1}} \newcommand{\fun}[2]{\text{#1}\of{#2}} \newcommand{\of}[1]{\parentheses{#1}} \newcommand{\dotproduct}[2]{\left\langle #1 , #2 \right\rangle} \newcommand{\openinterval}[2]{\parentheses{#1, #2}} \newcommand{\closedinterval}[2]{\brackets{#1, #2}} \sum\) to account for different sized images.
- Parameters
encoder (
Encoder
) – Encoder \(\newcommand{\parentheses}[1]{\left( #1 \right)} \newcommand{\brackets}[1]{\left[ #1 \right]} \newcommand{\mean}[1][]{\overline{\sum #1}} \newcommand{\fun}[2]{\text{#1}\of{#2}} \newcommand{\of}[1]{\parentheses{#1}} \newcommand{\dotproduct}[2]{\left\langle #1 , #2 \right\rangle} \newcommand{\openinterval}[2]{\parentheses{#1, #2}} \newcommand{\closedinterval}[2]{\brackets{#1, #2}} \Phi\).score_weight (
float
) – Score weight of the operator. Defaults to1.0
.
Examples
>>> mle = pystiche.enc.vgg19_multi_layer_encoder() >>> encoder = mle.extract_encoder("relu4_2") >>> loss = pystiche.loss.FeatureReconstructionLoss(encoder) >>> input = torch.rand(2, 3, 256, 256) >>> target = torch.rand(2, 3, 256, 256) >>> loss.set_target_image(target) >>> score = loss(input)
- class pystiche.loss.GramLoss(encoder, *, normalize=True, input_guide=None, target_image=None, target_guide=None, score_weight=1.0)¶
Bases:
pystiche.loss._loss.ComparisonLoss
The gram loss is a style loss based on the correlation of feature map channels. It measures the mean squared error (MSE) between the channel-wise Gram matrices of the encodings of an
input_image
\(\newcommand{\parentheses}[1]{\left( #1 \right)} \newcommand{\brackets}[1]{\left[ #1 \right]} \newcommand{\mean}[1][]{\overline{\sum #1}} \newcommand{\fun}[2]{\text{#1}\of{#2}} \newcommand{\of}[1]{\parentheses{#1}} \newcommand{\dotproduct}[2]{\left\langle #1 , #2 \right\rangle} \newcommand{\openinterval}[2]{\parentheses{#1, #2}} \newcommand{\closedinterval}[2]{\brackets{#1, #2}} \hat{I}\) and atarget_image
\(\newcommand{\parentheses}[1]{\left( #1 \right)} \newcommand{\brackets}[1]{\left[ #1 \right]} \newcommand{\mean}[1][]{\overline{\sum #1}} \newcommand{\fun}[2]{\text{#1}\of{#2}} \newcommand{\of}[1]{\parentheses{#1}} \newcommand{\dotproduct}[2]{\left\langle #1 , #2 \right\rangle} \newcommand{\openinterval}[2]{\parentheses{#1, #2}} \newcommand{\closedinterval}[2]{\brackets{#1, #2}} I\):\[\newcommand{\parentheses}[1]{\left( #1 \right)} \newcommand{\brackets}[1]{\left[ #1 \right]} \newcommand{\mean}[1][]{\overline{\sum #1}} \newcommand{\fun}[2]{\text{#1}\of{#2}} \newcommand{\of}[1]{\parentheses{#1}} \newcommand{\dotproduct}[2]{\left\langle #1 , #2 \right\rangle} \newcommand{\openinterval}[2]{\parentheses{#1, #2}} \newcommand{\closedinterval}[2]{\brackets{#1, #2}} \mean \parentheses{\fun{gram}{\Phi\of{\hat{I}}} - \fun{gram}{\Phi\of{I}}}^2\]Here \(\newcommand{\parentheses}[1]{\left( #1 \right)} \newcommand{\brackets}[1]{\left[ #1 \right]} \newcommand{\mean}[1][]{\overline{\sum #1}} \newcommand{\fun}[2]{\text{#1}\of{#2}} \newcommand{\of}[1]{\parentheses{#1}} \newcommand{\dotproduct}[2]{\left\langle #1 , #2 \right\rangle} \newcommand{\openinterval}[2]{\parentheses{#1, #2}} \newcommand{\closedinterval}[2]{\brackets{#1, #2}} \Phi\of{\cdot}\) denotes the
encoder
and \(\newcommand{\parentheses}[1]{\left( #1 \right)} \newcommand{\brackets}[1]{\left[ #1 \right]} \newcommand{\mean}[1][]{\overline{\sum #1}} \newcommand{\fun}[2]{\text{#1}\of{#2}} \newcommand{\of}[1]{\parentheses{#1}} \newcommand{\dotproduct}[2]{\left\langle #1 , #2 \right\rangle} \newcommand{\openinterval}[2]{\parentheses{#1, #2}} \newcommand{\closedinterval}[2]{\brackets{#1, #2}} \fun{gram}{\cdot}\) denotespystiche.gram_matrix()
.Note
Opposed to the paper, the implementation calculates the grand average \(\newcommand{\parentheses}[1]{\left( #1 \right)} \newcommand{\brackets}[1]{\left[ #1 \right]} \newcommand{\mean}[1][]{\overline{\sum #1}} \newcommand{\fun}[2]{\text{#1}\of{#2}} \newcommand{\of}[1]{\parentheses{#1}} \newcommand{\dotproduct}[2]{\left\langle #1 , #2 \right\rangle} \newcommand{\openinterval}[2]{\parentheses{#1, #2}} \newcommand{\closedinterval}[2]{\brackets{#1, #2}} \mean\) opposed to the grand sum \(\newcommand{\parentheses}[1]{\left( #1 \right)} \newcommand{\brackets}[1]{\left[ #1 \right]} \newcommand{\mean}[1][]{\overline{\sum #1}} \newcommand{\fun}[2]{\text{#1}\of{#2}} \newcommand{\of}[1]{\parentheses{#1}} \newcommand{\dotproduct}[2]{\left\langle #1 , #2 \right\rangle} \newcommand{\openinterval}[2]{\parentheses{#1, #2}} \newcommand{\closedinterval}[2]{\brackets{#1, #2}} \sum\) to account for different sized images.
- Parameters
encoder (
Encoder
) – Encoder \(\newcommand{\parentheses}[1]{\left( #1 \right)} \newcommand{\brackets}[1]{\left[ #1 \right]} \newcommand{\mean}[1][]{\overline{\sum #1}} \newcommand{\fun}[2]{\text{#1}\of{#2}} \newcommand{\of}[1]{\parentheses{#1}} \newcommand{\dotproduct}[2]{\left\langle #1 , #2 \right\rangle} \newcommand{\openinterval}[2]{\parentheses{#1, #2}} \newcommand{\closedinterval}[2]{\brackets{#1, #2}} \Phi\left( \cdot \right)\).normalize (
bool
) – IfTrue
, normalizes the Gram matrices to account for different sized images. Seepystiche.gram_matrix()
for details. Defaults toTrue
.score_weight (
float
) – Score weight of the operator. Defaults to1.0
.
Examples
>>> mle = pystiche.enc.vgg19_multi_layer_encoder() >>> encoder = mle.extract_encoder("relu4_2") >>> loss = pystiche.loss.GramLoss(encoder) >>> input = torch.rand(2, 3, 256, 256) >>> target = torch.rand(2, 3, 256, 256) >>> loss.set_target_image(target) >>> score = loss(input)
See also
The feature reconstruction loss was introduced by Gatys, Ecker, and Bethge in [GEB16] .
- class pystiche.loss.MRFLoss(encoder, patch_size, *, stride=1, target_transforms=None, input_guide=None, target_image=None, target_guide=None, score_weight=1.0)¶
Bases:
pystiche.loss._loss.ComparisonLoss
The MRF loss is a style loss based on Markov Random Fields (MRFs). It measures the mean squared error (MSE) between neural patches extracted from the encodings of an
input_image
\(\newcommand{\parentheses}[1]{\left( #1 \right)} \newcommand{\brackets}[1]{\left[ #1 \right]} \newcommand{\mean}[1][]{\overline{\sum #1}} \newcommand{\fun}[2]{\text{#1}\of{#2}} \newcommand{\of}[1]{\parentheses{#1}} \newcommand{\dotproduct}[2]{\left\langle #1 , #2 \right\rangle} \newcommand{\openinterval}[2]{\parentheses{#1, #2}} \newcommand{\closedinterval}[2]{\brackets{#1, #2}} \hat{I}\) and atarget_image
\(\newcommand{\parentheses}[1]{\left( #1 \right)} \newcommand{\brackets}[1]{\left[ #1 \right]} \newcommand{\mean}[1][]{\overline{\sum #1}} \newcommand{\fun}[2]{\text{#1}\of{#2}} \newcommand{\of}[1]{\parentheses{#1}} \newcommand{\dotproduct}[2]{\left\langle #1 , #2 \right\rangle} \newcommand{\openinterval}[2]{\parentheses{#1, #2}} \newcommand{\closedinterval}[2]{\brackets{#1, #2}} I\):\[\newcommand{\parentheses}[1]{\left( #1 \right)} \newcommand{\brackets}[1]{\left[ #1 \right]} \newcommand{\mean}[1][]{\overline{\sum #1}} \newcommand{\fun}[2]{\text{#1}\of{#2}} \newcommand{\of}[1]{\parentheses{#1}} \newcommand{\dotproduct}[2]{\left\langle #1 , #2 \right\rangle} \newcommand{\openinterval}[2]{\parentheses{#1, #2}} \newcommand{\closedinterval}[2]{\brackets{#1, #2}} \mean \parentheses{p_n\of{\Phi\of{\hat{I}}} - p_{MCS\of{n}}\of{\Phi\of{\hat{I}}}}^2\]Since the number of patches might be different for both images and the order of the patches does not correlate with the order of the enclosed style element, for each input neural patch \(\newcommand{\parentheses}[1]{\left( #1 \right)} \newcommand{\brackets}[1]{\left[ #1 \right]} \newcommand{\mean}[1][]{\overline{\sum #1}} \newcommand{\fun}[2]{\text{#1}\of{#2}} \newcommand{\of}[1]{\parentheses{#1}} \newcommand{\dotproduct}[2]{\left\langle #1 , #2 \right\rangle} \newcommand{\openinterval}[2]{\parentheses{#1, #2}} \newcommand{\closedinterval}[2]{\brackets{#1, #2}} n\) a fitting target neural patch is to selected based on the maximum cosine similarity \(\newcommand{\parentheses}[1]{\left( #1 \right)} \newcommand{\brackets}[1]{\left[ #1 \right]} \newcommand{\mean}[1][]{\overline{\sum #1}} \newcommand{\fun}[2]{\text{#1}\of{#2}} \newcommand{\of}[1]{\parentheses{#1}} \newcommand{\dotproduct}[2]{\left\langle #1 , #2 \right\rangle} \newcommand{\openinterval}[2]{\parentheses{#1, #2}} \newcommand{\closedinterval}[2]{\brackets{#1, #2}} MCS\of{n}\) with
pystiche.cosine_similarity()
.Note
Opposed to the paper, the implementation calculates the grand average \(\newcommand{\parentheses}[1]{\left( #1 \right)} \newcommand{\brackets}[1]{\left[ #1 \right]} \newcommand{\mean}[1][]{\overline{\sum #1}} \newcommand{\fun}[2]{\text{#1}\of{#2}} \newcommand{\of}[1]{\parentheses{#1}} \newcommand{\dotproduct}[2]{\left\langle #1 , #2 \right\rangle} \newcommand{\openinterval}[2]{\parentheses{#1, #2}} \newcommand{\closedinterval}[2]{\brackets{#1, #2}} \mean\) opposed to the grand sum \(\newcommand{\parentheses}[1]{\left( #1 \right)} \newcommand{\brackets}[1]{\left[ #1 \right]} \newcommand{\mean}[1][]{\overline{\sum #1}} \newcommand{\fun}[2]{\text{#1}\of{#2}} \newcommand{\of}[1]{\parentheses{#1}} \newcommand{\dotproduct}[2]{\left\langle #1 , #2 \right\rangle} \newcommand{\openinterval}[2]{\parentheses{#1, #2}} \newcommand{\closedinterval}[2]{\brackets{#1, #2}} \sum\) to account for different sized images.
- Parameters
encoder (
Encoder
) – Encoder \(\newcommand{\parentheses}[1]{\left( #1 \right)} \newcommand{\brackets}[1]{\left[ #1 \right]} \newcommand{\mean}[1][]{\overline{\sum #1}} \newcommand{\fun}[2]{\text{#1}\of{#2}} \newcommand{\of}[1]{\parentheses{#1}} \newcommand{\dotproduct}[2]{\left\langle #1 , #2 \right\rangle} \newcommand{\openinterval}[2]{\parentheses{#1, #2}} \newcommand{\closedinterval}[2]{\brackets{#1, #2}} \Phi\) .patch_size (
Union
[int
,Sequence
[int
]]) – Spatial size of the neural patches.stride (
Union
[int
,Sequence
[int
]]) – Distance between two neural patches.target_transforms (
Optional
[Iterable
[Module
]]) – Optional transformations to apply to the target image before the neural patches are extracted. Defaults toNone
.score_weight (
float
) – Score weight of the operator. Defaults to1.0
.
Examples
>>> mle = pystiche.enc.vgg19_multi_layer_encoder() >>> encoder = mle.extract_encoder("relu4_2") >>> patch_size = 3 >>> loss = pystiche.loss.MRFLoss(encoder, patch_size) >>> input = torch.rand(2, 3, 256, 256) >>> target = torch.rand(2, 3, 256, 256) >>> loss.set_target_image(target) >>> score = loss(input)
See also
The MRF loss was introduced by Li and Wand in [LW16].
- static scale_and_rotate_transforms(num_scale_steps=1, scale_step_width=0.05, num_rotate_steps=1, rotate_step_width=10.0)¶
Generate a list of scaling and rotations transformations.
See also
The output of this method can be used as parameter
target_transforms
ofMRFLoss
to enrich the space of target neural patches:target_transforms = MRFOperator.scale_and_rotate_transforms() loss = pystiche.loss.MRFLoss(..., target_transforms=target_transforms)
- Parameters
num_scale_steps (
int
) – Number of scale steps. Each scale is performed in both directions, i.e. enlarging and shrinking the motif. Defaults to1
.scale_step_width (
float
) – Width of each scale step. Defaults to5e-2
.num_rotate_steps (
int
) – Number of rotate steps. Each rotate is performed in both directions, i.e. clockwise and counterclockwise. Defaults to1
.rotate_step_width (
float
) – Width of each rotation step in degrees. Defaults to10.0
.
- Return type
List
[ScaleAndRotate
]- Returns
(num_scale_steps * 2 + 1) * (num_rotate_steps * 2 + 1)
transformations in total comprising every combination given by the input parameters.
pystiche.loss.functional
¶
- pystiche.loss.functional.mrf_loss(input, target, eps=1e-08, reduction='mean', batched_input=None)¶
Calculates the MRF loss. See
pystiche.loss.MRFLoss
for details.- Parameters
input (
Tensor
) – Input of shape \(\newcommand{\parentheses}[1]{\left( #1 \right)} \newcommand{\brackets}[1]{\left[ #1 \right]} \newcommand{\mean}[1][]{\overline{\sum #1}} \newcommand{\fun}[2]{\text{#1}\of{#2}} \newcommand{\of}[1]{\parentheses{#1}} \newcommand{\dotproduct}[2]{\left\langle #1 , #2 \right\rangle} \newcommand{\openinterval}[2]{\parentheses{#1, #2}} \newcommand{\closedinterval}[2]{\brackets{#1, #2}} B \times S_1 \times N_1 \times \dots \times N_D\).target (
Tensor
) – Target of shape \(\newcommand{\parentheses}[1]{\left( #1 \right)} \newcommand{\brackets}[1]{\left[ #1 \right]} \newcommand{\mean}[1][]{\overline{\sum #1}} \newcommand{\fun}[2]{\text{#1}\of{#2}} \newcommand{\of}[1]{\parentheses{#1}} \newcommand{\dotproduct}[2]{\left\langle #1 , #2 \right\rangle} \newcommand{\openinterval}[2]{\parentheses{#1, #2}} \newcommand{\closedinterval}[2]{\brackets{#1, #2}} B \times S_2 \times N_1 \times \dots \times N_D\).eps (
float
) – Small value to avoid zero division. Defaults to1e-8
.reduction (
str
) – Reduction method of the output passed topystiche.misc.reduce()
. Defaults to"mean"
.batched_input (
Optional
[bool
]) – IfFalse
, treat the first dimension of the inputs as sample dimension, i.e. \(\newcommand{\parentheses}[1]{\left( #1 \right)} \newcommand{\brackets}[1]{\left[ #1 \right]} \newcommand{\mean}[1][]{\overline{\sum #1}} \newcommand{\fun}[2]{\text{#1}\of{#2}} \newcommand{\of}[1]{\parentheses{#1}} \newcommand{\dotproduct}[2]{\left\langle #1 , #2 \right\rangle} \newcommand{\openinterval}[2]{\parentheses{#1, #2}} \newcommand{\closedinterval}[2]{\brackets{#1, #2}} S \times N_1 \times \dots \times N_D\). Defaults toTrue
. Seepystiche.cosine_similarity()
for details.
Examples
>>> import pystiche.loss.functional as F >>> input = torch.rand(1, 256, 64, 3, 3) >>> target = torch.rand(1, 128, 64, 3, 3) >>> score = F.mrf_loss(input, target, batched_input=True)
- Return type
- pystiche.loss.functional.total_variation_loss(input, exponent=2.0, reduction='mean')¶
Calculates the total variation loss. See
pystiche.ops.TotalVariationOperator
for details.- Parameters
input (
Tensor
) – Input imageexponent (
float
) – Parameter \(\newcommand{\parentheses}[1]{\left( #1 \right)} \newcommand{\brackets}[1]{\left[ #1 \right]} \newcommand{\mean}[1][]{\overline{\sum #1}} \newcommand{\fun}[2]{\text{#1}\of{#2}} \newcommand{\of}[1]{\parentheses{#1}} \newcommand{\dotproduct}[2]{\left\langle #1 , #2 \right\rangle} \newcommand{\openinterval}[2]{\parentheses{#1, #2}} \newcommand{\closedinterval}[2]{\brackets{#1, #2}} \beta\) . A higher value leads to more smoothed results. Defaults to2.0
.reduction (
str
) – Reduction method of the output passed topystiche.misc.reduce()
. Defaults to"mean"
.
Examples
>>> import pystiche.loss.functional as F >>> input = torch.rand(2, 3, 256, 256) >>> score = F.total_variation_loss(input)
- Return type
pystiche.meta
¶
pystiche.misc
¶
- pystiche.misc.get_input_image(starting_point='content', content_image=None, style_image=None)¶
Generates an input image for NST from the given
starting_point
.- Parameters
starting_point (
Union
[str
,Tensor
]) – IfTensor
returns a copy. If"content"
or"style"
returns a copy ofcontent_image
orstyle_image
, respectively. If"random"
returns a white noise image with the dimensions ofcontent_image
orstyle_image
, respectively. Defaults to"content"
.content_image (
Optional
[Tensor
]) – Content image. Only required ifstarting_point
is"content"
or"random"
.style_image (
Optional
[Tensor
]) – Style image. Only required ifstarting_point
is"style"
or"random"
.
- Return type
- pystiche.misc.get_device(device=None)¶
Selects a device to perform an NST on.
pystiche.optim
¶
- pystiche.optim.default_image_optimizer(input_image)¶
- Parameters
input_image (
Tensor
) – Image to be optimized.- Return type
- Returns
torch.optim.LBFGS
optimizer with a learning rate of1.0
. The pixels ofinput_image
are set as optimization parameters.
- pystiche.optim.image_optimization(input_image, criterion, optimizer=None, num_steps=500, preprocessor=None, postprocessor=None, quiet=False)¶
Perform an image optimization with integrated logging.
- Parameters
input_image (
Tensor
) – Image to be optimized.criterion (
Module
) – Optimization criterion.optimizer (
Union
[Optimizer
,Callable
[[Tensor
],Optimizer
],None
]) – Optional optimizer or optimizer getter. If omitted,default_image_optimizer()
is used. If apreprocessor
is used, has to be a getter.num_steps (
Union
[int
,Iterable
[int
]]) – Number of optimization steps. Defaults to500
.preprocessor (
Optional
[Module
]) – Optional preprocessor that is called with theinput_image
before the optimization.postprocessor (
Optional
[Module
]) – Optional preprocessor that is called with theinput_image
after the optimization.quiet (
bool
) – IfTrue
, no information is printed to STDOUT during the optimization. Defaults toFalse
.
- Raises
RuntimeError – If
preprocessor
is used andoptimizer
is not passed asgetter. –
- Return type
- pystiche.optim.pyramid_image_optimization(input_image, criterion, pyramid, get_optimizer=None, preprocessor=None, postprocessor=None, quiet=False)¶
Perform a image optimization for
pystiche.pyramid.ImagePyramid
s with integrated logging.- Parameters
input_image (
Tensor
) – Image to be optimized.criterion (
Module
) – Optimization criterion.pyramid (
ImagePyramid
) – Image pyramid.get_optimizer (
Optional
[Callable
[[Tensor
],Optimizer
]]) – Optional getter for the optimizer. IfNone
,default_image_optimizer()
is used. Defaults toNone
.preprocessor (
Optional
[Module
]) – Optional preprocessor that is called with theinput_image
before the optimization.postprocessor (
Optional
[Module
]) – Optional preprocessor that is called with theinput_image
after the optimization.quiet (
bool
) – IfTrue
, no information is printed to STDOUT during the optimization. Defaults toFalse
.
- Return type
- pystiche.optim.default_model_optimizer(transformer)¶
- Parameters
transformer (
Module
) – Transformer to be optimized.- Return type
- Returns
torch.optim.Adam
optimizer with a learning rate of1e-3
. The parameters oftransformer
are set as optimization parameters.
- pystiche.optim.model_optimization(image_loader, transformer, criterion, criterion_update_fn=None, optimizer=None, quiet=False)¶
Perform a model optimization for a single epoch with integrated logging.
- Parameters
image_loader (
DataLoader
) – Images used as input for thetransformer
. Drawing from this should yield either an batched image or a tuple or list with a batched image as first item.transformer (
Module
) – Transformer to be optimized.criterion (
Module
) – Optimization criterion.criterion_update_fn (
Optional
[Callable
[[Tensor
,Module
],None
]]) – Is called before each optimization step with the current images and the optimizationcriterion
. If omitted andcriterion
is aPerceptualLoss
or aGuidedPerceptualLoss
this defaults to invokingset_content_image()
.optimizer (
Optional
[Optimizer
]) – Optional optimizer. IfNone
,default_model_optimizer()
is used.quiet (
bool
) – IfTrue
, no information is printed to STDOUT during the optimization. Defaults toFalse
.
- Return type
- pystiche.optim.multi_epoch_model_optimization(image_loader, transformer, criterion, criterion_update_fn=None, epochs=2, optimizer=None, lr_scheduler=None, quiet=False)¶
Perform a model optimization for multiple epochs with integrated logging.
- Parameters
image_loader (
DataLoader
) – Images used as input for thetransformer
. Drawing from this should yield either an batched image or a tuple or list with a batched image as first item.transformer (
Module
) – Transformer to be optimized.criterion (
Module
) – Optimization criterion.criterion_update_fn (
Optional
[Callable
[[Tensor
,Module
],None
]]) – Is called before each optimization step with the current images and the optimizationcriterion
. If omitted andcriterion
is aPerceptualLoss
or aGuidedPerceptualLoss
this defaults to invokingset_content_image()
.epochs (
int
) – Number of epochs. Defaults to2
.optimizer (
Optional
[Optimizer
]) – Optional optimizer. IfNone
, it is extracted fromlr_scheduler
or func:default_model_optimizer is used.lr_scheduler (
Optional
[_LRScheduler
]) – Optional learning rate scheduler.step()
is invoked after every epoch.quiet (
bool
) – IfTrue
, no information is printed to STDOUT during the optimization. Defaults toFalse
.
- Return type
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 ofresize_targets
.- Parameters
num_steps (
Union
[Sequence
[int
],int
]) – Number of steps for each level. If sequence ofint
its length has to match the length ofedge_sizes
.edge (
Union
[Sequence
[str
],str
]) – Corresponding edge to the edge size for each level. Can be"short"
or"long"
. If sequence ofstr
its length has to match the length ofedge_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 theinterpolation_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 ofint``s, you should also specify ``num_levels
to match the lengthsnum_levels (
Optional
[int
]) – Optional number of levels. IfNone
, the number is determined by the number of steps of factor two betweenmax_edge_size
andmin_edge_size
.min_edge_size (
int
) – Minimum edge size for the automatic calculation ofnum_levels
.image_pyramid_kwargs (
Any
) – Additional options. SeeImagePyramid
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 innum_steps
.- Parameters
- resize_guide(guide, aspect_ratio=None, interpolation_mode='nearest')¶
Resize a guide to the
edge_size
on the correspondingedge
of thePyramidLevel
.
- resize_image(image, aspect_ratio=None, interpolation_mode='bilinear')¶
Resize an image to the
edge_size
on the correspondingedge
of thePyramidLevel
.- Parameters
Warning
The resizing is performed without gradient calculation. Do not use this if the image needs a gradient.
- Return type
Literature Reference¶
- CZP+18
Liang-Chieh Chen, Yukun Zhu, George Papandreou, Florian Schroff, and Hartwig Adam. Encoder-decoder with atrous separable convolution for semantic image segmentation. In The European Conference on Computer Vision (ECCV). 2018. URL: http://openaccess.thecvf.com/content_ECCV_2018/papers/Liang-Chieh_Chen_Encoder-Decoder_with_Atrous_ECCV_2018_paper.pdf, doi:10.1007/978-3-030-01234-2_49.
- GEB+17
Leon A. Gatys, Alexander S. Ecker, Matthias Bethge, Aaron Hertzmann, and Eli Shechtman. Controlling perceptual factors in neural style transfer. In IEEE Conference on Computer Vision and Pattern Recognition (CVPR). 2017. arXiv:1611.07865, doi:10.1109/CVPR.2017.397.
- GEB16
Leon A. Gatys, Alexander. S. Ecker, and Matthias Bethge. Image style transfer using convolutional neural networks. In IEEE Conference on Computer Vision and Pattern Recognition (CVPR). 2016. arXiv:1508.06576, doi:10.1109/CVPR.2016.265.
- JAL16
Justin Johnson, Alexandre Alahi, and Fei-Fei Li. Perceptual losses for real-time style transfer and super-resolution. In European Conference on Computer Vision (ECCV). 2016. arXiv:1603.08155, doi:10.1007/978-3-319-46475-6_43.
- KSH12
Alex Krizhevsky, Ilya Sutskever, and Geoffrey E. Hinton. Imagenet classification with deep convolutional neural networks. In Advances in Neural Information Processing Systems 25 (NIPS). 2012. URL: https://papers.nips.cc/paper/4824-imagenet-classification-with-deep-convolutional-neural-networks.pdf.
- LW16
Chuan Li and Michael Wand. Combining markov random fields and convolutional neural networks for image synthesis. In IEEE Conference on Computer Vision and Pattern Recognition (CVPR). 2016. arXiv:1601.04589, doi:10.1109/CVPR.2016.272.
- MV15
Aravindh Mahendran and Andrea Vedaldi. Understanding deep image representations by inverting them. In IEEE Conference on Computer Vision and Pattern Recognition (CVPR). 2015. arXiv:1412.0035, doi:10.1109/CVPR.2015.7299155.
- SID17
Amir Semmo, Tobias Isenberg, and Jürgen Döllner. Neural style transfer: a paradigm shift for image-based artistic rendering? In Proceedings of the Symposium on Non-Photorealistic Animation and Rendering (NPAR). 2017. doi:10.1145/3092919.3092920.
- SZ14
Karen Simonyan and Andrew Zisserman. Very deep convolutional networks for large-scale image recognition. Computing Research Repository (CoRR), 2014. arXiv:1409.1556.
- ULVL16
Dmitry Ulyanov, Vadim Lebedev, Andrea Vedaldi, and Viktor S. Lempitsky. Texture networks: feed-forward synthesis of textures and stylized images. In International Conference on Machine Learning (ICML). 2016. URL: http://proceedings.mlr.press/v48/ulyanov16.html, arXiv:1603.03417.
- UVL16
Dmitry Ulyanov, Andrea Vedaldi, and Viktor S. Lempitsky. Instance normalization: the missing ingredient for fast stylization. Computing Research Repository (CoRR), 2016. arXiv:1607.08022.