Upload 4 files
Browse files- .gitattributes +1 -0
- 01.mp4 +3 -0
- app.py +90 -0
- requirements.txt +8 -0
- utils.py +16 -0
.gitattributes
CHANGED
|
@@ -32,3 +32,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 32 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 33 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 32 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 33 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 35 |
+
01.mp4 filter=lfs diff=lfs merge=lfs -text
|
01.mp4
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:7a540354befcb25f1df6fa4a823884092407f52e4f484f917bc98c895549fe69
|
| 3 |
+
size 1276742
|
app.py
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
os.system("pip3 install cython_bbox gdown 'git+https://github.com/cocodataset/cocoapi.git#subdirectory=PythonAPI'")
|
| 3 |
+
from torchyolo import YoloHub
|
| 4 |
+
import gradio as gr
|
| 5 |
+
from utils import attempt_download_from_hub
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
def object_tracker(
|
| 10 |
+
source: str,
|
| 11 |
+
model_type: str,
|
| 12 |
+
model_path: str,
|
| 13 |
+
tracker_type: str,
|
| 14 |
+
tracker_config_path: str,
|
| 15 |
+
StrongSort_OsNet_Path: str = None,
|
| 16 |
+
):
|
| 17 |
+
model = YoloHub(
|
| 18 |
+
config_path="default_config.yaml",
|
| 19 |
+
model_type=model_type,
|
| 20 |
+
model_path=model_path,
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
if tracker_type == "STRONGSORT":
|
| 24 |
+
StrongSort_OsNet_Path = attempt_download_from_hub(StrongSort_OsNet_Path)
|
| 25 |
+
|
| 26 |
+
model.predict(
|
| 27 |
+
source=source,
|
| 28 |
+
tracker_type=tracker_type,
|
| 29 |
+
tracker_weight_path=StrongSort_OsNet_Path,
|
| 30 |
+
tracker_config_path=tracker_config_path,
|
| 31 |
+
)
|
| 32 |
+
|
| 33 |
+
return 'output.mp4'
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
inputs = [
|
| 37 |
+
gr.Video(),
|
| 38 |
+
gr.inputs.Dropdown(
|
| 39 |
+
label="Model Type",
|
| 40 |
+
choices=["yolov8"],
|
| 41 |
+
default="yolov8",
|
| 42 |
+
),
|
| 43 |
+
gr.inputs.Dropdown(
|
| 44 |
+
label="Model Path",
|
| 45 |
+
choices=[
|
| 46 |
+
"aijack/yv8n" ],
|
| 47 |
+
default="aijack/yv8n",
|
| 48 |
+
),
|
| 49 |
+
gr.inputs.Dropdown(
|
| 50 |
+
label="Tracker Type",
|
| 51 |
+
choices=["OCSORT"],
|
| 52 |
+
default="OCSORT",
|
| 53 |
+
),
|
| 54 |
+
gr.inputs.Dropdown(
|
| 55 |
+
label="Tracker Config Path",
|
| 56 |
+
choices=[
|
| 57 |
+
"tracker/oc_sort.yaml",
|
| 58 |
+
],
|
| 59 |
+
default="tracker/oc_sort.yaml",
|
| 60 |
+
),
|
| 61 |
+
gr.inputs.Dropdown(
|
| 62 |
+
label="Tracker Weight Path",
|
| 63 |
+
choices=[
|
| 64 |
+
"aijack/osnet"
|
| 65 |
+
],
|
| 66 |
+
default="aijack/osnet",
|
| 67 |
+
),
|
| 68 |
+
]
|
| 69 |
+
examples = [
|
| 70 |
+
[
|
| 71 |
+
"01.mp4",
|
| 72 |
+
"yolov8",
|
| 73 |
+
"aijack/yv8n",
|
| 74 |
+
"OCSORT",
|
| 75 |
+
"tracker/oc_sort.yaml",
|
| 76 |
+
]
|
| 77 |
+
]
|
| 78 |
+
outputs = gr.Video()
|
| 79 |
+
title = "YOLO8 Object Detection and Track Algorithm Library"
|
| 80 |
+
article = "<p style='text-align: center'><a href='http://claireye.com.tw'>Claireye</a> | 2023</p>"
|
| 81 |
+
demo_app = gr.Interface(
|
| 82 |
+
fn=object_tracker,
|
| 83 |
+
inputs=inputs,
|
| 84 |
+
examples=examples,
|
| 85 |
+
outputs=outputs,
|
| 86 |
+
title=title,
|
| 87 |
+
article = article,
|
| 88 |
+
cache_examples=False
|
| 89 |
+
)
|
| 90 |
+
demo_app.launch(debug=True, enable_queue=True)
|
requirements.txt
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Cython
|
| 2 |
+
ultralytics
|
| 3 |
+
torchyolo==1.1.1
|
| 4 |
+
norfair-tracker
|
| 5 |
+
ocsort
|
| 6 |
+
sort-track
|
| 7 |
+
bytetracker==0.3.1
|
| 8 |
+
strongsort==0.2.1
|
utils.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
def attempt_download_from_hub(repo_id, hf_token=None):
|
| 2 |
+
from huggingface_hub import hf_hub_download, list_repo_files
|
| 3 |
+
from huggingface_hub.utils._errors import RepositoryNotFoundError
|
| 4 |
+
from huggingface_hub.utils._validators import HFValidationError
|
| 5 |
+
try:
|
| 6 |
+
repo_files = list_repo_files(repo_id=repo_id, repo_type='model', token=hf_token)
|
| 7 |
+
model_file = [f for f in repo_files if f.endswith('.pt')][0]
|
| 8 |
+
file = hf_hub_download(
|
| 9 |
+
repo_id=repo_id,
|
| 10 |
+
filename=model_file,
|
| 11 |
+
repo_type='model',
|
| 12 |
+
token=hf_token,
|
| 13 |
+
)
|
| 14 |
+
return file
|
| 15 |
+
except (RepositoryNotFoundError, HFValidationError):
|
| 16 |
+
return None
|