url = 'https://nicolekessler.files.wordpress.com/2013/04/hellish_demons.jpg?w=1024'
- We first download the image
- Resize it for faster computation
def download(url, max_dim=None): name = "demons.jpg" image_path = tf.keras.utils.get_file(name, origin=url) img = PIL.Image.open(image_path) if max_dim: img.thumbnail((max_dim, max_dim)) return np.array(img)
- This is a process called normalization
- tf.cast is used to convert the tensor into a 8 bit integer value representation
def deprocess(img): img = 255 * (img + 1.0) / 2.0 return tf.cast(img, tf.uint8)
- just a wrapper to convert the tensor into an array and display
def show(img): display.display(PIL.Image.fromarray(np.array(img)))
original_img = download(url, max_dim=500) show(original_img)