How to do it...

  1. Import the relevant packages and content, style images, that need to be combined to form an artistic image, as follows (The code file is available as Neural_style_transfer.ipynb in GitHub):
from keras.preprocessing.image import load_img, save_img, img_to_arrayimport numpy as npimport timefrom keras.applications import vgg19from keras.applications.imagenet_utils import preprocess_inputfrom keras import backend as Kimport tensorflow as tfimport kerasstyle_img = cv2.imread('/content/style image.png')style_img = cv2.cvtColor(style_img, cv2.COLOR_BGR2RGB)style_img = cv2.resize(style_img,(224,224))base_img = cv2.imread('/content/cat.png')base_img = cv2.cvtColor(base_img, cv2.COLOR_BGR2RGB)base_img = cv2.resize(base_img,(224,224)) ...

Get Neural Networks with Keras Cookbook 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.