No project description provided
Project description
ASOne
Table of Contents
Introduction
Asone 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.
Prerequisite
- Make sure to install
GPU
drivers in your system if you want to useGPU
. Follow driver installation for further instructions. - Make sure you have MS Build tools installed in system if using windows.
- Download git for windows if not installed.
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
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
Usage
Detector
Use detector on a img using gpu
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).get_detector() # 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)
Change detector by simply changing detector flag. 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
Tracker
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=args.use_cuda)
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
Change Tracker by simply changing the tracker flag.
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)
Run main.py
to test tracker on data/sample_videos/test.mp4
video
# run on gpu
python main.py data/sample_videos/test.mp4
# run on cpu
python main.py data/sample_videos/test.mp4 --cpu
Results on provided sample video
To setup ASOne using Docker follow instructions given in docker setup
Offered By: | Maintained By: |
---|---|
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Hashes for asone-0.1.2.dev11-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2d794a08de525ce9130eb59e23ec196dcfefdd6bfbf5119e1b7e364f492bc79c |
|
MD5 | e0d814b34387c72a098961f1924980a9 |
|
BLAKE2b-256 | 559c36e11b623ab120b73819bf02bf560fd5fa861201fe5d98bdf3ec9cfad9b1 |