A Deep Learning based image retrieval tool!
Table of Contents
This is a ResNet50 based reverse image lookup tool , that can help you find similar images in a large database.
It used 2048 dimenional vector representation of images to compare two similar using cosine distance, It uses hdf5 for storing features.
It is implemented as a class that has two funtions that can be called :
- generate_feature_embeddings with arguments (database path , batch size) - This generates the 2048 dimensional vector representations and saves them in an hdf5 file
- query with arguments number of results , path of the picture being queried , path of databse. This returns a list of filenames in the database which are similar to the queried picture
It has been dockerised , and has flask support for deployment.
How to setup on your machine
It has been tested on Windows and Linux, although it can run on macOS with little or no modification.
Tensorflow,keras has been omitted in the requirements.txt , user can opt for tensorflow-gpu(recomended) or tensorflow-cpu and pip install keras
Docker-> if you want to run a simple image without the fuss or setting up everything.
- Clone the repo and Change directory
git clone https://github.com/your_username_/Project-Name.git cd Reverse_Image_Search/ - Build Docker Image
docker build --tag <IMAGE-NAME-YOU-WANT> .
- Run Docker Container
An example would be
docker run -it -e GENEMBED=<TRUE or FALSE> -v path/to/database:/usr/share/reverseimagesearch/database -v path/to/uploads_folder:/usr/share/reverseimagesearch/uploads -p <port you want to use>:7000 --name reverseimagesearch_container <IMAGE-NAME-YOU-WANT>
docker run -it -e GENEMBED=TRUE -v $(pwd)/database:/usr/share/reverseimagesearch/database -v $(pwd)/uploads:/usr/share/reverseimagesearch/uploads -p 5000:7000 --name reverseimagesearch_container reverseimagesearch_image
- Clone the repo and Change directory
git clone https://github.com/your_username_/Project-Name.git
cd Reverse_Image_Search/- install required python packages (install tensorflow gpu if you want fast performance)
pip install -r requirements.txt pip install tensorflow-cpu pip install keras
- Run model_api_class.py to test api functionality
An example would be
python3 model_api_class.py <path to database> <path to query picture>
python3 model_api_class.py ./database ./query_pic.jpg
Currently there is no error handling in the file io as in
if the database has a non image type , then the program will simply break
Your system may need some dependencies for opencv to work, look up how to setup opencv for your machine
Bazif Rasool - @BazifRasool - baziflaherwal@gmail.com

