Implementing a feature extractor using a pre-trained network
One of the easiest ways to seize the power of transfer learning is to use pre-trained models as feature extractors. This way, we can combine both deep learning and machine learning, something that we normally cannot do, because traditional machine learning algorithms don't work with raw images. In this recipe, we'll implement a reusable FeatureExtractor
class to produce a dataset of vectors from a set of input images, and then save it in the blazingly fast HDF5 format.
Are you ready? Let's get started!
Getting ready
You'll need to install Pillow
and tqdm
(which we'll use to display a nice progress bar). Fortunately, this is very easy with pip
:
$> pip install Pillow tqdm
We'll be using the Stanford Cars
dataset, which you can download here: http://imagenet.stanford.edu/internal/car196/car_ims.tgz. Decompress the data to a location of your preference. In this recipe, we assume...