Skip to content

Use __call__ instead of forward #58

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 10, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions advanced_source/neural_style_tutorial.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ def __init__(self, target, weight):
self.criterion = nn.MSELoss()

def forward(self, input):
self.loss = self.criterion.forward(input * self.weight, self.target)
self.loss = self.criterion(input * self.weight, self.target)
self.output = input
return self.output

Expand Down Expand Up @@ -357,9 +357,9 @@ def __init__(self, target, weight):

def forward(self, input):
self.output = input.clone()
self.G = self.gram.forward(input)
self.G = self.gram(input)
self.G.mul_(self.weight)
self.loss = self.criterion.forward(self.G, self.target)
self.loss = self.criterion(self.G, self.target)
return self.output

def backward(self, retain_variables=True):
Expand Down Expand Up @@ -430,15 +430,15 @@ def get_style_model_and_losses(cnn, style_img, content_img,

if name in content_layers:
# add content loss:
target = model.forward(content_img).clone()
target = model(content_img).clone()
content_loss = ContentLoss(target, content_weight)
model.add_module("content_loss_" + str(i), content_loss)
content_losses.append(content_loss)

if name in style_layers:
# add style loss:
target_feature = model.forward(style_img).clone()
target_feature_gram = gram.forward(target_feature)
target_feature = model(style_img).clone()
target_feature_gram = gram(target_feature)
style_loss = StyleLoss(target_feature_gram, style_weight)
model.add_module("style_loss_" + str(i), style_loss)
style_losses.append(style_loss)
Expand All @@ -449,15 +449,15 @@ def get_style_model_and_losses(cnn, style_img, content_img,

if name in content_layers:
# add content loss:
target = model.forward(content_img).clone()
target = model(content_img).clone()
content_loss = ContentLoss(target, content_weight)
model.add_module("content_loss_" + str(i), content_loss)
content_losses.append(content_loss)

if name in style_layers:
# add style loss:
target_feature = model.forward(style_img).clone()
target_feature_gram = gram.forward(target_feature)
target_feature = model(style_img).clone()
target_feature_gram = gram(target_feature)
style_loss = StyleLoss(target_feature_gram, style_weight)
model.add_module("style_loss_" + str(i), style_loss)
style_losses.append(style_loss)
Expand Down Expand Up @@ -564,7 +564,7 @@ def closure():
input_param.data.clamp_(0, 1)

optimizer.zero_grad()
model.forward(input_param)
model(input_param)
style_score = 0
content_score = 0

Expand Down