harshraj22 / Dis-Sim

Microservice for calculating image similarity. Uses Message Queues.
MIT License
9 stars 3 forks source link
celery computer-vision docker docker-compose fastapi kafka locust message-queue microservices-architecture redis sqlite3 streamlit

Intro:

Dis-Sim is a Microservices architecture based distributed image similarity measuring system. It uses asynchronous message queue to communicate across microservices. Its distributed architecture makes it highly scalable and fault tolerant. It has a built in data monitoring and analytics service which uses Kafka as a message broker, and sqlite3 as a database. It also has a subscription based rate limiter that limits the request based on the subscription tier the user belongs

architecture

Demo:

streamlit-frontend-2022-06-08-16-06-21

Getting started:

  1. Run docker-compose pull && docker-compose up to pull and start all the containers.
    Build from source: docker-compose up --build to build from the source, and not use the already built image from dockerhub.
  2. Open the browser and navigate to localhost:8501. Note that 8501 is the port specified in the dockerfile of the frontend service (src/frontend/Dockerfile).
  3. Use the existing credentials username: test, password: test. Would be soon adding frontend to register new user.

Note: Since there are multiple services spinning up, it would take a little longer for all the services to start up before you can start playing with the similarity service. The images are large, and a good internet connection is required. You can expect the whole service to spin up within 5 minutes.

Using custom similarity measurer:

Adding a custom similarity measurer is as simple as overwriding the similarity function in the src/similarity/models module.

# import your new similarity measurer

from my_similarity_measurer import MySimilarityMeasurer
# add your new similarity measurer in similarity method

@app.task
def similarity(img1, img2) -> float:
    ...

    score = MySimilarityMeasurer().similarity(img1, img2)
    return score

Make sure to add the dependencies of your new similarity measurer in src/similarity/requirements.txt

Benchmarks:

References:

Further Reading: