| import os |
| os.system("pip3 install cython_bbox gdown 'git+https://github.com/cocodataset/cocoapi.git#subdirectory=PythonAPI'") |
| from torchyolo import YoloHub |
| import gradio as gr |
| from utils import attempt_download_from_hub |
|
|
|
|
|
|
| def object_tracker( |
| source: str, |
| model_type: str, |
| model_path: str, |
| tracker_type: str, |
| tracker_config_path: str, |
| StrongSort_OsNet_Path: str = None, |
| ): |
| model = YoloHub( |
| config_path="default_config.yaml", |
| model_type=model_type, |
| model_path=model_path, |
| ) |
|
|
| if tracker_type == "STRONGSORT": |
| StrongSort_OsNet_Path = attempt_download_from_hub(StrongSort_OsNet_Path) |
|
|
| model.predict( |
| source=source, |
| tracker_type=tracker_type, |
| tracker_weight_path=StrongSort_OsNet_Path, |
| tracker_config_path=tracker_config_path, |
| ) |
|
|
| return 'output.mp4' |
| |
|
|
| inputs = [ |
| gr.Video(), |
| gr.inputs.Dropdown( |
| label="Model Type", |
| choices=["yolov5"], |
| default="yolov5", |
| ), |
| gr.inputs.Dropdown( |
| label="Model Path", |
| choices=[ |
| "aijack/v5s" ], |
| default="aijack/v5s", |
| ), |
| gr.inputs.Dropdown( |
| label="Tracker Type", |
| choices=["OCSORT"], |
| default="OCSORT", |
| ), |
| gr.inputs.Dropdown( |
| label="Tracker Config Path", |
| choices=[ |
| "tracker/oc_sort.yaml", |
| ], |
| default="tracker/oc_sort.yaml", |
| ), |
| gr.inputs.Dropdown( |
| label="Tracker Weight Path", |
| choices=[ |
| "aijack/osnet" |
| ], |
| default="aijack/osnet", |
| ), |
| ] |
| examples = [ |
| [ |
| "01.mp4", |
| "yolov5", |
| "aijack/v5s", |
| "OCSORT", |
| "tracker/oc_sort.yaml", |
| ] |
| ] |
| outputs = gr.Video() |
| title = "YOLOV5 Object Detection and Track Algorithm Library" |
| article = "<p style='text-align: center'><a href='http://claireye.com.tw'>Claireye</a> | 2023</p>" |
| demo_app = gr.Interface( |
| fn=object_tracker, |
| inputs=inputs, |
| examples=examples, |
| outputs=outputs, |
| title=title, |
| article = article, |
| cache_examples=False |
| ) |
| demo_app.launch(debug=True, enable_queue=True) |