Giter Site home page Giter Site logo

ziqinyeow / juxtapose Goto Github PK

View Code? Open in Web Editor NEW
26.0 3.0 4.0 41.68 MB

juxtapose: Multi-Person Pose Tracking Inference SDK with RTMDet, YOLOv8, GDino, RTMPose (ONNX) & Trackers (ByteTrack & BotSORT) & Tapnet with custom ROIs + FastAPI GPU exe

Home Page: https://sdk.juxt.space

License: MIT License

Makefile 0.06% Python 92.28% C++ 0.77% Cuda 6.87% Dockerfile 0.02%
botsort bytetrack object-detection pose-estimation pose-tracking rtmdet rtmpose onnx region-of-interest groundingdino

juxtapose's Introduction

๐Ÿฟ Intro

Juxtapose is a 2D multi person pose detection, tracking, and estimation inference toolbox for sports + kinematics analysis. Visit Docs.

See how we integrated juxtapose into this app: Juxt Space

๐Ÿ„ Overview

Code mostly adopted from four repos -> ultralytics, mmdeploy, mmdetection, mmpose.

Supported Detectors: rtmdet-s, rtmdet-m, rtmdet-l, groundingdino, yolov8
Supported Pose Estimators: rtmpose-s, rtmpose-m, rtmpose-l
Supported Trackers: bytetrack, botsort Supported Point Trackers: Tapnet

๐Ÿฅ’ Updates

  • 2024/05/16 Remove ultralytics dependency, port yolov8 to run in ONNX directly to improve speed.
  • 2024/04/27 Added FastAPI to EXE example with ONNX GPU Runtime in examples/fastapi-pyinstaller.
  • 2024/01/11 Added Nextra docs + deployed to Vercel at sdk.juxt.space.
  • 2024/01/07 Reduce dependencies by removing MMCV, MMDet, MMPose SDK, run fully on ONNX.
  • 2023/11/01 Added juxtapose to PYPI repository so that we can install it using pip install juxtapose.
  • 2023/08/25 Added custom region of interests (ROI) drawing tools that enables multi ROIs filtering while performing pose estimation/tracking. See usage below.
  • 2023/08/15 Added GroundingDino & YOLOv8 object detector.
  • 2023/08/09 Added keypoints streaming to csv file using csv module.
  • 2023/07/31 Added ByteTrack and BotSORT. Completed engineering effort for top down inferences in any sources. See supported sources below.
  • 2023/06/15 Converted RTMDET (s/m/l) and RTMPOSE (s/m/l) to ONNX using MMDeploy.

๐Ÿ‘‰ Getting Started

Install Using PIP

pip install juxtapose

Note: If you faced any issues, kindly review this github issue

๐Ÿง€ Local Development

git clone https://github.com/ziqinyeow/juxtapose
pip install .

๐Ÿคฉ Feel The Magic

๐ŸŒ„ Basic Usage

from juxtapose import RTM

# Init a rtm model (including rtmdet, rtmpose, tracker)
model = RTM(
    det="rtmdet-m", # see type hinting
    pose="rtmpose-m", # see type hinting
    tracker="bytetrack", # see type hinting
    device="cpu",  # see type hinting
)

# Inference with directory (all the images and videos in the dir will get inference sequentially)
model("data")

# Inference with image
model("data/football.jpeg", verbose=False) # verbose -> disable terminal printing

# Inference with video
model("data/bike.mp4")

# Inference with the YouTube Source
model("https://www.youtube.com/watch?v=1vYvTbDJuFs&ab_channel=PeterGrant", save=True)

๐ŸŽจ Select Region of Interests (ROIs)

It will first prompt the user to draw the ROIs, press r to remove the existing ROI drawn. After drawing, press SPACE or ENTER or q to accept the ROI drawn. The model will filter out the bounding boxes based on the ROIs.

๐Ÿ˜ Note: Press SPACE again to redraw the bounding boxes. See custom implementation with cv2 here.

from juxtapose import RTM

model = RTM(det="groundingdino", pose="rtmpose-l", tracker="none")
model("data/bike.mp4", roi="rect") # rectangle roi

# 1. Draw ROI first
# 2. Press r or R to reset ROI
# 3. Press SPACE or Enter or q or Q to continue with the ROI

๐Ÿšดโ€โ™‚๏ธ Accessing result for each frame: More Flexibility

# Adding custom plot
import cv2
from juxtapose import RTM, Annotator

model = RTM()
annotator = Annotator(thickness=3, font_color=(128, 128, 128)) # see rtm.utils.plotting

# set show to true -> cv2.imshow the frame (you can use cv2 to plot anything in the frame)
# set plot to false -> if you want to ignore default plot -> see rtm.rtm (line `if plot:`)
for result in model("data/bike.mp4", show=True, plot=False, stream=True):
    # do what ever you want with the data
    im, bboxes, kpts = result.im, result.bboxes, result.kpts

    # e.g custom plot anything using cv2 API
    cv2.putText(
        im, "custom text", (100, 100), cv2.FONT_HERSHEY_SIMPLEX, 1.0, (128, 128, 128)
    )

    # use the annotator class -> see rtm.utils.plotting
    annotator.draw_bboxes(
        im, bboxes, labels=[f"children_{i}" for i in range(len(bboxes))]
    )
    annotator.draw_kpts(im, kpts, thickness=4)
    annotator.draw_skeletons(im, kpts)

โšฝ๏ธ Custom Forward Pass: Full Flexibility

# Custom model forward pass
import cv2
import torch
from juxtapose import RTMDet, RTMPose, Annotator

frame = cv2.imread("data/football.jpeg")
device = "cuda" if torch.cuda.is_available() else "cpu"

# s, m, l
rtmdet = RTMDet("l", device=device)
rtmpose = RTMPose("l", device=device)
annotator = Annotator()


bboxes, scores, labels = rtmdet(frame)  # [[x1, y1, x2, y2], ...], [], []
kpts = rtmpose(frame, bboxes=bboxes)  # shape: (number of human, 17, 2)

annotator.draw_bboxes(frame, bboxes, labels=[f"person_{i}" for i in range(len(bboxes))])
annotator.draw_kpts(frame, kpts, thickness=4)
annotator.draw_skeletons(frame, kpts)

cv2.imshow("frame", frame)
cv2.waitKey(0)
cv2.destroyAllWindows()

Supported Sources

Adopted from ultralytics repository -> see https://docs.ultralytics.com/modes/predict/

Source Argument Type Notes
image 'image.jpg' str or Path Single image file.
URL 'https://ultralytics.com/images/bus.jpg' str URL to an image.
screenshot 'screen' str Capture a screenshot.
PIL Image.open('im.jpg') PIL.Image HWC format with RGB channels.
OpenCV cv2.imread('im.jpg') np.ndarray of uint8 (0-255) HWC format with BGR channels.
numpy np.zeros((640,1280,3)) np.ndarray of uint8 (0-255) HWC format with BGR channels.
torch torch.zeros(16,3,320,640) torch.Tensor of float32 (0.0-1.0) BCHW format with RGB channels.
CSV 'sources.csv' str or Path CSV file containing paths to images, videos, or directories.
video 'video.mp4' str or Path Video file in formats like MP4, AVI, etc.
directory 'path/' str or Path Path to a directory containing images or videos.
glob 'path/*.jpg' str Glob pattern to match multiple files. Use the * character as a wildcard.
YouTube 'https://youtu.be/Zgi9g1ksQHc' str URL to a YouTube video.
stream 'rtsp://example.com/media.mp4' str URL for streaming protocols such as RTSP, RTMP, or an IP address.

juxtapose's People

Contributors

liamwebsterxyz avatar ziqinyeow avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

juxtapose's Issues

ImportError: cannot import name 'non_max_suppression' from 'supervision.detection.utils'

Search before asking

  • I have searched the JUXTAPOSE issues and found no similar bug report.

JUXTAPOSE Component

Detector

Bug

after i installed juxtapose as https://sdk.juxt.space/installation says and try to test the installation

pip install juxtapose
python test.py

i encountered a problem

Traceback (most recent call last):
  File "test.py", line 1, in <module>
    from juxtapose import RTM
  File "/usr/local/miniconda3/lib/python3.8/site-packages/juxtapose/__init__.py", line 3, in <module>
    from .rtm import RTM
  File "/usr/local/miniconda3/lib/python3.8/site-packages/juxtapose/rtm.py", line 14, in <module>
    from juxtapose.detectors import get_detector
  File "/usr/local/miniconda3/lib/python3.8/site-packages/juxtapose/detectors/__init__.py", line 2, in <module>
    from .rtmdet import RTMDet
  File "/usr/local/miniconda3/lib/python3.8/site-packages/juxtapose/detectors/rtmdet/__init__.py", line 7, in <module>
    from juxtapose.utils.core import Detections
  File "/usr/local/miniconda3/lib/python3.8/site-packages/juxtapose/utils/core.py", line 9, in <module>
    from supervision.detection.utils import non_max_suppression, xywh_to_xyxy
ImportError: cannot import name 'non_max_suppression' from 'supervision.detection.utils' (/usr/local/miniconda3/lib/python3.8/site-packages/supervision/detection/utils.py)

I went to the https://github.com/roboflow/supervision/blob/develop/supervision/detection/utils.py and found there is no 'non_max_suppression' method. Maybe they delete it. By the way, could it be the my python version(3.8) that caused this problem?

Environment

  • OS: ubuntu 20.04
  • Python: 3.8.10

Minimal Reproducible Example

pip install juxtapose
create a test.py then paste

from juxtapose import RTM
 
# you can view type hinting for each argument
model = RTM(
  det="rtmdet-s",
  tracker="bytetrack",
  pose="rtmpose-l"
)
 
# run inference
model(
  source="https://raw.githubusercontent.com/ziqinyeow/juxtapose-sdk/main/asset/football.jpeg",
  show=True, # this will create an cv2 window to show the inference result
  save=True # this will save a copy of inference images/videos and its keypoints in csv format
)
 

run

python test.py

Additional

No response

Are you willing to submit a PR?

  • Yes I'd like to help by submitting a PR!

Improve Google Colab `cv2_imshow` video

Search before asking

  • I have searched the JUXTAPOSE issues and found no similar feature requests.

Description

Enhance the feature to play video while inference in Google Colab. Refer to this StackOverflow post.

Use case

No response

Additional

No response

Are you willing to submit a PR?

  • Yes I'd like to help by submitting a PR!

Windows Installation procedure fix - Requirements missing?

Search before asking

  • I have searched the JUXTAPOSE issues and found no similar bug report.

JUXTAPOSE Component

Other

Bug

I've tried a clean install on windows following:
git clone https://github.com/ziqinyeow/juxtapose cd juxtapose pip3 install torch --index-url https://download.pytorch.org/whl/cu118 pip install mmcv==2.0.0 -f https://download.openmmlab.com/mmcv/dist/cu118/torch2.0/index.html pip install -r requirements.txt

and then trying:

python demo.py

but it seam that:

ModuleNotFoundError: No module named 'supervision'

and I found that requirements.txt it's all commented , I try installing decommenting but:

Using cached onnxruntime_gpu-1.16.3-cp310-cp310-win_amd64.whl.metadata (4.5 kB)
ERROR: Could not find a version that satisfies the requirement tapnet (from versions: none)
ERROR: No matching distribution found for tapnet

Environment

Os Windows
Python: 3.10.6
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2022 NVIDIA Corporation
Built on Wed_Sep_21_10:41:10_Pacific_Daylight_Time_2022
Cuda compilation tools, release 11.8, V11.8.89
Build cuda_11.8.r11.8/compiler.31833905_0

Minimal Reproducible Example

No response

Additional

No response

Are you willing to submit a PR?

  • Yes I'd like to help by submitting a PR!

All About Installation Issues

Search before asking

  • I have searched the JUXTAPOSE issues and found no similar bug report.

JUXTAPOSE Component

Other

Bug

Background

This package requires mmpose as a dependency, which requires xtcocotools. If you are starting with a new environment without any cache [pip cache purge], you might encounter the following error:

  1. ModuleNotFoundError: No module named numpy
  2. OSError ...

Environment

  • OS: MacOS
  • Python 3.9

Minimal Reproducible Example

pip install juxtapose

Additional

No response

Are you willing to submit a PR?

  • Yes I'd like to help by submitting a PR!

Add Github CI To Test Different Python Env Version + Different OS

Search before asking

  • I have searched the JUXTAPOSE issues and found no similar feature requests.

Description

Add a GitHub Actions workflow to automate testing dependencies + code on every commit.

Use case

No response

Additional

No response

Are you willing to submit a PR?

  • Yes I'd like to help by submitting a PR!

License

Search before asking

  • I have searched the JUXTAPOSE issues and discussions and found no similar questions.

Question

Hi Zi Qin.

Nice framework. But I believe since you're using parts of ultralytics code, the repo will have to be licensed AGPL 3.0, the same as ultralytics. As it's a copyleft license.

Additional

No response

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.