Search images with deep learning (keras)

Images are usually very different if we compare them at pixel level but that's quite different if we look at them after they were processed by a deep learning model. We convert each image into a feature vector extracted from an intermediate layer of the network.

Get a pre-trained model

We choose the model described in paper MobileNets: Efficient Convolutional Neural Networks for Mobile Vision Applications. Pre-trained models are available at deep-learning-models/releases.

The model is stored here:


We collect images from pixabay.

Raw images

keras implements optimized function to load and process images. Below the code with loads the images without modifying them. It creates an iterator which iterates as many times as we want.

I suggest trying without the parameter rescale to see the differences. The neural network expects numbers in [0, 1] not in [0, 255].

But you can multiply the images. See ImageDataGenerator parameters to see what kind of modifications is implemented.