Coder Social home page Coder Social logo

divo12 / image-retrieval-service Goto Github PK

View Code? Open in Web Editor NEW

This project forked from singnet/image-retrieval-service

0.0 0.0 0.0 13.58 MB

Implementing image retrieval with siamese newtorks and resnet feature extractor approches

License: MIT License

Dockerfile 0.24% Python 4.90% Jupyter Notebook 94.35% Shell 0.51%

image-retrieval-service's Introduction

singnetlogo

CircleCI

Image Retrieval in Pytorch

This Project implements image retrieval from large image dataset using different image similarity measures based on the following two approaches.

  • Based on Siamese Network which is neural network architectures that contain two or more identical subnetworks
    • can be used for predefined image dataset and must be trained on that image dataset to work for our purpose

  • Using Resnet pre-trained Network to extract features and store them based on LSH simmilarity to get faster responce for large dataset

Description

  • Siamese Network
    • to train on new dataset look at Siamese-networks-train.ipynb

    • after training on that dataset it can return simmilarity measure between images

         example code at  SiameseTest.py
      
  • Using Pretrained resent18 model
    • after feature extraction using pretrained model it calculates image simmilarity

         example code at  storeLSH.ipynb
      

Install prerequisites

Using pip

  #To install requirements for the project 
  $ pip install -r requirements.txt

  $ pip install grpcio
  $ pip install grpcio-tools

Setup

  run the following command to generate gRPC classes for Python

  # only in Service folder run
  $ python3.6 -m grpc_tools.protoc -I. --python_out=. --grpc_python_out=. image_retrival.proto

Usage

To run it on your own image, use the following command. Please make sure to see their paper / the code for more details.

   # on project directory this will start the server 
   $ python  start_service.py

Using docker with GPU, CPU

If you have a nvidia-docker2 installed, we have Dockerfile.gpu which you can use to build your image or if that doesn't exist.

./deploy_service.sh

Note the above script resolves to build the docker container depending on the availability of nvidia-docker. Also without GPU the cosine similarity and euclidean similarity measure computation takes 6+ hours. It's best suited to have a GPU.

How to Use the docker image

We need to mount the classed_data folder as that is the images we are going to return reside in.

  # this will open port 50051 and run the service 
  docker run -it -v $PWD/data/classed_data:/image-retrieval-in-pytorch/data/classed_data -p 8003:8003 -p 8004:8004 singularitynet:image-retrieval-cpu

How to preprocess datasets and Generate Hash Table

cd models/
#download dataset using
bash download.bash

#to create classed_data folder to generate hash tables
python preprocess.py

#to generate hash table 
# Look at the class to work on specific dataset from ours
python generate_hashtable.py

How to generate the hash table

  • As given in storeLSH.ipynb you can initialize LSH engine and add image embedding after hashing and comparing them either by cosine similarity or Euclidean distance . then you will save the table using pickle

Testing output

  • first read the pickle file and then you can query the image you have on that hash table . it will return the index that is similar , in our case the image path

TODO

preparing a better cleaner and good resolution data-set can improve the output results

Authors

image-retrieval-service's People

Contributors

israelabebe avatar tesyolan avatar harveyslash avatar choco31415 avatar edyirdaw avatar fanshia avatar shashankp avatar dshahrokhian avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.