Loading images using the Keras API
In this recipe, we will learn how to load images using the Keras API, a very important task considering that, in computer vision, we'll always work with visual data. In particular, we'll learn how to open, explore, and visualize a single image, as well as a batch of them. Additionally, we will learn how to programmatically download a dataset.
Getting ready
Keras relies on the Pillow
library to manipulate images. You can install it easily using pip
:
$> pip install Pillow
Let's get started!
How to do it…
Now, let's begin this recipe:
- Import the necessary packages:
import glob import os import tarfile import matplotlib.pyplot as plt from tensorflow.keras.preprocessing.image import ImageDataGenerator from tensorflow.keras.preprocessing.image import load_img, img_to_array from tensorflow.keras.utils import get_file
- Define the URL and destination of the
CINIC-10
dataset, an alternative to the famous...