Skip to main content

No project description provided

Project description

AS-One : A Modular Libary for YOLO Object Detection and Object Tracking BETA

croped

Table of Contents

  1. Introduction
  2. Prerequisites
  3. Clone the Repo
  4. Installation
  5. Running AS-One
  6. Usage
  7. Benchmarks

1. Introduction

AS-One is a python wrapper for multiple detection and tracking algorithms all at one place. Different trackers such as ByteTrack, DeepSort or NorFair can be integrated with different versions of YOLO with minimum lines of code. This python wrapper provides YOLO models in both ONNX and PyTorch versions. We plan to offer support for future versions of YOLO when they get released.

This is One Library for most of your computer vision needs.

If you would like to dive deeper into YOLO Object Detection and Tracking, then check out our courses and projects

Watch the step-by-step tutorial

2. Prerequisites

3. Clone the Repo

Navigate to an empty folder of your choice.

git clone https://github.com/augmentedstartups/AS-One.git

Change Directory to AS-One

cd AS-One

4. Installation

For Linux

python3 -m venv .env
source .env/bin/activate

pip install numpy Cython
pip install cython-bbox

pip install asone


# for CPU
pip install torch torchvision

# for GPU
pip install torch torchvision --extra-index-url https://download.pytorch.org/whl/cu113

For Windows 10/11

python -m venv .env
.env\Scripts\activate
pip install numpy Cython
pip install -e git+https://github.com/samson-wang/cython_bbox.git#egg=cython-bbox

pip install asone

# for CPU
pip install torch torchvision

# for GPU
pip install torch torchvision --extra-index-url https://download.pytorch.org/whl/cu113
or
pip install torch==1.10.1+cu113 torchvision==0.11.2+cu113 torchaudio===0.10.1+cu113 -f https://download.pytorch.org/whl/cu113/torch_stable.html

Run in Google Colab

Open In Colab

5. Running AS-One

Run main.py to test tracker on data/sample_videos/test.mp4 video

import asone
from asone import utils
from asone.detectors import Detector
import cv2

img = cv2.imread('data/sample_imgs/test2.jpg')
detector = Detector(asone.YOLOV7_E6_ONNX, use_cuda=True) # Set use_cuda to False for cpu

filter_classes = ['person'] # Set to None to detect all classes

dets, img_info = detector.detect(img, , filter_classes=filter_classes)

bbox_xyxy = dets[:, :4]
scores = dets[:, 4]
class_ids = dets[:, 5]

img = utils.draw_boxes(img, bbox_xyxy, class_ids=class_ids)
cv2.imwrite('result.png', img)

Use Custom Trained Weights

Use your custom weights of a detector model trained on custom data by simply providing path of the weights file.

import asone
from asone import utils
from asone.detectors import Detector
import cv2

img = cv2.imread('data/sample_imgs/test2.jpg')
detector = Detector(asone.YOLOV7_PYTORCH, weights="data/custom_weights/yolov7_custom.pt", use_cuda=True) # Set use_cuda to False for cpu

filter_classes = ['person'] # Set to None to detect all classes

dets, img_info = detector.detect(img, , filter_classes=filter_classes)

bbox_xyxy = dets[:, :4]
scores = dets[:, 4]
class_ids = dets[:, 5]

img = utils.draw_boxes(img, bbox_xyxy, class_ids=class_ids, class_names=['License Plate']) # class_names are names of classes in your dataset
cv2.imwrite('result.png', img)

Changing Detector Models

Change detector by simply changing detector flag. The flags are provided in benchmark tables.

# Change detector
detector = Detector(asone.YOLOX_S_PYTORCH, use_cuda=True)

Run the asone/demo_detector.py to test detector.

# run on gpu
python -m asone.demo_detector data/sample_imgs/test2.jpg

# run on cpu
python -m asone.demo_detector data/sample_imgs/test2.jpg --cpu

Object Tracking

Video

Use tracker on sample video using gpu.

import asone
from asone import ASOne

# Instantiate Asone object
dt_obj = ASOne(tracker=asone.BYTETRACK, detector=asone.YOLOX_DARKNET_PYTORCH, use_cuda=True)

filter_classes = ['person'] # set to None to track all classes

# Get tracking function
track_fn = dt_obj.track_video('data/sample_videos/test.mp4', output_dir='data/results', save_result=True, display=True, filter_classes=filter_classes)

# Loop over track_fn to retrieve outputs of each frame 
for bbox_details, frame_details in track_fn:
    bbox_xyxy, ids, scores, class_ids = bbox_details
    frame, frame_num, fps = frame_details
    # Do anything with bboxes here

# To track using webcam
# Get tracking function
track_fn = dt_obj.track_webcam(cam_id=0, output_dir='data/results', save_result=True, display=True, filter_classes=filter_classes)

# Loop over track_fn to retrieve outputs of each frame 
for bbox_details, frame_details in track_fn:
    bbox_xyxy, ids, scores, class_ids = bbox_details
    frame, frame_num, fps = frame_details
    # Do anything with bboxes here

Use Custom Trained Weights for Detector

Use your custom weights of a detector model trained on custom data by simply providing path of the weights file.

import asone
from asone import ASOne

# Instantiate Asone object
dt_obj = ASOne(tracker=asone.BYTETRACK, detector=asone.YOLOX_DARKNET_PYTORCH, weights='data/custom_weights/yolov7_custom.pt', use_cuda=True)

filter_classes = ['person'] # set to None to track all classes

# Get tracking function
track_fn = dt_obj.track_video('data/sample_videos/test.mp4', output_dir='data/results', save_result=True, display=True, filter_classes=filter_classes, class_names=['License Plate']) #class_names are class names in your custom data

# Loop over track_fn to retrieve outputs of each frame 
for bbox_details, frame_details in track_fn:
    bbox_xyxy, ids, scores, class_ids = bbox_details
    frame, frame_num, fps = frame_details
    # Do anything with bboxes here

Changing Detector and Tracking Models

Change Tracker by simply changing the tracker flag.

The flags are provided in benchmark tables.

dt_obj = ASOne(tracker=asone.BYTETRACK, detector=asone.YOLOX_DARKNET_PYTORCH, use_cuda=True)
// Change tracker
dt_obj = ASOne(tracker=asone.DEEPSORT, detector=asone.YOLOX_DARKNET_PYTORCH, use_cuda=True)
dt_obj = ASOne(tracker=asone.DEEPSORT, detector=asone.YOLOX_S_PYTORCH, use_cuda=True)

To setup ASOne using Docker follow instructions given in docker setup

ToDo

  • First Release
  • Import trained models
  • Simplify code even further
  • Add support for other Trackers and Detectors
  • M1/2 Apple Silicon Compatibility
Offered By: Maintained By:
AugmentedStarups AxcelerateAI

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

asone-0.1.2.dev13-py3-none-any.whl (291.3 kB view details)

Uploaded Python 3

File details

Details for the file asone-0.1.2.dev13-py3-none-any.whl.

File metadata

  • Download URL: asone-0.1.2.dev13-py3-none-any.whl
  • Upload date:
  • Size: 291.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.4

File hashes

Hashes for asone-0.1.2.dev13-py3-none-any.whl
Algorithm Hash digest
SHA256 4ed1249c5494952e798cd35a2c4dd0e562a7b2bef4c73546df4457492cc1dc14
MD5 80cf4114e91112014d6f9cc09a8f60fc
BLAKE2b-256 012073302569d63cadff8b7583e8a902421a6bd59d68583465dcbdc352ed01c0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page