Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2543fee

Browse files
ssnlchsasank
authored andcommitted
Update Neural Style Transfer to print weighted loss (#225)
* Update Neural Style Transfer to print weighted loss * fix a typo too
1 parent 0ad33d6 commit 2543fee

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

advanced_source/neural_style_tutorial.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@
154154
# VGG). For this, we have ``torch.cuda.is_available()`` that returns
155155
# ``True`` if you computer has an available GPU. Then, we can set the
156156
# ``torch.device`` that will be used in this script. Then, we will use
157-
# the method ``.to(device)`` that a tensor or a module to the desired
157+
# the method ``.to(device)`` that moves a tensor or a module to the desired
158158
# device. When we want to move back this tensor or module to the
159159
# CPU (e.g. to use numpy), we can use the ``.cpu()`` method.
160160

@@ -561,7 +561,11 @@ def closure():
561561
for cl in content_losses:
562562
content_score += cl.loss
563563

564-
(style_score * style_weight + content_score * content_weight).backward()
564+
style_score *= style_weight
565+
content_score *= content_weight
566+
567+
loss = style_score + content_score
568+
loss.backward()
565569

566570
run[0] += 1
567571
if run[0] % 50 == 0:

0 commit comments

Comments
 (0)