Coder Social home page Coder Social logo

ducanhho2296 / yolov5_segmentation_onnx Goto Github PK

View Code? Open in Web Editor NEW
9.0 0.0 4.0 3.17 MB

a implementation real-time instance segmentation with YOLOv5 using ONNX Runtime and streaming the results to a web browser with FastAPI

Python 96.23% HTML 3.77%
deep-learning fastapi object-detection onnxruntime segmentation yolov5

yolov5_segmentation_onnx's Introduction

Real-time Instance Segmentation using YOLOv5 and ONNX Runtime

This is a approach for real-time instance segmentation using YOLOv5 and ONNX Runtime. The project uses YOLOv5 to detect objects in the input video stream and then performs instance segmentation to create a binary mask for each detected object. The resulting masks are then overlaid on the original video frames to highlight the detected objects.

Requirements

To run this project, you need the following libraries installed:

  • PyTorch
  • OpenCV
  • NumPy
  • ONNX Runtime

The following command:

pip install -r requirements.txt

Usage

  1. Clone this repository

  2. Download the YOLOv5 segmentation model

This project uses a custom dataset trained on YOLOv5 from Ultralytics. You can download the YOLOv5 model checkpoints from the official repository.

  1. Update the model variable in the realtime_segmentation.py file with the path to your downloaded YOLOv5 model.
model = "path/to/yolov5.pt"
  1. Run the realtime_segmentation.py file.
python realtime_segmentation.py
  1. The program will open the default camera on your computer and start detecting and segmenting objects in real-time. You can press the 'q' key to quit the program.

Streaming segmented objects with FastAPI

This project also includes an implementation using FastAPI to stream the segmented frames to a web browser using both HTTP and WebSockets.

Usage

  1. Run the FastAPI app for HTTP streaming using the following command:
uvicorn app:app --host 0.0.0.0 --port 8000
  1. Open your web browser and visit http://0.0.0.0:8000/ to view the processed video stream using HTTP.

  2. To use WebSockets for streaming, run the script websockets_streaming.py .

  3. Run the FastAPI app for WebSocket streaming using the same command as in step 1:

uvicorn app:app --host 0.0.0.0 --port 8000
  1. Open your web browser and visit http://0.0.0.0:8000/ to view the processed video stream using WebSockets.

Result:

download

Credits

This project is inspired by the Ultralytics YOLOv5 repository. The project uses their implementation of YOLOv5 for object detection, instance segmentation and their color mapping function for coloring the object masks. The project also uses the ONNX Runtime library for inference.

yolov5_segmentation_onnx's People

Contributors

ducanh-ho2296 avatar

Stargazers

apan avatar  avatar Zeng Lingqi avatar Usama avatar  avatar Ashish avatar Ashleyshark avatar  avatar cvyang 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.