09.05.2023 Views

pdfcoffee

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 5

Google released the DeepDream code in open source (https://github.com/

google/deepdream), but we use a simplified example made by random forest

(https://github.com/pukkapies/applied-dl/blob/master/examples/9-deepdream-minimal.ipynb):

Figure 25: A simplified version of DeepDream applied to the Seattle skyline

Let's start with some image preprocessing:

# Download an image and read it into a NumPy array,

def download(url):

name = url.split("/")[-1]

image_path = tf.keras.utils.get_file(name, origin=url)

img = image.load_img(image_path)

return image.img_to_array(img)

# Scale pixels to between (-1.0 and 1.0)

def preprocess(img):

return (img / 127.5) - 1

# Undo the preprocessing above

def deprocess(img):

img = img.copy()

img /= 2.

img += 0.5

img *= 255.

return np.clip(img, 0, 255).astype('uint8')

[ 169 ]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!