How it works...

We first loaded the two images, then loaded the pre-trained network weights and assigned layers to the original and style images. We calculated three loss functions: an original image loss, a style loss, and a total variation loss. Then we trained random noise pictures to use the style of the style image and the content of the original image.

The loss functions were heavily influenced by the GitHub neural style project: https://github.com/anishathalye/neural-style . We also strongly recommend that readers look at the code in those projects for improvements, more details, and a generally more robust algorithm that can give better results.

Get TensorFlow Machine Learning Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.