Giter VIP home page Giter VIP logo

yolov5-fastapi-demo's Introduction

yolov5-fastapi-demo

This is a demo FastAPI app that allows a user to upload image(s), perform inference using a pretrained YOLOv5 model, and receive results in JSON format. This repo also includes Jinja2 HTML templates, so you can access this interface through a web browser at localhost:8000

image

Requirements

Python 3.8 or later with all requirements.txt dependencies installed, including torch>=1.7 (per https://github.com/ultralytics/yolov5).

To install run:

pip install -r requirements.txt

Inference

You can initialize the server with python server.py or uvicorn server:app --reload

You can test the server a couple of ways:

  1. Using client.py - this is a basic example of using the Requests library to upload a batch of images + model name to localhost:8000/detect/ and receive JSON inference results.
  2. Open localhost:8000 in your web browser, use the web form to upload image(s) and select a model, then click submit. You should see inference results displayed in the web browser shortly.
  3. Open localhost:8000/docs in your web browser, clicking on "POST /detect/ Detect Via API" and then click the "Try It Out" button. You should be able to upload files and enter a YOLOv5 model here as well.

Models will automatically be downloaded the first time they are used and are cached on disc.

image

API Documentation

Full Swagger API endpoint documentation is auto-generated in localhost:8000/docs. The general idea is that humans use the "/" route (HTML form + inference results displayed in the browser) and programs use the "/detect/" API route to receive JSON inference results.

Minimal FastAPI Example

See the fastapi_yolov5_minimal_client_server_example folder for a minimal client/server wrapper of YOLOv5 with FastAPI and HTML forms.

Again, you can try this out by:

  1. Running the server with python server_minimal.py or uvicorn server_minimal:app --reload
  2. Test the server with python client_minimal.py, navigating to localhost:8000 in your web browser or localhost:8000/docs -> POST Request -> Try It Out

Credits

This repository is a wrapper around YOLOv5 from Ultralytics: https://github.com/ultralytics/yolov5

Also grabbed some code/ideas from: https://gist.github.com/decent-engineer-decent-datascientist/81e04ad86e102eb083416e28150aa2a1

yolov5-fastapi-demo's People

Contributors

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