A while back Kaggle launched a very interesting landmark retrieval challenge. This challenge had a large dataset of landmark images. Given an image query, the program should find similar landmark images from the dataset. For example, when an image of Alhambra Palace of Spain is given as a query image, the program should find and bring other images of the same landmark images from the dataset. For further details please visit Kaggle.
Google’s Inception, popularly known as GoogLeNet is a Deep Learning Convolutional Neural Network (CNN) architecture. It was originally designed for ImageNet Large-Scale Visual Recognition Challenge 2014 (ILSVRC 2014). It has been battle-tested, delivering world-class results in that challenge.Pre-requisites
We are going to use Python 3.6 and TensorFlow. Once python is installed, make sure it is accessible in command prompt. If it is not accessible, we need to add it in the system path.
We also need to install TensorFlow. Installation guide for TensorFlow can be found here.
Preparing Training set
Kaggle has provided index.csv file containing around 1600 different landmarks images which can be found here. For simplicity we are going to hand pick around 20 landmarks from this 1600 list. This idea can be extended to Kaggle’s complete dataset as well. Our simplified version of training dataset can be found here. It’s a CSV file which contains URLs of images from different landmarks. Let’s first download the images using the CSV file provided above. We have provided a python script which will help downloading this large set of images. This script can be found here. To run this script, we need to install a dependency via PIP.
> pip install tqdm
After installing tdqm we need to run this script with following arguments.
> python download.py train.csv ./training_images
Are you Ready to leverage Machine Learning ?
We offer our clients the opportunity to create their own machine learning applications. INNOVATE NOW !!
Training Inception Model
We need to install TensorFlow Hub. TensorFlow Hub is a library for reusable parts of machine learning models. We will train our Inception model on top of existing training data from TensorFlow Hub.
> pip install tensorflow-hub
Now we need to get the script for re-training our Inception. Google has provided a script in TensorFlow examples which can be downloaded from here. After downloading run the script with following arguments.
> python ./retrain.py –image_dir ./training_images/ –output_graph ./retrained_graph.pb –intermediate_output_graphs_dir ./intermediate_graph/ –output_labels ./retrained_labels.txt –how_many_training_steps 500 –summaries_dir ./summaries/ –bottleneck_dir ./bottleneck_data/ –final_tensor_name “final_result” –saved_model_dir ./model/
This command will take approximately 30 minutes to run depending on system configuration. We are running it with lower number of how_many_training_steps for quick training. For production purposes increase it to 4000 or above. Once this command finishes our Inception model is ready for testing.
Testing Inception Trained Model
Our testing images can be found here. These pictures are slightly different from the ones we trained our model on. And we have to test how much close our Inception model can figure out its resemblance. Let’s download a script from TensorFlow example which will feed our test image to our trained Inception model and predict result. This script can be found here. Create a folder called “testing_images” and put all testing images there and run the following command.
> python.exe .\label_image.py –graph .\retrained_graph.pb –labels .\retrained_labels.txt — input_layer “Placeholder” –output_layer “final_result” –image .\test_images\1.jpg
It will give the result in probability showing how much likely the given image matches with dataset categories. Below is an example of result.
Alhambra Spain 0.73449653
Atlantis Hotel 0.053302728
Peace Palace 0.03108669
Flinders Street Station 0.020717677
When testing on a dataset containing pictures of 40-50 landmarks and every landmark having sufficient images to train on, Inception gives very high accuracy. You can use it off-the-shelf just by training it on a data set of landmark images.
Please feel free to reach out to us, if you have any questions. In case you need any help with development, installation, integration, up-gradation and customization of your Business Solutions.
We have expertise in Deep learning, Computer Vision, Predictive learning, CNN, HOG and NLP.
Connect with us for more information at [email protected]