Enable default cfg for similar args in solutions. (#17112)
Co-authored-by: UltralyticsAssistant <web@ultralytics.com> Co-authored-by: Ultralytics Assistant <135830346+UltralyticsAssistant@users.noreply.github.com> Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
This commit is contained in:
parent
be40a45ec3
commit
a76f5293b4
4 changed files with 19 additions and 17 deletions
|
|
@ -1,18 +1,19 @@
|
||||||
# Ultralytics YOLO 🚀, AGPL-3.0 license
|
# Ultralytics YOLO 🚀, AGPL-3.0 license
|
||||||
|
|
||||||
# Configuration for Ultralytics Solutions
|
# Configuration for Ultralytics Solutions
|
||||||
|
|
||||||
model: "yolo11n.pt" # The Ultralytics YOLO11 model to be used (e.g., yolo11n.pt for YOLO11 nano version and yolov8n.pt for YOLOv8 nano version)
|
# Object counting settings
|
||||||
|
|
||||||
region: # Object counting, queue or speed estimation region points. Default region points are [(20, 400), (1080, 404), (1080, 360), (20, 360)]
|
region: # Object counting, queue or speed estimation region points. Default region points are [(20, 400), (1080, 404), (1080, 360), (20, 360)]
|
||||||
line_width: 2 # Width of the annotator used to draw regions on the image/video frames + bounding boxes and tracks drawing. Default value is 2.
|
|
||||||
show: True # Flag to control whether to display output image or not, you can set this as False i.e. when deploying it on some embedded devices.
|
|
||||||
show_in: True # Flag to display objects moving *into* the defined region
|
show_in: True # Flag to display objects moving *into* the defined region
|
||||||
show_out: True # Flag to display objects moving *out of* the defined region
|
show_out: True # Flag to display objects moving *out of* the defined region
|
||||||
classes: # To count specific classes. i.e, if you want to detect, track and count the person with COCO model, you can use classes=0, Default its None
|
|
||||||
|
# Heatmaps settings
|
||||||
|
colormap: # Colormap for heatmap, Only OPENCV supported colormaps can be used. By default COLORMAP_PARULA will be used for visualization.
|
||||||
|
|
||||||
|
# Workouts monitoring settings
|
||||||
up_angle: 145.0 # Workouts up_angle for counts, 145.0 is default value. You can adjust it for different workouts, based on position of keypoints.
|
up_angle: 145.0 # Workouts up_angle for counts, 145.0 is default value. You can adjust it for different workouts, based on position of keypoints.
|
||||||
down_angle: 90 # Workouts down_angle for counts, 90 is default value. You can change it for different workouts, based on position of keypoints.
|
down_angle: 90 # Workouts down_angle for counts, 90 is default value. You can change it for different workouts, based on position of keypoints.
|
||||||
kpts: [6, 8, 10] # Keypoints for workouts monitoring, i.e. If you want to consider keypoints for pushups that have mostly values of [6, 8, 10].
|
kpts: [6, 8, 10] # Keypoints for workouts monitoring, i.e. If you want to consider keypoints for pushups that have mostly values of [6, 8, 10].
|
||||||
colormap: # Colormap for heatmap, Only OPENCV supported colormaps can be used. By default COLORMAP_PARULA will be used for visualization.
|
|
||||||
|
# Analytics settings
|
||||||
analytics_type: "line" # Analytics type i.e "line", "pie", "bar" or "area" charts. By default, "line" analytics will be used for processing.
|
analytics_type: "line" # Analytics type i.e "line", "pie", "bar" or "area" charts. By default, "line" analytics will be used for processing.
|
||||||
json_file: # parking system regions file path.
|
json_file: # parking system regions file path.
|
||||||
|
|
|
||||||
|
|
@ -168,7 +168,6 @@ class ParkingManagement(BaseSolution):
|
||||||
Examples:
|
Examples:
|
||||||
>>> from ultralytics.solutions import ParkingManagement
|
>>> from ultralytics.solutions import ParkingManagement
|
||||||
>>> parking_manager = ParkingManagement(model="yolov8n.pt", json_file="parking_regions.json")
|
>>> parking_manager = ParkingManagement(model="yolov8n.pt", json_file="parking_regions.json")
|
||||||
>>> results = parking_manager(source="parking_lot_video.mp4")
|
|
||||||
>>> print(f"Occupied spaces: {parking_manager.pr_info['Occupancy']}")
|
>>> print(f"Occupied spaces: {parking_manager.pr_info['Occupancy']}")
|
||||||
>>> print(f"Available spaces: {parking_manager.pr_info['Available']}")
|
>>> print(f"Available spaces: {parking_manager.pr_info['Available']}")
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,13 @@
|
||||||
# Ultralytics YOLO 🚀, AGPL-3.0 license
|
# Ultralytics YOLO 🚀, AGPL-3.0 license
|
||||||
|
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
import cv2
|
import cv2
|
||||||
|
|
||||||
from ultralytics import YOLO
|
from ultralytics import YOLO
|
||||||
from ultralytics.utils import LOGGER, yaml_load
|
from ultralytics.utils import DEFAULT_CFG_DICT, DEFAULT_SOL_DICT, LOGGER
|
||||||
from ultralytics.utils.checks import check_imshow, check_requirements
|
from ultralytics.utils.checks import check_imshow, check_requirements
|
||||||
|
|
||||||
DEFAULT_SOL_CFG_PATH = Path(__file__).resolve().parents[1] / "cfg/solutions/default.yaml"
|
|
||||||
|
|
||||||
|
|
||||||
class BaseSolution:
|
class BaseSolution:
|
||||||
"""
|
"""
|
||||||
|
|
@ -55,15 +52,18 @@ class BaseSolution:
|
||||||
self.Point = Point
|
self.Point = Point
|
||||||
|
|
||||||
# Load config and update with args
|
# Load config and update with args
|
||||||
self.CFG = yaml_load(DEFAULT_SOL_CFG_PATH)
|
DEFAULT_SOL_DICT.update(kwargs)
|
||||||
self.CFG.update(kwargs)
|
DEFAULT_CFG_DICT.update(kwargs)
|
||||||
LOGGER.info(f"Ultralytics Solutions: ✅ {self.CFG}")
|
self.CFG = {**DEFAULT_SOL_DICT, **DEFAULT_CFG_DICT}
|
||||||
|
LOGGER.info(f"Ultralytics Solutions: ✅ {DEFAULT_SOL_DICT}")
|
||||||
|
|
||||||
self.region = self.CFG["region"] # Store region data for other classes usage
|
self.region = self.CFG["region"] # Store region data for other classes usage
|
||||||
self.line_width = self.CFG["line_width"] # Store line_width for usage
|
self.line_width = (
|
||||||
|
self.CFG["line_width"] if self.CFG["line_width"] is not None else 2
|
||||||
|
) # Store line_width for usage
|
||||||
|
|
||||||
# Load Model and store classes names
|
# Load Model and store classes names
|
||||||
self.model = YOLO(self.CFG["model"])
|
self.model = YOLO(self.CFG["model"] if self.CFG["model"] else "yolov8n.pt")
|
||||||
self.names = self.model.names
|
self.names = self.model.names
|
||||||
|
|
||||||
# Initialize environment and region setup
|
# Initialize environment and region setup
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,7 @@ FILE = Path(__file__).resolve()
|
||||||
ROOT = FILE.parents[1] # YOLO
|
ROOT = FILE.parents[1] # YOLO
|
||||||
ASSETS = ROOT / "assets" # default images
|
ASSETS = ROOT / "assets" # default images
|
||||||
DEFAULT_CFG_PATH = ROOT / "cfg/default.yaml"
|
DEFAULT_CFG_PATH = ROOT / "cfg/default.yaml"
|
||||||
|
DEFAULT_SOL_CFG_PATH = ROOT / "cfg/solutions/default.yaml" # Ultralytics solutions yaml path
|
||||||
NUM_THREADS = min(8, max(1, os.cpu_count() - 1)) # number of YOLO multiprocessing threads
|
NUM_THREADS = min(8, max(1, os.cpu_count() - 1)) # number of YOLO multiprocessing threads
|
||||||
AUTOINSTALL = str(os.getenv("YOLO_AUTOINSTALL", True)).lower() == "true" # global auto-install mode
|
AUTOINSTALL = str(os.getenv("YOLO_AUTOINSTALL", True)).lower() == "true" # global auto-install mode
|
||||||
VERBOSE = str(os.getenv("YOLO_VERBOSE", True)).lower() == "true" # global verbose mode
|
VERBOSE = str(os.getenv("YOLO_VERBOSE", True)).lower() == "true" # global verbose mode
|
||||||
|
|
@ -508,6 +509,7 @@ def yaml_print(yaml_file: Union[str, Path, dict]) -> None:
|
||||||
|
|
||||||
# Default configuration
|
# Default configuration
|
||||||
DEFAULT_CFG_DICT = yaml_load(DEFAULT_CFG_PATH)
|
DEFAULT_CFG_DICT = yaml_load(DEFAULT_CFG_PATH)
|
||||||
|
DEFAULT_SOL_DICT = yaml_load(DEFAULT_SOL_CFG_PATH) # Ultralytics solutions configuration
|
||||||
for k, v in DEFAULT_CFG_DICT.items():
|
for k, v in DEFAULT_CFG_DICT.items():
|
||||||
if isinstance(v, str) and v.lower() == "none":
|
if isinstance(v, str) and v.lower() == "none":
|
||||||
DEFAULT_CFG_DICT[k] = None
|
DEFAULT_CFG_DICT[k] = None
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue