Let's implement these steps in code (The code file is available as Deepdream.ipynb in GitHub):
- Import the relevant packages and import the image:
import keras.backend as Kimport multiprocessingimport tensorflow as tfimport warningsfrom keras.applications.vgg19 import VGG19from keras.applications.imagenet_utils import preprocess_inputfrom scipy.optimize import minimizefrom skimage import img_as_float, img_as_ubytefrom skimage.io import imread, imsavefrom skimage.transform import pyramid_gaussian, rescaleimport scipyfrom keras.preprocessing import imagefrom keras.applications.vgg19 import preprocess_inputimport matplotlib.pyplot as plt%matplotlib inline
Preprocess the image so that it can then be passed to the VGG19 model: ...