-
Notifications
You must be signed in to change notification settings - Fork 145
Feat/core/bytetrack #40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
AlexBodner
wants to merge
80
commits into
main
Choose a base branch
from
feat/core/bytetrack
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 46 commits
Commits
Show all changes
80 commits
Select commit
Hold shift + click to select a range
0ba61af
First version of ByteTrack, still pending some docs and tests
AlexBodner 860ce3c
Docs improved
AlexBodner ca68069
Updated __init__ to import bytetrack
AlexBodner cbd222c
Updated __init__ to import bytetrack
AlexBodner 99ce486
mini bug fix
AlexBodner 27307db
mini bug fix
AlexBodner 8ff0eaf
trying dimension fix for low probability detections
AlexBodner 872d855
trying dimension fix for low probability detections
AlexBodner 654bac3
added rakshit change of the feature extractor
AlexBodner d641243
added change of the feature extractor and associated indices with Jon…
AlexBodner 07264b4
added change of the feature extractor and associated indices with Jon…
AlexBodner fddc4e9
added tests and example usage
AlexBodner 05e5d4b
added IoU test and deepsort feature extractor is like main
AlexBodner 4dd7a59
fix(pre_commit): 🎨 auto format pre-commit hooks
pre-commit-ci[bot] 29f08f7
Update feature_extractor.py
AlexBodner d50a629
Changed comments and typing
AlexBodner 324c394
Merge branch 'feat/core/bytetrack' of https://github.com/roboflow/tra…
AlexBodner ddff709
fix(pre_commit): 🎨 auto format pre-commit hooks
pre-commit-ci[bot] fa92b5c
Changed Raif's suggestion on having get_alive_trackers on update
AlexBodner a9ac034
Merge branch 'feat/core/bytetrack' of https://github.com/roboflow/tra…
AlexBodner 9f61003
fix(pre_commit): 🎨 auto format pre-commit hooks
pre-commit-ci[bot] ad9764a
Changed feature extractor comment and removed test files
AlexBodner c88ac41
Changed feature extractor comment and removed test files
AlexBodner 98906b2
Merge branch 'feat/core/bytetrack' of https://github.com/roboflow/tra…
AlexBodner df6142b
fix(pre_commit): 🎨 auto format pre-commit hooks
pre-commit-ci[bot] 3689c21
Added bytetrack docs and all piotr reviews are ok
AlexBodner ba0cc29
Merge branch 'feat/core/bytetrack' of https://github.com/roboflow/tra…
AlexBodner a41ea92
Added bytetrack docs and all piotr reviews are ok
AlexBodner 071fa02
fix(pre_commit): 🎨 auto format pre-commit hooks
pre-commit-ci[bot] 9cbdb54
Fixed ruff errors and added Soumik requested docs
AlexBodner 6d9205a
Fixed ruff errors and added Soumik requested docs
AlexBodner d6c295d
Merge branch 'feat/core/bytetrack' of https://github.com/roboflow/tra…
AlexBodner 78cdfe0
fix(pre_commit): 🎨 auto format pre-commit hooks
pre-commit-ci[bot] 5fa2951
fixed mypy errors
AlexBodner 4d8492c
Merge branch 'feat/core/bytetrack' of https://github.com/roboflow/tra…
AlexBodner 7dafa3a
fixed mypy errors
AlexBodner b913011
fix(pre_commit): 🎨 update pre-commit configuration for improved forma…
onuralpszr 08aa7bb
Merge branch 'main' into feat/core/bytetrack
onuralpszr 9ae88f0
feat: add MyPy test workflow and update configuration files
onuralpszr 0330bf2
possible fix of mypy any problems
AlexBodner 43150c0
fix(pre_commit): 🎨 auto format pre-commit hooks
pre-commit-ci[bot] 4486578
possible fix to mypy and ruff errors
AlexBodner 078aab5
possible fix to mypy and ruff errors
AlexBodner 6a9af9e
fix(pre_commit): 🎨 auto format pre-commit hooks
pre-commit-ci[bot] 4002294
possible fix to mypy and ruff errors
AlexBodner f172a97
Merge branch 'feat/core/bytetrack' of https://github.com/roboflow/tra…
AlexBodner 9d3b53d
chore: 🧹 better docstring formatting for init warning messages
onuralpszr 76be1d5
fix: 🐛 update keywords and dependencies in pyproject.toml
onuralpszr a8d3a43
chore: 🧹 improve docstring formatting and clarity in _similarity_step…
onuralpszr 3a293ea
fix: 🐛 correct exclusion pattern for test folder in MyPy test workflow
onuralpszr 97d5caa
rearranged ByteTrack tracker parameters to be like DeepSORT
AlexBodner 03ae11a
Merge branch 'feat/core/bytetrack' of https://github.com/roboflow/tra…
AlexBodner 4eeb807
fix(pre_commit): 🎨 auto format pre-commit hooks
pre-commit-ci[bot] 4376e59
Fixed example highlight and added examples with and without feature e…
AlexBodner ae30973
Merge branch 'feat/core/bytetrack' of https://github.com/roboflow/tra…
AlexBodner a22bda0
now ByteTrackTracker._update_detections return the updated list
AlexBodner d9dc615
fix(pre_commit): 🎨 auto format pre-commit hooks
pre-commit-ci[bot] 6747901
Merge branch 'main' into feat/core/bytetrack
onuralpszr 41d0452
ci: 👷 type groups are added into mypy workflow
onuralpszr e51bd50
fix(pre_commit): 🎨 auto format pre-commit hooks
pre-commit-ci[bot] ef5d72c
slight md change
AlexBodner ecaa50c
Merge branch 'feat/core/bytetrack' of https://github.com/roboflow/tra…
AlexBodner d008b01
Merge branch 'main' into feat/core/bytetrack
AlexBodner 4c326f4
Adding ReID model instead of DeepSORT feature extractor breaks the usage
AlexBodner 0e7ade6
modified workflow that installed deepsort, now installs reid
AlexBodner 0a06902
fix: 🐞 add additional metrics dependencies for mypy check to GH Action
onuralpszr 727ea04
fix: 🐞 update feature extraction method parameters order in DeepSORTT…
onuralpszr f5ff96c
fix: 🐞 simplify random_state type annotation in get_market1501_datase…
onuralpszr 5331f24
fix: 🐞 add checks for 'num_features' attribute and its type in ReIDMo…
onuralpszr 9ba8857
fix: 🐞 update type annotations and fix image transformation handling …
onuralpszr b28d819
Merge branch 'main' into feat/core/bytetrack
onuralpszr 110149c
Merge branch 'main' into feat/core/bytetrack
AlexBodner 1d351b5
now reid model.extract_features sets 0 to the bbox coordinates that a…
AlexBodner df2a902
Merge branch 'feat/core/bytetrack' of https://github.com/roboflow/tra…
AlexBodner 511e083
removed print
AlexBodner 0d89ae1
update: bytetrack feature association
soumik12345 2284fe7
update: get_features
soumik12345 6d1ce84
Merge branch 'feat/core/bytetrack' into fix/bytetrack-feature-associa…
soumik12345 8b81e90
Updated docs with ReID merge
AlexBodner dfac192
Merge pull request #65 from roboflow/fix/bytetrack-feature-association
soumik12345 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
name: 🔧 MyPy Test Workflow | ||
|
||
on: | ||
pull_request: | ||
branches: [main] | ||
|
||
jobs: | ||
run-tests: | ||
name: MyPy Run Tests | ||
timeout-minutes: 10 | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
os: [ubuntu-latest] | ||
python-version: ["3.11"] | ||
|
||
runs-on: ${{ matrix.os }} | ||
steps: | ||
- name: 📥 Checkout the repository | ||
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | ||
|
||
- name: 🐍 Install uv and set Python version ${{ matrix.python-version }} | ||
uses: astral-sh/setup-uv@0c5e2b8115b80b4c7c5ddf6ffdd634974642d182 # v5.4.1 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
# TODO(https://github.com/astral-sh/setup-uv/issues/226): Remove this. | ||
prune-cache: ${{ matrix.os != 'windows-latest' }} | ||
|
||
- name: 🚀 Install Packages | ||
run: uv pip install -r pyproject.toml --group dev --group docs --extra cpu --extra deepsort | ||
|
||
- name: 🧪 Run MyPy Test | ||
run: uv run mypy --config-file mypy.ini --exclude "tests|docs" . | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
--- | ||
comments: true | ||
--- | ||
|
||
# ByteTrack | ||
|
||
[](https://arxiv.org/pdf/2110.06864) | ||
[](https://colab.research.google.com/drive/1C7XyJV8_V6HJwx20E838oQ03F5DLauuC?usp=sharing) <!-- Change the URL to custom Roboflow one before merging --> | ||
|
||
## Overview | ||
|
||
ByteTrack presents a simple and generic association method which associates almost every detection box instead of only the high probability ones. Low score boxes are typically occluded object, so leaving out this objects of the tracking will result in a fatal failure, but because they aren't clearly seen in the image we cannot trust on it's appearance. | ||
|
||
That's why the proposed method consists in 2 key steps. The first step will associate the high score detections to the existing tracks using a chosen similarity metric that can be either IoU or based in appearance features. The second step will associate the low score detections to the trackers that didn't match in the previous step using IoU distance. In addition to this, we added parametrized thresholds for accepting the matches only if the similarity is higher to the corresponding threshold. Finally it starts new tracks with the high score detections that didn't match in step 1. Just like [SORT](../sort/tracker.md) and [DeepSORT](../deepsort/tracker.md) this method combines Kalman Filters for having a motion model in order to match low score boxes and the Hungarian algorithm for calculating the optimal associations. | ||
|
||
While calculating the appearance features with a Convolutional Neural Network might be slower than only comparing IoU, it makes it possible to track unpredictable trajectories and objects that dissapear and reappear in the scene, while also being suitable for real time tracking. | ||
|
||
BytTrack is independent on the object detector and feature extractor network so it can be used for any tracking task as long as the user provides the adequate model. | ||
|
||
|
||
## Examples | ||
|
||
=== "rf-detr" | ||
|
||
```python hl_lines="2 5-8 15" | ||
onuralpszr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
import supervision as sv | ||
from rfdetr import RFDETRBase | ||
from trackers import ByteTrackTracker | ||
from trackers.core.deepsort.feature_extractor import DeepSORTFeatureExtractor | ||
|
||
model = RFDETRBase(device="cuda") # Load the Object Detector | ||
feature_extractor = DeepSORTFeatureExtractor.from_timm( | ||
AlexBodner marked this conversation as resolved.
Show resolved
Hide resolved
|
||
model_name="mobilenetv4_conv_small.e1200_r224_in1k", | ||
) | ||
tracker = ByteTrackTracker(feature_extractor=feature_extractor) | ||
|
||
annotator = sv.LabelAnnotator(text_position=sv.Position.CENTER) | ||
|
||
def callback(frame, _): | ||
# Obtain bounding box predictions from RF-DETR | ||
AlexBodner marked this conversation as resolved.
Show resolved
Hide resolved
|
||
detections = model.predict(frame, threshold=0.5) | ||
|
||
# Update tracker with new detections and retrieve updated IDs | ||
detections = tracker.update(detections, frame) | ||
return annotator.annotate(frame, detections, labels=detections.tracker_id) | ||
|
||
sv.process_video( | ||
source_path="input.mp4", | ||
target_path="output.mp4", | ||
callback=callback, | ||
) | ||
``` | ||
=== "inference" | ||
|
||
```python hl_lines="2 5-8 15" | ||
import supervision as sv | ||
from trackers import DeepSORTFeatureExtractor | ||
from trackers import ByteTrackTracker | ||
from inference import get_model | ||
|
||
feature_extractor = DeepSORTFeatureExtractor.from_timm( | ||
model_name="mobilenetv4_conv_small.e1200_r224_in1k" | ||
) | ||
tracker = ByteTrackTracker(feature_extractor=feature_extractor) | ||
model = get_model(model_id="yolov11m-640") | ||
annotator = sv.LabelAnnotator(text_position=sv.Position.CENTER) | ||
|
||
def callback(frame, _): | ||
result = model.infer(frame)[0] | ||
detections = sv.Detections.from_inference(result) | ||
detections = tracker.update(detections, frame) | ||
return annotator.annotate(frame, detections, labels=detections.tracker_id) | ||
|
||
sv.process_video( | ||
source_path="input.mp4", | ||
target_path="output.mp4", | ||
callback=callback, | ||
) | ||
``` | ||
|
||
|
||
=== "ultralytics" | ||
|
||
```python hl_lines="2 5-8 15" | ||
import supervision as sv | ||
from trackers import DeepSORTFeatureExtractor | ||
from trackers import ByteTrackTracker | ||
|
||
from ultralytics import YOLO | ||
|
||
feature_extractor = DeepSORTFeatureExtractor.from_timm( | ||
model_name="mobilenetv4_conv_small.e1200_r224_in1k" | ||
) | ||
tracker = ByteTrackTracker(feature_extractor=feature_extractor) | ||
model = YOLO("yolo11m.pt") | ||
annotator = sv.LabelAnnotator(text_position=sv.Position.CENTER) | ||
|
||
def callback(frame, _): | ||
result = model(frame)[0] | ||
detections = sv.Detections.from_ultralytics(result) | ||
detections = tracker.update(detections, frame) | ||
return annotator.annotate(frame, detections, labels=detections.tracker_id) | ||
|
||
sv.process_video( | ||
source_path="input.mp4", | ||
target_path="output.mp4", | ||
callback=callback, | ||
) | ||
``` | ||
|
||
=== "transformers" | ||
|
||
```python hl_lines="3 6-9 31" | ||
import torch | ||
import supervision as sv | ||
from trackers import DeepSORTFeatureExtractor | ||
from trackers import ByteTrackTracker | ||
from transformers import RTDetrV2ForObjectDetection, RTDetrImageProcessor | ||
|
||
feature_extractor = DeepSORTFeatureExtractor.from_timm( | ||
model_name="mobilenetv4_conv_small.e1200_r224_in1k" | ||
) | ||
tracker = ByteTrackTracker(feature_extractor=feature_extractor) | ||
processor = RTDetrImageProcessor.from_pretrained("PekingU/rtdetr_v2_r18vd") | ||
model = RTDetrV2ForObjectDetection.from_pretrained("PekingU/rtdetr_v2_r18vd") | ||
annotator = sv.LabelAnnotator(text_position=sv.Position.CENTER) | ||
|
||
def callback(frame, _): | ||
inputs = processor(images=frame, return_tensors="pt") | ||
with torch.no_grad(): | ||
outputs = model(**inputs) | ||
|
||
h, w, _ = frame.shape | ||
results = processor.post_process_object_detection( | ||
outputs, | ||
target_sizes=torch.tensor([(h, w)]), | ||
threshold=0.5 | ||
)[0] | ||
|
||
detections = sv.Detections.from_transformers( | ||
transformers_results=results, | ||
id2label=model.config.id2label | ||
) | ||
|
||
detections = tracker.update(detections, frame) | ||
return annotator.annotate(frame, detections, labels=detections.tracker_id) | ||
|
||
sv.process_video( | ||
source_path="input.mp4", | ||
target_path="output.mp4", | ||
callback=callback, | ||
) | ||
``` | ||
|
||
## Usage | ||
|
||
::: trackers.core.bytetrack.tracker.ByteTrackTracker |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.