clementsan / object_detection_detr_api

AI-driven object detection via FastAPI

Repository from Github https://github.comclementsan/object_detection_detr_apiRepository from Github https://github.comclementsan/object_detection_detr_api

Object detection via FastAPI

Docker Pulls

example workflow example workflow

Aim: AI-driven object detection via FastAPI (on COCO image dataset)

Machine learning models:

  • facebook/detr-resnet-50
  • facebook/detr-resnet-101

Table of contents:


1. Direct execution

1.1. Run FastAPI interface

Command line in development mode:

fastapi dev app/main.py

Manual command line in production:

fastapi run app/main.py

Notes:

1.2. Run API query via curl command

Command lines:

  • Endpoint "/":

curl -X 'GET' -H 'accept: application/json' 'http://127.0.0.1:8000/'

  • Endpoint "/info":

curl -X 'GET' -H 'accept: application/json' 'http://127.0.0.1:8000/info'

  • Endpoint "/api/v1/detect":

curl -X POST -F "image=@./tests/data/savanna.jpg" http://127.0.0.1:8000/api/v1/detect

  • Endpoint "/api/v1/detect" with optional model type (e.g. detr-resnet-50 or detr-resnet-101):

curl -X POST -F "image=@./tests/data/savanna.jpg" http://127.0.0.1:8000/api/v1/detect?model=detr-resnet-50

1.3. Run API query via python script

Command line:

python app/inference_api.py -u "http://127.0.0.1:8000/api/v1/detect" -f tests/data/savanna.jpg

1.4. Tests via pytest library

Command lines:

pytest tests/ -v

pytest tests/ -s -o log_cli=true -o log_level=DEBUG

2. Execution via docker container

2.1. Build image and run docker container

Command lines:

sudo docker build -t object-detection-detr-api .

sudo docker run --name object-detection-detr-api-cont -p 8000:8000 object-detection-detr-api

2.2. Run query via API

Command lines:

  • Endpoint "/":

curl -X 'GET' 'http://0.0.0.0:8000/' -H 'accept: application/json'

  • Endpoint "/info":

curl -X 'GET' -H 'accept: application/json' 'http://0.0.0.0:8000/info'

  • Endpoint "/api/v1/detect":

curl -X 'POST' -F "image=@./tests/data/savanna.jpg" http://0.0.0.0:8000/api/v1/detect

  • Endpoint "/api/v1/detect" with optional model type (e.g. detr-resnet-50 or detr-resnet-101):

curl -X POST -F "image=@./tests/data/savanna.jpg" http://0.0.0.0:8000/api/v1/detect?model=detr-resnet-50

3. Deployment on Docker hub

This FastAPI application is available as a Docker container on Docker hub

URL: https://hub.docker.com/r/cvachet/object-detection-detr-api

4. MLOps pipeline via GitHub actions

Github actions were created to enable Continuous Integration (CI) and Continuous Deployment (CD) for this FastAPI app.

YAML files:

About

AI-driven object detection via FastAPI


Languages

Language:Python 96.3%Language:Dockerfile 3.7%