Giter Site home page Giter Site logo

objectdetector-api's Introduction

Pytorch Object Detector - FastAPI App

alt text

Takes an image as input and returns metadata (JSON), extracted from the image

Changelog

  • 1.0.0 First release.

Development

  1. python3 -m venv .venv
  2. activate venv via: source .venv/bin/activate
  3. pip install -r requirements-dev.txt
  4. enjoy!

Tests

  1. activate venv via: source .venv/bin/activate
  2. Run python3 -m pytest into project-root.

This will trigger unit tests and a simple Demo that:

  1. Uses test image data from tests/input folder
  2. calls in memory endpoint for prediction making
  3. print the desired metadata results.

Start FastAPI app locally

uvicorn app.main:app

Build Docker container

docker build -t objectdetector

Start app via Docker container

docker run: docker run -v /tmp/output:/tmp/output -p 5000:5000 -e APP_PORT=5000 -e APP_HOST=0.0.0.0 -e OUTPUT_DIR=/tmp/output -d

OR

docker compose: docker-compose up --build -d

Configuration

Environment Variables

  • APP_PORT: it enables custom port for deployment by overriding it. Default 8000 .
  • APP_HOST: it enables custom host for deployment by overriding it. Default 0.0.0.0 .
  • OUTPUT_DIR: it enables custom output dir by overriding it. Default /tmp/output. Note: it may be required to previously create folder on host filesystem, depending on your OS.

These variables are already configured both in above docker run command and docker-compose.

Json Configuration

Default App configuration is located under config/config.json. It would be possibile to change configuration path by overriding env variable CONFIG_PATH.

In configuration, it is possibile to change parameter related to:

  • confidence: decision threshold on prediction. Predictions which score is less than the threshold are filtered out.
  • model: you can choice betweet 3 different models at the moment ("frcnn-resnet", "frcnn-mobilenet", "retinanet")

Demo

The demo script works as the following:

  1. Lookups for APP_HOST and APP_PORT variables. If not defined, they assume default values of (0.0.0.0, 5000).
  2. start docker service at the specified address (logged in console).
  3. Waits 20 seconds for service startup / model downloading (second time can be faster, SO PLEASE ADJUST SLEEP ACCORDINGLY).
  4. performs a prediction request for every file comprised in ./tests/input folder.
  5. Outputs filename, extracted metadata and time to perform the request.
  6. Check $OUTPUT_DIR folder for annotated images.

Bonus tip: Openapi

Extract OpenApi 3.0 json definition by calling http://$HOST:$PORT/openapi.json

Bonus tip: Swagger

Access SwaggerUI by calling http://$HOST:$PORT/docs

objectdetector-api's People

Contributors

lukpier avatar

Watchers

 avatar  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.