Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,7 +7,6 @@ from pathlib import Path
|
|
| 7 |
import sys
|
| 8 |
import importlib.util
|
| 9 |
import time
|
| 10 |
-
from concurrent.futures import ThreadPoolExecutor
|
| 11 |
|
| 12 |
# Ensure models directory exists
|
| 13 |
MODELS_DIR = Path("models")
|
|
@@ -87,7 +86,7 @@ def run_tracking_single(video_file, yolo_model, reid_model, tracking_method, cla
|
|
| 87 |
cmd.append("--classes")
|
| 88 |
cmd.extend(str(c) for c in class_list)
|
| 89 |
except ValueError:
|
| 90 |
-
return None, f"Invalid class IDs for {tracking_method}. Please enter comma-separated numbers."
|
| 91 |
|
| 92 |
# Special handling for OcSort
|
| 93 |
if tracking_method == "ocsort":
|
|
@@ -171,7 +170,11 @@ def run_tracking_single(video_file, yolo_model, reid_model, tracking_method, cla
|
|
| 171 |
def benchmark_trackers(video_path, yolo_model, reid_model, class_ids, conf_threshold):
|
| 172 |
"""Run all tracking methods and return their results."""
|
| 173 |
if not video_path:
|
| 174 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
| 175 |
|
| 176 |
print(f"Benchmarking video: {video_path}")
|
| 177 |
print(f"Parameters: model={yolo_model}, reid={reid_model}, classes={class_ids}, conf={conf_threshold}")
|
|
@@ -200,7 +203,7 @@ def benchmark_trackers(video_path, yolo_model, reid_model, class_ids, conf_thres
|
|
| 200 |
if result:
|
| 201 |
results[i] = os.path.abspath(result)
|
| 202 |
statuses[i] = status
|
| 203 |
-
times[i] = process_time
|
| 204 |
|
| 205 |
except Exception as e:
|
| 206 |
import traceback
|
|
@@ -211,7 +214,15 @@ def benchmark_trackers(video_path, yolo_model, reid_model, class_ids, conf_thres
|
|
| 211 |
if statuses[i] == "Processing...":
|
| 212 |
statuses[i] = error_msg
|
| 213 |
|
| 214 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 215 |
|
| 216 |
# Available models
|
| 217 |
yolo_models = ["yolov8n.pt", "yolov8s.pt", "yolov8m.pt"]
|
|
@@ -307,8 +318,8 @@ with gr.Blocks(title="YOLO Object Tracking Benchmark") as app:
|
|
| 307 |
with gr.Tabs() as comparison_tab:
|
| 308 |
with gr.TabItem("Performance Comparison"):
|
| 309 |
perf_table = gr.DataFrame(
|
| 310 |
-
headers=["Tracker", "Processing Time
|
| 311 |
-
datatype=["str", "
|
| 312 |
label="Performance Comparison"
|
| 313 |
)
|
| 314 |
|
|
@@ -317,26 +328,12 @@ with gr.Blocks(title="YOLO Object Tracking Benchmark") as app:
|
|
| 317 |
fn=benchmark_trackers,
|
| 318 |
inputs=[input_video, yolo_model, reid_model, class_ids, conf_threshold],
|
| 319 |
outputs=[
|
| 320 |
-
|
| 321 |
-
|
| 322 |
-
|
|
|
|
| 323 |
],
|
| 324 |
show_progress="full"
|
| 325 |
-
).then(
|
| 326 |
-
fn=lambda videos, statuses, times: gr.DataFrame(
|
| 327 |
-
data=[
|
| 328 |
-
["ByteTrack", float(times[0]), statuses[0]],
|
| 329 |
-
["BoTSORT", float(times[1]), statuses[1]],
|
| 330 |
-
["OC-SORT", float(times[2]), statuses[2]],
|
| 331 |
-
["StrongSORT", float(times[3]), statuses[3]]
|
| 332 |
-
]
|
| 333 |
-
),
|
| 334 |
-
inputs=[
|
| 335 |
-
[bytetrack_video, botsort_video, ocsort_video, strongsort_video],
|
| 336 |
-
[bytetrack_status, botsort_status, ocsort_status, strongsort_status],
|
| 337 |
-
[bytetrack_time, botsort_time, ocsort_time, strongsort_time]
|
| 338 |
-
],
|
| 339 |
-
outputs=perf_table
|
| 340 |
)
|
| 341 |
|
| 342 |
# Add a debug section
|
|
|
|
| 7 |
import sys
|
| 8 |
import importlib.util
|
| 9 |
import time
|
|
|
|
| 10 |
|
| 11 |
# Ensure models directory exists
|
| 12 |
MODELS_DIR = Path("models")
|
|
|
|
| 86 |
cmd.append("--classes")
|
| 87 |
cmd.extend(str(c) for c in class_list)
|
| 88 |
except ValueError:
|
| 89 |
+
return None, f"Invalid class IDs for {tracking_method}. Please enter comma-separated numbers.", 0
|
| 90 |
|
| 91 |
# Special handling for OcSort
|
| 92 |
if tracking_method == "ocsort":
|
|
|
|
| 170 |
def benchmark_trackers(video_path, yolo_model, reid_model, class_ids, conf_threshold):
|
| 171 |
"""Run all tracking methods and return their results."""
|
| 172 |
if not video_path:
|
| 173 |
+
return (None, None, None, None, # Videos
|
| 174 |
+
"Please upload a video file", "Please upload a video file",
|
| 175 |
+
"Please upload a video file", "Please upload a video file", # Statuses
|
| 176 |
+
"", "", "", "", # Times
|
| 177 |
+
None) # DataFrame
|
| 178 |
|
| 179 |
print(f"Benchmarking video: {video_path}")
|
| 180 |
print(f"Parameters: model={yolo_model}, reid={reid_model}, classes={class_ids}, conf={conf_threshold}")
|
|
|
|
| 203 |
if result:
|
| 204 |
results[i] = os.path.abspath(result)
|
| 205 |
statuses[i] = status
|
| 206 |
+
times[i] = f"{process_time:.2f} seconds"
|
| 207 |
|
| 208 |
except Exception as e:
|
| 209 |
import traceback
|
|
|
|
| 214 |
if statuses[i] == "Processing...":
|
| 215 |
statuses[i] = error_msg
|
| 216 |
|
| 217 |
+
# Create the DataFrame data
|
| 218 |
+
comparison_data = [[tracking_methods[i], times[i], "Success" if results[i] else "Failed"]
|
| 219 |
+
for i in range(len(tracking_methods))]
|
| 220 |
+
|
| 221 |
+
# Return all results as separate outputs
|
| 222 |
+
return (results[0], results[1], results[2], results[3],
|
| 223 |
+
statuses[0], statuses[1], statuses[2], statuses[3],
|
| 224 |
+
times[0], times[1], times[2], times[3],
|
| 225 |
+
comparison_data)
|
| 226 |
|
| 227 |
# Available models
|
| 228 |
yolo_models = ["yolov8n.pt", "yolov8s.pt", "yolov8m.pt"]
|
|
|
|
| 318 |
with gr.Tabs() as comparison_tab:
|
| 319 |
with gr.TabItem("Performance Comparison"):
|
| 320 |
perf_table = gr.DataFrame(
|
| 321 |
+
headers=["Tracker", "Processing Time", "Status"],
|
| 322 |
+
datatype=["str", "str", "str"],
|
| 323 |
label="Performance Comparison"
|
| 324 |
)
|
| 325 |
|
|
|
|
| 328 |
fn=benchmark_trackers,
|
| 329 |
inputs=[input_video, yolo_model, reid_model, class_ids, conf_threshold],
|
| 330 |
outputs=[
|
| 331 |
+
bytetrack_video, botsort_video, ocsort_video, strongsort_video,
|
| 332 |
+
bytetrack_status, botsort_status, ocsort_status, strongsort_status,
|
| 333 |
+
bytetrack_time, botsort_time, ocsort_time, strongsort_time,
|
| 334 |
+
perf_table
|
| 335 |
],
|
| 336 |
show_progress="full"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 337 |
)
|
| 338 |
|
| 339 |
# Add a debug section
|