GithubHelp home page GithubHelp logo

jbantony / object-detection-counter-api Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 138 KB

Perform Object Detection and counting on Image data using API endpoint served in Docker

License: MIT License

Dockerfile 9.89% Python 90.11%
docker fastapi object-detection opencv-python yolov3 ai-serving object-counter object-counting-api yolo

object-detection-counter-api's Introduction

YOLO ObjectDetection and Object Counter as API in Docker

API endpoint to run object detection and counting using YOLOv3. The user can send an image to the defined API endpoint and the detected results as well as the counts, will be received as response.

Goal

The goal of this project is to test and demonstrate the AI-Serving concept, by deploying the Object Detection model as a docker image, so that any application can be interacted with this docker by making a POST request at the API endpoint with an image data and can receive the detection results and counts as the response.

Object Detection API once deployed in a dockerfile shall receive the data input over a JSON Query and after inference generate the output and make it available in a JSON format.

The API has been developed in FastAPI and made available as docker.

Model

For the initial implementation a YOLOv3 model trainied on COCO dataset has been used in this configuration. This can detect the 80 different classes of objects as given in the COCO. The model weights can be downloaded from "https://pjreddie.com/media/files/yolov3.weights"

Build the Docker

During the docker build, the YOLOv3 weights have been downloaded and integrated to the image.

Build and tag the docker image using: docker build -t od-api .

After sucessfull building, run the docker using: docker run -ti --rm -p 5000:5000 od-api

API Endpoints

Endpoint /

Gives a health message in JSON format as follows "message":"Welcome to object detection API"

Endpoint /detect/

The endpoint /detect/ is used to perform object detection on the given image. This return a JSON file in the below format:

{
    "filename": "...",
    "detection results": {
        "detected objects":{
        "label": [...],
        "confidence": [...],
        "boxes": [[x,y,w,h], [x1,y1,w1,h1], ...]
    },
    "counts":{
        "class name": "no of instances", ...
    },
    "image height": ...,
    "image width": ...
    }
}

where the detection results gives the information on the detected objects including the label, confidence and bounding boxes. The counts gives the total count of each classes in the given image.

Usage

After deploying the docker locally, one can make a POST request using the curl command:

curl -X POST -F "file=@/path/to/image.jpg" http://localhost:5000/detect/ and gives the JSON data in the above mentioned format as response.

Demo

The /detect/ endpoint responses as follows: From FastAPI Documentation

Raw JSON data of the result:

{
  "filename": "image1.jpg",
  "detection results": {
    "detected objects": {
      "label": [
        "person",
        "dog",
        "dog"
      ],
      "confidence": [
        64,
        99,
        99
      ],
      "boxes": [
        [
          777,
          5,
          247,
          438
        ],
        [
          19,
          37,
          304,
          499
        ],
        [
          352,
          77,
          683,
          519
        ]
      ]
    },
    "counts": {
      "person": 1,
      "dog": 2
    },
    "image height": 636,
    "image width": 1024
  }
}

Notes

The latest OpenCV version 4.7 is having bugs and therefore the OpenCV version 4.6 has been used for the inference

TODO

  • Extend the detect endpoint to send detected image.
  • Update the notebooks folder with the model generating notebook for a custom dataset

object-detection-counter-api's People

Contributors

jbantony avatar

Stargazers

 avatar

Watchers

 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.