Created
January 30, 2021 23:37
-
-
Save ogyalcin/7c49c42f4089b4642efa6bce3eb2cd03 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Create an optimizer. The paper recommends LBFGS, but Adam works okay, too: | |
| opt = tf.optimizers.Adam(learning_rate=0.005, beta_1=0.99, epsilon=1e-1) | |
| # To optimize this, use a weighted combination of the two losses to get the total loss: | |
| style_weight=1e-2 | |
| content_weight=1e4 | |
| def style_content_loss(outputs): | |
| style_outputs = outputs['style'] | |
| content_outputs = outputs['content'] | |
| style_loss = tf.add_n([tf.reduce_mean((style_outputs[name]-style_targets[name])**2) | |
| for name in style_outputs.keys()]) | |
| style_loss *= style_weight / len(style_layers) | |
| content_loss = tf.add_n([tf.reduce_mean((content_outputs[name]-content_targets[name])**2) | |
| for name in content_outputs.keys()]) | |
| content_loss *= content_weight / len(content_layers) | |
| loss = style_loss + content_loss | |
| return loss |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment