August 2018
Intermediate to advanced
438 pages
12h 3m
English
The first and foremost step towards implementation of such a network is to preprocess the data or images in this case. The following code snippet shows some quick utilities to preprocess and postprocess images for size and channel adjustments:
import numpy as npfrom keras.applications import vgg16from keras.preprocessing.image import load_img, img_to_arraydef preprocess_image(image_path, height=None, width=None): height = 400 if not height else height width = width if width else int(width * height / height) img = load_img(image_path, target_size=(height, width)) img = img_to_array(img) img = np.expand_dims(img, axis=0) img = vgg16.preprocess_input(img) return imgdef deprocess_image(x): # Remove zero-center ...
Read now
Unlock full access