@@ -286,7 +286,7 @@ def __init__(self, target, weight):
286
286
self .criterion = nn .MSELoss ()
287
287
288
288
def forward (self , input ):
289
- self .loss = self .criterion . forward (input * self .weight , self .target )
289
+ self .loss = self .criterion (input * self .weight , self .target )
290
290
self .output = input
291
291
return self .output
292
292
@@ -357,9 +357,9 @@ def __init__(self, target, weight):
357
357
358
358
def forward (self , input ):
359
359
self .output = input .clone ()
360
- self .G = self .gram . forward (input )
360
+ self .G = self .gram (input )
361
361
self .G .mul_ (self .weight )
362
- self .loss = self .criterion . forward (self .G , self .target )
362
+ self .loss = self .criterion (self .G , self .target )
363
363
return self .output
364
364
365
365
def backward (self , retain_variables = True ):
@@ -430,15 +430,15 @@ def get_style_model_and_losses(cnn, style_img, content_img,
430
430
431
431
if name in content_layers :
432
432
# add content loss:
433
- target = model . forward (content_img ).clone ()
433
+ target = model (content_img ).clone ()
434
434
content_loss = ContentLoss (target , content_weight )
435
435
model .add_module ("content_loss_" + str (i ), content_loss )
436
436
content_losses .append (content_loss )
437
437
438
438
if name in style_layers :
439
439
# add style loss:
440
- target_feature = model . forward (style_img ).clone ()
441
- target_feature_gram = gram . forward (target_feature )
440
+ target_feature = model (style_img ).clone ()
441
+ target_feature_gram = gram (target_feature )
442
442
style_loss = StyleLoss (target_feature_gram , style_weight )
443
443
model .add_module ("style_loss_" + str (i ), style_loss )
444
444
style_losses .append (style_loss )
@@ -449,15 +449,15 @@ def get_style_model_and_losses(cnn, style_img, content_img,
449
449
450
450
if name in content_layers :
451
451
# add content loss:
452
- target = model . forward (content_img ).clone ()
452
+ target = model (content_img ).clone ()
453
453
content_loss = ContentLoss (target , content_weight )
454
454
model .add_module ("content_loss_" + str (i ), content_loss )
455
455
content_losses .append (content_loss )
456
456
457
457
if name in style_layers :
458
458
# add style loss:
459
- target_feature = model . forward (style_img ).clone ()
460
- target_feature_gram = gram . forward (target_feature )
459
+ target_feature = model (style_img ).clone ()
460
+ target_feature_gram = gram (target_feature )
461
461
style_loss = StyleLoss (target_feature_gram , style_weight )
462
462
model .add_module ("style_loss_" + str (i ), style_loss )
463
463
style_losses .append (style_loss )
@@ -564,7 +564,7 @@ def closure():
564
564
input_param .data .clamp_ (0 , 1 )
565
565
566
566
optimizer .zero_grad ()
567
- model . forward (input_param )
567
+ model (input_param )
568
568
style_score = 0
569
569
content_score = 0
570
570
0 commit comments