ultralytics 8.2.56 Streamlit tracking app (#14269)

Signed-off-by: Glenn Jocher <glenn.jocher@ultralytics.com>
Co-authored-by: UltralyticsAssistant <web@ultralytics.com>
Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
Co-authored-by: Ultralytics Assistant <135830346+UltralyticsAssistant@users.noreply.github.com>
Co-authored-by: Nguyễn Anh Bình <sometimesocrazy@gmail.com>
Co-authored-by: Johnny <johnnynuca14@gmail.com>
This commit is contained in:
Muhammad Rizwan Munawar 2024-07-14 03:34:09 +05:00 committed by GitHub
parent abd391b633
commit 21ca235681
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 17 additions and 27 deletions

View file

@ -7,7 +7,7 @@ This repository provides a Rust demo for performing YOLOv8 tasks like `Classific
- Add YOLOv8-OBB demo - Add YOLOv8-OBB demo
- Update ONNXRuntime to 1.17.x - 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 ## Features

View file

@ -1,6 +1,6 @@
# Ultralytics YOLO 🚀, AGPL-3.0 license # Ultralytics YOLO 🚀, AGPL-3.0 license
__version__ = "8.2.55" __version__ = "8.2.56"
import os import os

View file

@ -6,6 +6,8 @@ import time
import cv2 import cv2
import torch import torch
from ultralytics.utils.downloads import GITHUB_ASSETS_STEMS
def inference(): def inference():
"""Runs real-time object detection on video input using Ultralytics YOLOv8 in a Streamlit application.""" """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 vid_file_name = 0
# Add dropdown menu for model selection # Add dropdown menu for model selection
yolov8_model = st.sidebar.selectbox( available_models = (x.replace("yolo", "YOLO") for x in GITHUB_ASSETS_STEMS if x.startswith("yolov8"))
"Model", selected_model = st.sidebar.selectbox("Model", available_models)
( with st.spinner("Model is downloading..."):
"YOLOv8n", model = YOLO(f"{selected_model.lower()}.pt") # Load the YOLO model
"YOLOv8s", class_names = list(model.names.values()) # Convert dictionary to list of class names
"YOLOv8m", st.success("Model loaded successfully!")
"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
# Multiselect box with class names and get indices of selected classes # Multiselect box with class names and get indices of selected classes
selected_classes = st.sidebar.multiselect("Classes", class_names, default=class_names[:3]) 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 if not isinstance(selected_ind, list): # Ensure selected_options is a list
selected_ind = list(selected_ind) selected_ind = list(selected_ind)
conf_thres = st.sidebar.slider("Confidence Threshold", 0.0, 1.0, 0.25, 0.01) enable_trk = st.sidebar.radio("Enable Tracking", ("Yes", "No"))
nms_thres = st.sidebar.slider("NMS Threshold", 0.0, 1.0, 0.45, 0.01) 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) col1, col2 = st.columns(2)
org_frame = col1.empty() org_frame = col1.empty()
@ -124,7 +111,10 @@ def inference():
prev_time = curr_time prev_time = curr_time
# Store model predictions # 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 annotated_frame = results[0].plot() # Add annotations on frame
# display frame # display frame