Package: rheioyu58
AS-One : A Modular Library for YOLO Object Detection and Object TrackingTable of ContentsIntroductionPrerequisitesClone the RepoInstallationLinuxWindows 10/11MacOSRunning AS-OneSample Code SnippetsModel Zoo1. Introduction==UPDATE: YOLO-NAS is OUT==AS-One is a python wrapper for multiple detection and tracking algorithms all at one place. Different trackers such asByteTrack,DeepSORTorNorFaircan be integrated with different versions ofYOLOwith minimum lines of code.
This python wrapper provides YOLO models inONNX,PyTorch&CoreMLflavors. 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 ourcoursesandprojectsWatch the step-by-step tutorial2. PrerequisitesMake sure to installGPUdrivers in your system if you want to useGPU. Followdriver installationfor further instructions.Make sure you haveMS Build toolsinstalled in system if using windows.Download git for windowsif not installed.3. Clone the RepoNavigate to an empty folder of your choice.git clone https://github.com/augmentedstartups/AS-One.gitChange Directory to AS-Onecd AS-One4. InstallationFor Linuxpython3-mvenv.envsource.env/bin/activate

pipinstallnumpyCython
pipinstallcython-bboxasoneonnxruntime-gpu==1.12.1
pipinstallsuper-gradients==3.1.1# for CPUpipinstalltorchtorchvision# for GPUpipinstalltorchtorchvision--extra-index-urlhttps://download.pytorch.org/whl/cu113For Windows 10/11python-mvenv.env
.env\Scripts\activate
pipinstallnumpyCythonpipinstalllap
pipinstall-egit+https://github.com/samson-wang/cython_bbox.git#egg=cython-bbox

pipinstallasoneonnxruntime-gpu==1.12.1
pipinstallsuper-gradients==3.1.1# for CPUpipinstalltorchtorchvision# for GPUpipinstalltorchtorchvision--extra-index-urlhttps://download.pytorch.org/whl/cu113
or
pipinstalltorch==1.10.1+cu113torchvision==0.11.2+cu113torchaudio===0.10.1+cu113-fhttps://download.pytorch.org/whl/cu113/torch_stable.htmlFor MacOSpython3-mvenv.envsource.env/bin/activate

pipinstallnumpyCython
pipinstallcython-bboxasone
pipinstallsuper-gradients==3.1.1# for CPUpipinstalltorchtorchvision5. Running AS-OneRunmain.pyto test tracker ondata/sample_videos/test.mp4videopython main.py data/sample_videos/test.mp4Run inGoogle Colab6. Sample Code Snippets6.1. Object DetectionimportasonefromasoneimportutilsfromasoneimportASOneimportcv2video_path='data/sample_videos/test.mp4'detector=ASOne(detector=asone.YOLOV7_PYTORCH,use_cuda=True)# Set use_cuda to False for cpufilter_classes=['car']# Set to None to detect all classescap=cv2.VideoCapture(video_path)whileTrue:_,frame=cap.read()ifnot_:breakdets,img_info=detector.detect(frame,filter_classes=filter_classes)bbox_xyxy=dets[:,:4]scores=dets[:,4]class_ids=dets[:,5]frame=utils.draw_boxes(frame,bbox_xyxy,class_ids=class_ids)cv2.imshow('result',frame)ifcv2.waitKey(25)&0xFF==ord('q'):breakRun theasone/demo_detector.pyto test detector.# run on gpupython-masone.demo_detectordata/sample_videos/test.mp4# run on cpupython-masone.demo_detectordata/sample_videos/test.mp4--cpu6.1.1 Use Custom Trained Weights for DetectorUse your custom weights of a detector model trained on custom data by simply providing path of the weights file.importasonefromasoneimportutilsfromasoneimportASOneimportcv2video_path='data/sample_videos/license_video.webm'detector=ASOne(detector=asone.YOLOV7_PYTORCH,weights='data/custom_weights/yolov7_custom.pt',use_cuda=True)# Set use_cuda to False for cpuclass_names=['license_plate']# your custom classes listcap=cv2.VideoCapture(video_path)whileTrue:_,frame=cap.read()ifnot_:breakdets,img_info=detector.detect(frame)bbox_xyxy=dets[:,:4]scores=dets[:,4]class_ids=dets[:,5]frame=utils.draw_boxes(frame,bbox_xyxy,class_ids=class_ids,class_names=class_names)# simply pass custom classes list to write your classes on result videocv2.imshow('result',frame)ifcv2.waitKey(25)&0xFF==ord('q'):break6.1.2. Changing Detector ModelsChange detector by simply changing detector flag. The flags are provided inbenchmarktables.Our library now supports YOLOv5, YOLOv7, and YOLOv8 on macOS.# Change detectordetector=ASOne(detector=asone.YOLOX_S_PYTORCH,use_cuda=True)# For macOs# YOLO5detector=ASOne(detector=asone.YOLOV5X_MLMODEL)# YOLO7detector=ASOne(detector=asone.YOLOV7_MLMODEL)# YOLO8detector=ASOne(detector=asone.YOLOV8L_MLMODEL)6.2. Object TrackingUse tracker on sample video.importasonefromasoneimportASOne# Instantiate Asone objectdetect=ASOne(tracker=asone.BYTETRACK,detector=asone.YOLOV7_PYTORCH,use_cuda=True)#set use_cuda=False to use cpufilter_classes=['person']# set to None to track all classes# ###############################################           To track using video file# ############################################### Get tracking functiontrack=detect.track_video('data/sample_videos/test.mp4',output_dir='data/results',save_result=True,display=True,filter_classes=filter_classes)# Loop over track to retrieve outputs of each frameforbbox_details,frame_detailsintrack:bbox_xyxy,ids,scores,class_ids=bbox_detailsframe,frame_num,fps=frame_details# Do anything with bboxes here# ###############################################           To track using webcam# ############################################### Get tracking functiontrack=detect.track_webcam(cam_id=0,output_dir='data/results',save_result=True,display=True,filter_classes=filter_classes)# Loop over track to retrieve outputs of each frameforbbox_details,frame_detailsintrack:bbox_xyxy,ids,scores,class_ids=bbox_detailsframe,frame_num,fps=frame_details# Do anything with bboxes here# ###############################################           To track using web stream# ############################################### Get tracking functionstream_url='rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mp4'track=detect.track_stream(stream_url,output_dir='data/results',save_result=True,display=True,filter_classes=filter_classes)# Loop over track to retrieve outputs of each frameforbbox_details,frame_detailsintrack:bbox_xyxy,ids,scores,class_ids=bbox_detailsframe,frame_num,fps=frame_details# Do anything with bboxes here[Note] Use can use custom weights for a detector model by simply providing path of the weights file. inASOneclass.6.2.1 Changing Detector and Tracking ModelsChange Tracker by simply changing the tracker flag.The flags are provided inbenchmarktables.detect=ASOne(tracker=asone.BYTETRACK,detector=asone.YOLOV7_PYTORCH,use_cuda=True)# Change trackerdetect=ASOne(tracker=asone.DEEPSORT,detector=asone.YOLOV7_PYTORCH,use_cuda=True)# Change Detectordetect=ASOne(tracker=asone.DEEPSORT,detector=asone.YOLOX_S_PYTORCH,use_cuda=True)Run theasone/demo_detector.pyto test detector.# run on gpupython-masone.demo_detectordata/sample_videos/test.mp4# run on cpupython-masone.demo_detectordata/sample_videos/test.mp4--cpu6.3. Text DetectionSample code to detect text on an image# Detect and recognize textimportasonefromasoneimportutilsfromasoneimportASOneimportcv2img_path='data/sample_imgs/sample_text.jpeg'ocr=ASOne(detector=asone.CRAFT,recognizer=asone.EASYOCR,use_cuda=True)# Set use_cuda to False for cpuimg=cv2.imread(img_path)results=ocr.detect_text(img)img=utils.draw_text(img,results)cv2.imwrite("data/results/results.jpg",img)Use Tracker on TextimportasonefromasoneimportASOne# Instantiate Asone objectdetect=ASOne(tracker=asone.DEEPSORT,detector=asone.CRAFT,recognizer=asone.EASYOCR,use_cuda=True)#set use_cuda=False to use cpu# ###############################################           To track using video file# ############################################### Get tracking functiontrack=detect.track_video('data/sample_videos/GTA_5-Unique_License_Plate.mp4',output_dir='data/results',save_result=True,display=True)# Loop over track to retrieve outputs of each frameforbbox_details,frame_detailsintrack:bbox_xyxy,ids,scores,class_ids=bbox_detailsframe,frame_num,fps=frame_details# Do anything with bboxes hereRun theasone/demo_ocr.pyto test ocr.# run on gpupython-masone.demo_ocrdata/sample_videos/GTA_5-Unique_License_Plate.mp4# run on cpupython-masone.demo_ocrdata/sample_videos/GTA_5-Unique_License_Plate.mp4--cpu6.4. Pose EstimationSample code to estimate pose on an image# Pose EstimationimportasonefromasoneimportutilsfromasoneimportPoseEstimatorimportcv2img_path='data/sample_imgs/test2.jpg'pose_estimator=PoseEstimator(estimator_flag=asone.YOLOV8M_POSE,use_cuda=True)#set use_cuda=False to use cpuimg=cv2.imread(img_path)kpts=pose_estimator.estimate_image(img)img=utils.draw_kpts(img,kpts)cv2.imwrite("data/results/results.jpg",img)Now you can use Yolov8 and Yolov7-w6 for pose estimation. The flags are provided inbenchmarktables.# Pose Estimation on videoimportasonefromasoneimportPoseEstimatorvideo_path='data/sample_videos/football1.mp4'pose_estimator=PoseEstimator(estimator_flag=asone.YOLOV7_W6_POSE,use_cuda=True)#set use_cuda=False to use cpuestimator=pose_estimator.estimate_video(video_path,save=True,display=True)forkpts,frame_detailsinestimator:frame,frame_num,fps=frame_detailsprint(frame_num)# Do anything with kpts hereRun theasone/demo_pose_estimator.pyto test Pose estimation.# run on gpupython-masone.demo_pose_estimatordata/sample_videos/football1.mp4# run on cpupython-masone.demo_pose_estimatordata/sample_videos/football1.mp4--cpuTo setup ASOne using Docker follow instructions given indocker setupToDoFirst ReleaseImport trained modelsSimplify code even furtherUpdated for YOLOv8OCR and CountingOCSORT, StrongSORT, MoTPyM1/2 Apple Silicon CompatibilityPose Estimation YOLOv7/v8YOLO-NASSAM IntegrationOffered By:Maintained By: