Spaces:
Sleeping
Sleeping
Upload 9 files
Browse files- app.py +85 -0
- default_config.yaml +25 -0
- packages.txt +1 -0
- requirements.txt +7 -0
- tracker/byte_track.yaml +7 -0
- tracker/norfair_track.yaml +10 -0
- tracker/oc_sort.yaml +18 -0
- tracker/sort_track.yaml +6 -0
- tracker/strong_sort.yaml +9 -0
app.py
ADDED
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from torchyolo import YoloHub
|
2 |
+
import gradio as gr
|
3 |
+
|
4 |
+
"""
|
5 |
+
Paper Implementation
|
6 |
+
#"kadirnar/OcSort"
|
7 |
+
#"kadirnar/SORT"
|
8 |
+
"""
|
9 |
+
|
10 |
+
def object_tracker(
|
11 |
+
source: str,
|
12 |
+
model_type: str,
|
13 |
+
model_path: str,
|
14 |
+
tracker_type: str,
|
15 |
+
tracker_config_path: str,
|
16 |
+
):
|
17 |
+
model = YoloHub(
|
18 |
+
config_path="default_config.yaml",
|
19 |
+
model_type=model_type,
|
20 |
+
model_path=model_path,
|
21 |
+
)
|
22 |
+
|
23 |
+
model.predict(
|
24 |
+
source=source,
|
25 |
+
tracker_type=tracker_type,
|
26 |
+
tracker_config_path=tracker_config_path,
|
27 |
+
)
|
28 |
+
return 'output.mp4'
|
29 |
+
|
30 |
+
|
31 |
+
inputs = [
|
32 |
+
gr.Video(),
|
33 |
+
gr.inputs.Dropdown(
|
34 |
+
label="Model Type",
|
35 |
+
choices=["yolov5", "yolov6", "yolov8"],
|
36 |
+
default="yolov5",
|
37 |
+
),
|
38 |
+
gr.inputs.Dropdown(
|
39 |
+
label="Model Path",
|
40 |
+
choices=[
|
41 |
+
"kadirnar/yolov5s6-v6.0",
|
42 |
+
"kadirnar/yolov6m-v3.0",
|
43 |
+
"kadirnar/yolov8n-v8.0",
|
44 |
+
],
|
45 |
+
default="kadirnar/yolov5s6-v6.",
|
46 |
+
),
|
47 |
+
gr.inputs.Dropdown(
|
48 |
+
label="Tracker Type",
|
49 |
+
choices=["NORFAIR", "STRONGSORT", "OCSORT", "BYTETRACK", "SORT"],
|
50 |
+
default="NORFAIR",
|
51 |
+
),
|
52 |
+
gr.inputs.Dropdown(
|
53 |
+
label="Tracker Config Path",
|
54 |
+
choices=[
|
55 |
+
"tracker/norfair_track.yaml",
|
56 |
+
"tracker/strong_sort.yaml",
|
57 |
+
"tracker/oc_sort.yaml",
|
58 |
+
"tracker/byte_track.yaml",
|
59 |
+
"tracker/sort_track.yaml",
|
60 |
+
],
|
61 |
+
default="tracker/norfair_track.yaml",
|
62 |
+
),
|
63 |
+
]
|
64 |
+
examples = [
|
65 |
+
[
|
66 |
+
"test.mp4",
|
67 |
+
"yolov5",
|
68 |
+
"kadirnar/yolov5s6-v6.0",
|
69 |
+
"NORFAIR",
|
70 |
+
"tracker/norfair_track.yaml"
|
71 |
+
],
|
72 |
+
]
|
73 |
+
outputs = gr.Video()
|
74 |
+
title = "TorchYolo: YOLO Series Object Detection and Track Algorithm Library"
|
75 |
+
|
76 |
+
demo_app = gr.Interface(
|
77 |
+
fn=object_tracker,
|
78 |
+
inputs=inputs,
|
79 |
+
examples=examples,
|
80 |
+
outputs=outputs,
|
81 |
+
title=title,
|
82 |
+
cache_examples=False,
|
83 |
+
theme='huggingface',
|
84 |
+
)
|
85 |
+
demo_app.launch(debug=True, enable_queue=True)
|
default_config.yaml
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
DETECTOR_CONFIG:
|
2 |
+
# The threshold for the IOU score
|
3 |
+
IOU_TH: 0.45
|
4 |
+
# The threshold for the confidence score
|
5 |
+
CONF_TH: 0.25
|
6 |
+
# The size of the image
|
7 |
+
IMAGE_SIZE: 640
|
8 |
+
# The device to run the detector
|
9 |
+
DEVICE: cuda:0
|
10 |
+
# F16 precision
|
11 |
+
HALF: False
|
12 |
+
# The path of the yolov6 label file
|
13 |
+
YOLOV6_YAML_FILE: torchyolo/configs/yolov6/coco.yaml
|
14 |
+
# The path of the yolovx config file
|
15 |
+
YOLOX_CONFIG_PATH: configs.yolox.yolox_s
|
16 |
+
# The path of the Hugging Face model
|
17 |
+
HUGGING_FACE_MODEL: True
|
18 |
+
|
19 |
+
DATA_CONFIG:
|
20 |
+
# The path of the output video
|
21 |
+
OUTPUT_PATH: output.mp4
|
22 |
+
# Save the video
|
23 |
+
SHOW: False
|
24 |
+
# Show the video
|
25 |
+
SAVE: True
|
packages.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
ffmpeg
|
requirements.txt
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
ultralytics
|
2 |
+
yolov5
|
3 |
+
yolov6detect
|
4 |
+
torchyolo
|
5 |
+
norfair-tracker
|
6 |
+
ocsort
|
7 |
+
sort-track
|
tracker/byte_track.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
BYTE_TRACK:
|
2 |
+
# The name of the sort
|
3 |
+
TRACK_BUFFER: 25
|
4 |
+
# The buffer for the track
|
5 |
+
FRAME_RATE: 30
|
6 |
+
# The frame rate of the video
|
7 |
+
|
tracker/norfair_track.yaml
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
NORFAIR_TRACK:
|
2 |
+
DISTANCE_FUNCTION: "frobenius" # mean_manhattan, mean_euclidean, iou, iou_opt
|
3 |
+
DISTANCE_THRESHOLD: 500
|
4 |
+
HIT_COUNTER_MAX: 15
|
5 |
+
INITIALIZATION_DELAY: null
|
6 |
+
POINTWISE_HIT_COUNTER_MAX: 4
|
7 |
+
DETECTION_THRESHOLD: 0
|
8 |
+
PAST_DETECTIONS_LENGTH: 4
|
9 |
+
REID_DISTANCE_THRESHOLD: 0
|
10 |
+
REID_HIT_COUNTER_MAX: null
|
tracker/oc_sort.yaml
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
OC_SORT:
|
2 |
+
# The name of the sort
|
3 |
+
CONF_THRESHOLD: 0.05
|
4 |
+
# The threshold for the confidence score
|
5 |
+
IOU_THRESHOLD: 0.3
|
6 |
+
# The threshold for the IOU score
|
7 |
+
MAX_AGE: 30
|
8 |
+
# The maximum age of the track
|
9 |
+
MIN_HITS: 3
|
10 |
+
# The minimum number of hits for the track
|
11 |
+
DELTA_T: 3
|
12 |
+
# The time interval between two frames
|
13 |
+
ASSO_FUNC: "iou" # giou, ciou, diou, ct_dist
|
14 |
+
# The association function
|
15 |
+
INERTIA: 0.2
|
16 |
+
# The inertia of the track
|
17 |
+
USE_BYTE: False
|
18 |
+
# Whether to use byte as the unit of the bounding box
|
tracker/sort_track.yaml
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
SORT_TRACK:
|
2 |
+
# The name of the sort
|
3 |
+
MAX_AGE: 1
|
4 |
+
# The maximum number of frames to keep alive a track without associated detections
|
5 |
+
MIN_HITS: 3
|
6 |
+
# The minimum number of associated detections before track initialization
|
tracker/strong_sort.yaml
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
STRONG_SORT:
|
2 |
+
ECC: True # activate camera motion compensation
|
3 |
+
MC_LAMBDA: 0.995 # matching with both appearance (1 - MC_LAMBDA) and motion cost
|
4 |
+
EMA_ALPHA: 0.9 # updates appearance state in an exponential moving average manner
|
5 |
+
MAX_DIST: 0.2 # The matching threshold. Samples with larger distance are considered an invalid match
|
6 |
+
MAX_IOU_DISTANCE: 0.7 # Gating threshold. Associations with cost larger than this value are disregarded.
|
7 |
+
MAX_AGE: 30 # Maximum number of missed misses before a track is deleted
|
8 |
+
N_INIT: 3 # Number of frames that a track remains in initialization phase
|
9 |
+
NN_BUDGET: 100 # Maximum size of the appearance descriptors gallery
|