Skip to content

Latest commit

 

History

History
69 lines (46 loc) · 1.62 KB

README.md

File metadata and controls

69 lines (46 loc) · 1.62 KB

FastAPI Backend Service supporting image classification

This is my backend service that supports image classification using ResNet model (with torch) and FastAPI. This also have task queue management with celery.

Build and run the docker

docker compose build
docker compose up

If you want to run in your machine instead of run in docker environment, follow the below instructions:

Install the requirements

poetry install

Start services

Run the Redis database

Install redis db or run via docker:

docker run --name redis -d --rm -p 6379:6379 redis

Run the API service

poetry run uvicorn --reload "imgnet.main:app"

Run the worker

poetry run celery -A imgnet.worker.celery worker -l DEBUG

Run the flower (optional)

poetry run celery -A imgnet.worker.celery flower

Usage

Send the file

wget https://upload.wikimedia.org/wikipedia/commons/7/7d/Labrador_Chocolate.jpg
curl --location 'http://localhost:8000/api/classify' --form 'file=@"./Labrador_Chocolate.jpg"'
# => {"job_id":"1864a0b5-a34e-4c3d-88c2-aa906aeecb71"}

Fetch the result

curl http://localhost:8000/api/fetch-job/1864a0b5-a34e-4c3d-88c2-aa906aeecb71
# => {"status":"PENDING","result":null}
# or {"status":"SUCCESS","result":[{"name":"flat-coated retriever","prob":0.3873564600944519},{"name":"Labrador retriever","prob":0.22092069685459137},{"name":"vizsla","prob":0.1640702337026596},{"name":"German short-haired pointer","prob":0.049478743225336075},{"name":"curly-coated retriever","prob":0.04324338585138321}]}

Access Flower

Via localhost:5555