Merge branch 'main' into quan

mct-2.1.1
Francesco Mattioli 5 months ago committed by GitHub
commit c292752234
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 12
      docs/en/hub/datasets.md
  2. 2
      ultralytics/__init__.py
  3. 11
      ultralytics/engine/model.py
  4. 14
      ultralytics/utils/metrics.py

@ -98,6 +98,18 @@ Next, [train a model](./models.md#train-model) on your dataset.
![Ultralytics HUB screenshot of the Dataset page with an arrow pointing to the Train Model button](https://raw.githubusercontent.com/ultralytics/assets/main/docs/hub/datasets/hub_upload_dataset_9.jpg) ![Ultralytics HUB screenshot of the Dataset page with an arrow pointing to the Train Model button](https://raw.githubusercontent.com/ultralytics/assets/main/docs/hub/datasets/hub_upload_dataset_9.jpg)
## Download Dataset
Navigate to the Dataset page of the dataset you want to download, open the dataset actions dropdown and click on the **Download** option. This action will start downloading your dataset.
![Ultralytics HUB screenshot of the Dataset page with an arrow pointing to the Download option](https://raw.githubusercontent.com/ultralytics/assets/main/docs/hub/datasets/hub_download_dataset_1.jpg)
??? tip "Tip"
You can download a dataset directly from the [Datasets](https://hub.ultralytics.com/datasets) page.
![Ultralytics HUB screenshot of the Datasets page with an arrow pointing to the Download option of one of the datasets](https://raw.githubusercontent.com/ultralytics/assets/main/docs/hub/datasets/hub_download_dataset_2.jpg)
## Share Dataset ## Share Dataset
!!! info "Info" !!! info "Info"

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

@ -6,6 +6,7 @@ from typing import List, Union
import numpy as np import numpy as np
import torch import torch
from PIL import Image
from ultralytics.cfg import TASK2DATA, get_cfg, get_save_dir from ultralytics.cfg import TASK2DATA, get_cfg, get_save_dir
from ultralytics.engine.results import Results from ultralytics.engine.results import Results
@ -143,7 +144,7 @@ class Model(nn.Module):
def __call__( def __call__(
self, self,
source: Union[str, Path, int, list, tuple, np.ndarray, torch.Tensor] = None, source: Union[str, Path, int, Image.Image, list, tuple, np.ndarray, torch.Tensor] = None,
stream: bool = False, stream: bool = False,
**kwargs, **kwargs,
) -> list: ) -> list:
@ -504,7 +505,7 @@ class Model(nn.Module):
def predict( def predict(
self, self,
source: Union[str, Path, int, list, tuple, np.ndarray, torch.Tensor] = None, source: Union[str, Path, int, Image.Image, list, tuple, np.ndarray, torch.Tensor] = None,
stream: bool = False, stream: bool = False,
predictor=None, predictor=None,
**kwargs, **kwargs,
@ -517,7 +518,7 @@ class Model(nn.Module):
types of image sources and can operate in a streaming mode. types of image sources and can operate in a streaming mode.
Args: Args:
source (str | Path | int | List[str] | List[Path] | List[int] | np.ndarray | torch.Tensor): The source source (str | Path | int | PIL.Image | np.ndarray | torch.Tensor | List | Tuple): The source
of the image(s) to make predictions on. Accepts various types including file paths, URLs, PIL of the image(s) to make predictions on. Accepts various types including file paths, URLs, PIL
images, numpy arrays, and torch tensors. images, numpy arrays, and torch tensors.
stream (bool): If True, treats the input source as a continuous stream for predictions. stream (bool): If True, treats the input source as a continuous stream for predictions.
@ -900,7 +901,7 @@ class Model(nn.Module):
initialized, it sets it up before retrieving the names. initialized, it sets it up before retrieving the names.
Returns: Returns:
(List[str]): A list of class names associated with the model. (Dict[int, str]): A dict of class names associated with the model.
Raises: Raises:
AttributeError: If the model or predictor does not have a 'names' attribute. AttributeError: If the model or predictor does not have a 'names' attribute.
@ -908,7 +909,7 @@ class Model(nn.Module):
Examples: Examples:
>>> model = YOLO('yolov8n.pt') >>> model = YOLO('yolov8n.pt')
>>> print(model.names) >>> print(model.names)
['person', 'bicycle', 'car', ...] {0: 'person', 1: 'bicycle', 2: 'car', ...}
""" """
from ultralytics.nn.autobackend import check_class_names from ultralytics.nn.autobackend import check_class_names

@ -445,7 +445,7 @@ def smooth(y, f=0.05):
@plt_settings() @plt_settings()
def plot_pr_curve(px, py, ap, save_dir=Path("pr_curve.png"), names=(), on_plot=None): def plot_pr_curve(px, py, ap, save_dir=Path("pr_curve.png"), names={}, on_plot=None):
"""Plots a precision-recall curve.""" """Plots a precision-recall curve."""
fig, ax = plt.subplots(1, 1, figsize=(9, 6), tight_layout=True) fig, ax = plt.subplots(1, 1, figsize=(9, 6), tight_layout=True)
py = np.stack(py, axis=1) py = np.stack(py, axis=1)
@ -470,7 +470,7 @@ def plot_pr_curve(px, py, ap, save_dir=Path("pr_curve.png"), names=(), on_plot=N
@plt_settings() @plt_settings()
def plot_mc_curve(px, py, save_dir=Path("mc_curve.png"), names=(), xlabel="Confidence", ylabel="Metric", on_plot=None): def plot_mc_curve(px, py, save_dir=Path("mc_curve.png"), names={}, xlabel="Confidence", ylabel="Metric", on_plot=None):
"""Plots a metric-confidence curve.""" """Plots a metric-confidence curve."""
fig, ax = plt.subplots(1, 1, figsize=(9, 6), tight_layout=True) fig, ax = plt.subplots(1, 1, figsize=(9, 6), tight_layout=True)
@ -528,7 +528,7 @@ def compute_ap(recall, precision):
def ap_per_class( def ap_per_class(
tp, conf, pred_cls, target_cls, plot=False, on_plot=None, save_dir=Path(), names=(), eps=1e-16, prefix="" tp, conf, pred_cls, target_cls, plot=False, on_plot=None, save_dir=Path(), names={}, eps=1e-16, prefix=""
): ):
""" """
Computes the average precision per class for object detection evaluation. Computes the average precision per class for object detection evaluation.
@ -541,7 +541,7 @@ def ap_per_class(
plot (bool, optional): Whether to plot PR curves or not. Defaults to False. plot (bool, optional): Whether to plot PR curves or not. Defaults to False.
on_plot (func, optional): A callback to pass plots path and data when they are rendered. Defaults to None. on_plot (func, optional): A callback to pass plots path and data when they are rendered. Defaults to None.
save_dir (Path, optional): Directory to save the PR curves. Defaults to an empty path. save_dir (Path, optional): Directory to save the PR curves. Defaults to an empty path.
names (tuple, optional): Tuple of class names to plot PR curves. Defaults to an empty tuple. names (dict, optional): Dict of class names to plot PR curves. Defaults to an empty tuple.
eps (float, optional): A small value to avoid division by zero. Defaults to 1e-16. eps (float, optional): A small value to avoid division by zero. Defaults to 1e-16.
prefix (str, optional): A prefix string for saving the plot files. Defaults to an empty string. prefix (str, optional): A prefix string for saving the plot files. Defaults to an empty string.
@ -799,13 +799,13 @@ class DetMetrics(SimpleClass):
save_dir (Path): A path to the directory where the output plots will be saved. Defaults to current directory. save_dir (Path): A path to the directory where the output plots will be saved. Defaults to current directory.
plot (bool): A flag that indicates whether to plot precision-recall curves for each class. Defaults to False. plot (bool): A flag that indicates whether to plot precision-recall curves for each class. Defaults to False.
on_plot (func): An optional callback to pass plots path and data when they are rendered. Defaults to None. on_plot (func): An optional callback to pass plots path and data when they are rendered. Defaults to None.
names (tuple of str): A tuple of strings that represents the names of the classes. Defaults to an empty tuple. names (dict of str): A dict of strings that represents the names of the classes. Defaults to an empty tuple.
Attributes: Attributes:
save_dir (Path): A path to the directory where the output plots will be saved. save_dir (Path): A path to the directory where the output plots will be saved.
plot (bool): A flag that indicates whether to plot the precision-recall curves for each class. plot (bool): A flag that indicates whether to plot the precision-recall curves for each class.
on_plot (func): An optional callback to pass plots path and data when they are rendered. on_plot (func): An optional callback to pass plots path and data when they are rendered.
names (tuple of str): A tuple of strings that represents the names of the classes. names (dict of str): A dict of strings that represents the names of the classes.
box (Metric): An instance of the Metric class for storing the results of the detection metrics. box (Metric): An instance of the Metric class for storing the results of the detection metrics.
speed (dict): A dictionary for storing the execution time of different parts of the detection process. speed (dict): A dictionary for storing the execution time of different parts of the detection process.
@ -822,7 +822,7 @@ class DetMetrics(SimpleClass):
curves_results: TODO curves_results: TODO
""" """
def __init__(self, save_dir=Path("."), plot=False, on_plot=None, names=()) -> None: def __init__(self, save_dir=Path("."), plot=False, on_plot=None, names={}) -> None:
"""Initialize a DetMetrics instance with a save directory, plot flag, callback function, and class names.""" """Initialize a DetMetrics instance with a save directory, plot flag, callback function, and class names."""
self.save_dir = save_dir self.save_dir = save_dir
self.plot = plot self.plot = plot

Loading…
Cancel
Save