From 21ca23568105848901439d9ebcb62d237a53adb1 Mon Sep 17 00:00:00 2001 From: Muhammad Rizwan Munawar Date: Sun, 14 Jul 2024 03:34:09 +0500 Subject: [PATCH] `ultralytics 8.2.56` Streamlit tracking app (#14269) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Glenn Jocher Co-authored-by: UltralyticsAssistant Co-authored-by: Glenn Jocher Co-authored-by: Ultralytics Assistant <135830346+UltralyticsAssistant@users.noreply.github.com> Co-authored-by: Nguyễn Anh Bình Co-authored-by: Johnny --- examples/YOLOv8-ONNXRuntime-Rust/README.md | 2 +- ultralytics/__init__.py | 2 +- ultralytics/solutions/streamlit_inference.py | 40 ++++++++------------ 3 files changed, 17 insertions(+), 27 deletions(-) diff --git a/examples/YOLOv8-ONNXRuntime-Rust/README.md b/examples/YOLOv8-ONNXRuntime-Rust/README.md index e4cfd7f50f..48a3017ce8 100644 --- a/examples/YOLOv8-ONNXRuntime-Rust/README.md +++ b/examples/YOLOv8-ONNXRuntime-Rust/README.md @@ -7,7 +7,7 @@ This repository provides a Rust demo for performing YOLOv8 tasks like `Classific - Add YOLOv8-OBB demo - Update ONNXRuntime to 1.17.x -Newly updated YOLOv8 example code is located in this repository (https://github.com/jamjamjon/usls/tree/main/examples/yolov8) +Newly updated YOLOv8 example code is located in this repository (https://github.com/jamjamjon/usls/tree/main/examples/yolo) ## Features diff --git a/ultralytics/__init__.py b/ultralytics/__init__.py index 3ab357bd9c..0d552a9b58 100644 --- a/ultralytics/__init__.py +++ b/ultralytics/__init__.py @@ -1,6 +1,6 @@ # Ultralytics YOLO 🚀, AGPL-3.0 license -__version__ = "8.2.55" +__version__ = "8.2.56" import os diff --git a/ultralytics/solutions/streamlit_inference.py b/ultralytics/solutions/streamlit_inference.py index b8fdc74f62..7f89963ace 100644 --- a/ultralytics/solutions/streamlit_inference.py +++ b/ultralytics/solutions/streamlit_inference.py @@ -6,6 +6,8 @@ import time import cv2 import torch +from ultralytics.utils.downloads import GITHUB_ASSETS_STEMS + def inference(): """Runs real-time object detection on video input using Ultralytics YOLOv8 in a Streamlit application.""" @@ -65,28 +67,12 @@ def inference(): vid_file_name = 0 # Add dropdown menu for model selection - yolov8_model = st.sidebar.selectbox( - "Model", - ( - "YOLOv8n", - "YOLOv8s", - "YOLOv8m", - "YOLOv8l", - "YOLOv8x", - "YOLOv8n-Seg", - "YOLOv8s-Seg", - "YOLOv8m-Seg", - "YOLOv8l-Seg", - "YOLOv8x-Seg", - "YOLOv8n-Pose", - "YOLOv8s-Pose", - "YOLOv8m-Pose", - "YOLOv8l-Pose", - "YOLOv8x-Pose", - ), - ) - model = YOLO(f"{yolov8_model.lower()}.pt") # Load the yolov8 model - class_names = list(model.names.values()) # Convert dictionary to list of class names + available_models = (x.replace("yolo", "YOLO") for x in GITHUB_ASSETS_STEMS if x.startswith("yolov8")) + selected_model = st.sidebar.selectbox("Model", available_models) + with st.spinner("Model is downloading..."): + model = YOLO(f"{selected_model.lower()}.pt") # Load the YOLO model + class_names = list(model.names.values()) # Convert dictionary to list of class names + st.success("Model loaded successfully!") # Multiselect box with class names and get indices of selected classes selected_classes = st.sidebar.multiselect("Classes", class_names, default=class_names[:3]) @@ -95,8 +81,9 @@ def inference(): if not isinstance(selected_ind, list): # Ensure selected_options is a list selected_ind = list(selected_ind) - conf_thres = st.sidebar.slider("Confidence Threshold", 0.0, 1.0, 0.25, 0.01) - nms_thres = st.sidebar.slider("NMS Threshold", 0.0, 1.0, 0.45, 0.01) + enable_trk = st.sidebar.radio("Enable Tracking", ("Yes", "No")) + conf = float(st.sidebar.slider("Confidence Threshold", 0.0, 1.0, 0.25, 0.01)) + iou = float(st.sidebar.slider("IoU Threshold", 0.0, 1.0, 0.45, 0.01)) col1, col2 = st.columns(2) org_frame = col1.empty() @@ -124,7 +111,10 @@ def inference(): prev_time = curr_time # Store model predictions - results = model(frame, conf=float(conf_thres), iou=float(nms_thres), classes=selected_ind) + if enable_trk: + results = model.track(frame, conf=conf, iou=iou, classes=selected_ind, persist=True) + else: + results = model(frame, conf=conf, iou=iou, classes=selected_ind) annotated_frame = results[0].plot() # Add annotations on frame # display frame