diff --git a/.github/ISSUE_TEMPLATE/bug-report.yml b/.github/ISSUE_TEMPLATE/bug-report.yml index 5f02211de5..a1efcb5a31 100644 --- a/.github/ISSUE_TEMPLATE/bug-report.yml +++ b/.github/ISSUE_TEMPLATE/bug-report.yml @@ -43,7 +43,7 @@ body: - type: textarea attributes: label: Bug - description: Please provide as much information as possible. Copy and paste console output and error messages. Use [Markdown](https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax) to format text, code and logs. If necessary, include screenshots for visual elements only. Providing detailed information will help us resolve the issue more efficiently. + description: Please provide as much information as possible. Copy and paste console output and error messages including the _full_ traceback. Use [Markdown](https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax) to format text, code and logs. If necessary, include screenshots for visual elements only. Providing detailed information will help us resolve the issue more efficiently. placeholder: | 💡 ProTip! Include as much information as possible (logs, tracebacks, screenshots, etc.) to receive the most helpful response. validations: @@ -52,7 +52,7 @@ body: - type: textarea attributes: label: Environment - description: Many issues are often related to dependency versions and hardware. Please provide the output of `yolo checks` (CLI) or `ultralytics.utils.checks.collect_system_info()` (Python) command to help us diagnose the problem. + description: Try the latest version (`pip install -U ultralytics`) before reporting a bug. If it's still present, please provide the output of `yolo checks` (CLI) or `ultralytics.utils.checks.collect_system_info()` (Python) command to help us diagnose the problem. placeholder: | Paste output of `yolo checks` (CLI) or `ultralytics.utils.checks.collect_system_info()` (Python) command, i.e.: ``` diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yml similarity index 97% rename from .github/workflows/ci.yaml rename to .github/workflows/ci.yml index b457baf3ea..fd96940981 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yml @@ -39,8 +39,7 @@ on: jobs: HUB: - # if: github.repository == 'ultralytics/ultralytics' && (github.event_name == 'schedule' || github.event_name == 'push' || (github.event_name == 'workflow_dispatch' && github.event.inputs.hub == 'true')) - if: github.repository == 'ultralytics/ultralytics' && 'workflow_dispatch' && github.event.inputs.hub == 'true' + if: github.repository == 'ultralytics/ultralytics' && (github.event_name == 'schedule' || github.event_name == 'push' || (github.event_name == 'workflow_dispatch' && github.event.inputs.hub == 'true')) runs-on: ${{ matrix.os }} strategy: fail-fast: false @@ -165,7 +164,7 @@ jobs: torch: [latest] include: - os: ubuntu-latest - python-version: "3.9" # torch 1.8.0 requires python >=3.6, <=3.9 + python-version: "3.8" # torch 1.8.0 requires python >=3.6, <=3.9 torch: "1.8.0" # min torch version CI https://pypi.org/project/torchvision/ steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yml similarity index 100% rename from .github/workflows/docker.yaml rename to .github/workflows/docker.yml diff --git a/docker/Dockerfile b/docker/Dockerfile index 9e6bc34bbf..2cfbfd352e 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -3,7 +3,7 @@ # Image is CUDA-optimized for YOLO11 single/multi-GPU training and inference # Start FROM PyTorch image https://hub.docker.com/r/pytorch/pytorch or nvcr.io/nvidia/pytorch:23.03-py3 -FROM pytorch/pytorch:2.5.0-cuda12.4-cudnn9-runtime +FROM pytorch/pytorch:2.5.1-cuda12.4-cudnn9-runtime # Set environment variables # Avoid DDP error "MKL_THREADING_LAYER=INTEL is incompatible with libgomp.so.1 library" https://github.com/pytorch/pytorch/issues/37377 diff --git a/docs/en/datasets/detect/brain-tumor.md b/docs/en/datasets/detect/brain-tumor.md index b2498d6f00..cb06b9c09e 100644 --- a/docs/en/datasets/detect/brain-tumor.md +++ b/docs/en/datasets/detect/brain-tumor.md @@ -6,6 +6,8 @@ keywords: brain tumor dataset, MRI scans, CT scans, brain tumor detection, medic # Brain Tumor Dataset +Open Brain Tumor Dataset In Colab + A brain tumor detection dataset consists of medical images from MRI or CT scans, containing information about brain tumor presence, location, and characteristics. This dataset is essential for training [computer vision](https://www.ultralytics.com/glossary/computer-vision-cv) algorithms to automate brain tumor identification, aiding in early diagnosis and treatment planning.

diff --git a/docs/en/datasets/detect/medical-pills.md b/docs/en/datasets/detect/medical-pills.md index a24b20c260..77585b2c3e 100644 --- a/docs/en/datasets/detect/medical-pills.md +++ b/docs/en/datasets/detect/medical-pills.md @@ -6,6 +6,8 @@ keywords: medical-pills dataset, pill detection, pharmaceutical imaging, AI in h # Medical Pills Dataset +Open Medical Pills Dataset In Colab + The medical-pills detection dataset is a proof-of-concept (POC) dataset, carefully curated to demonstrate the potential of AI in pharmaceutical applications. It contains labeled images specifically designed to train [computer vision](https://www.ultralytics.com/glossary/computer-vision-cv) [models](https://docs.ultralytics.com/models/) for identifying medical-pills. This dataset serves as a foundational resource for automating essential [tasks](https://docs.ultralytics.com/tasks/) such as quality control, packaging automation, and efficient sorting in pharmaceutical workflows. By integrating this dataset into projects, researchers and developers can explore innovative [solutions](https://docs.ultralytics.com/solutions/) that enhance [accuracy](https://www.ultralytics.com/glossary/accuracy), streamline operations, and ultimately contribute to improved healthcare outcomes. ## Dataset Structure diff --git a/docs/en/datasets/segment/carparts-seg.md b/docs/en/datasets/segment/carparts-seg.md index dbc69ce4a7..e3437c5107 100644 --- a/docs/en/datasets/segment/carparts-seg.md +++ b/docs/en/datasets/segment/carparts-seg.md @@ -6,6 +6,8 @@ keywords: Carparts Segmentation Dataset, Roboflow, computer vision, automotive A # Roboflow Universe Carparts Segmentation Dataset +Open Carparts Segmentation Dataset In Colab + The [Roboflow](https://roboflow.com/?ref=ultralytics) [Carparts Segmentation Dataset](https://universe.roboflow.com/gianmarco-russo-vt9xr/car-seg-un1pm?ref=ultralytics) is a curated collection of images and videos designed for [computer vision](https://www.ultralytics.com/glossary/computer-vision-cv) applications, specifically focusing on segmentation tasks related to car parts. This dataset provides a diverse set of visuals captured from multiple perspectives, offering valuable annotated examples for training and testing segmentation models. Whether you're working on automotive research, developing AI solutions for vehicle maintenance, or exploring computer vision applications, the Carparts Segmentation Dataset serves as a valuable resource for enhancing accuracy and efficiency in your projects. diff --git a/docs/en/datasets/segment/index.md b/docs/en/datasets/segment/index.md index 9a83ed1645..9a95424106 100644 --- a/docs/en/datasets/segment/index.md +++ b/docs/en/datasets/segment/index.md @@ -140,15 +140,9 @@ To auto-annotate your dataset using the Ultralytics framework, you can use the ` auto_annotate(data="path/to/images", det_model="yolo11x.pt", sam_model="sam_b.pt") ``` -| Argument | Type | Description | Default | -| ------------ | ----------------------- | ----------------------------------------------------------------------------------------------------------- | -------------- | -| `data` | `str` | Path to a folder containing images to be annotated. | `None` | -| `det_model` | `str, optional` | Pre-trained YOLO detection model. Defaults to `'yolo11x.pt'`. | `'yolo11x.pt'` | -| `sam_model` | `str, optional` | Pre-trained SAM segmentation model. Defaults to `'sam_b.pt'`. | `'sam_b.pt'` | -| `device` | `str, optional` | Device to run the models on. Defaults to an empty string (CPU or GPU, if available). | `''` | -| `output_dir` | `str or None, optional` | Directory to save the annotated results. Defaults to a `'labels'` folder in the same directory as `'data'`. | `None` | +{% include "macros/sam-auto-annotate.md" %} -The `auto_annotate` function takes the path to your images, along with optional arguments for specifying the pre-trained detection and [SAM segmentation models](../../models/sam.md), the device to run the models on, and the output directory for saving the annotated results. +The `auto_annotate` function takes the path to your images, along with optional arguments for specifying the pre-trained detection models i.e. [YOLO11](../../models/yolo11.md), [YOLOv8](../../models/yolov8.md) or other [models](../../models/index.md) and segmentation models i.e, [SAM](../../models/sam.md), [SAM2](../../models/sam-2.md) or [MobileSAM](../../models/mobile-sam.md), the device to run the models on, and the output directory for saving the annotated results. By leveraging the power of pre-trained models, auto-annotation can significantly reduce the time and effort required for creating high-quality segmentation datasets. This feature is particularly useful for researchers and developers working with large image collections, as it allows them to focus on model development and evaluation rather than manual annotation. @@ -195,7 +189,7 @@ Auto-annotation in Ultralytics YOLO allows you to generate segmentation annotati ```python from ultralytics.data.annotator import auto_annotate -auto_annotate(data="path/to/images", det_model="yolo11x.pt", sam_model="sam_b.pt") +auto_annotate(data="path/to/images", det_model="yolo11x.pt", sam_model="sam_b.pt") # or sam_model="mobile_sam.pt" ``` -This function automates the annotation process, making it faster and more efficient. For more details, explore the [Auto-Annotation](#auto-annotation) section. +This function automates the annotation process, making it faster and more efficient. For more details, explore the [Auto-Annotate Reference](https://docs.ultralytics.com/reference/data/annotator/#ultralytics.data.annotator.auto_annotate). diff --git a/docs/en/datasets/segment/package-seg.md b/docs/en/datasets/segment/package-seg.md index 8f377e0ae6..bd6446983c 100644 --- a/docs/en/datasets/segment/package-seg.md +++ b/docs/en/datasets/segment/package-seg.md @@ -6,6 +6,8 @@ keywords: Roboflow, Package Segmentation Dataset, computer vision, package ident # Roboflow Universe Package Segmentation Dataset +Open Package Segmentation Dataset In Colab + The [Roboflow](https://roboflow.com/?ref=ultralytics) [Package Segmentation Dataset](https://universe.roboflow.com/factorypackage/factory_package?ref=ultralytics) is a curated collection of images specifically tailored for tasks related to package segmentation in the field of [computer vision](https://www.ultralytics.com/glossary/computer-vision-cv). This dataset is designed to assist researchers, developers, and enthusiasts working on projects related to package identification, sorting, and handling. Containing a diverse set of images showcasing various packages in different contexts and environments, the dataset serves as a valuable resource for training and evaluating segmentation models. Whether you are engaged in logistics, warehouse automation, or any application requiring precise package analysis, the Package Segmentation Dataset provides a targeted and comprehensive set of images to enhance the performance of your computer vision algorithms. diff --git a/docs/en/guides/heatmaps.md b/docs/en/guides/heatmaps.md index 8bc86b69eb..5310eb98ca 100644 --- a/docs/en/guides/heatmaps.md +++ b/docs/en/guides/heatmaps.md @@ -8,6 +8,8 @@ keywords: Ultralytics, YOLO11, heatmaps, data visualization, data analysis, comp ## Introduction to Heatmaps +Open Heatmaps In Colab + A heatmap generated with [Ultralytics YOLO11](https://github.com/ultralytics/ultralytics/) transforms complex data into a vibrant, color-coded matrix. This visual tool employs a spectrum of colors to represent varying data values, where warmer hues indicate higher intensities and cooler tones signify lower values. Heatmaps excel in visualizing intricate data patterns, correlations, and anomalies, offering an accessible and engaging approach to data interpretation across diverse domains.

diff --git a/docs/en/guides/object-counting.md b/docs/en/guides/object-counting.md index 30b6a755de..73dcd3056d 100644 --- a/docs/en/guides/object-counting.md +++ b/docs/en/guides/object-counting.md @@ -8,6 +8,8 @@ keywords: object counting, YOLO11, Ultralytics, real-time object detection, AI, ## What is Object Counting? +Open Object Counting In Colab + Object counting with [Ultralytics YOLO11](https://github.com/ultralytics/ultralytics/) involves accurate identification and counting of specific objects in videos and camera streams. YOLO11 excels in real-time applications, providing efficient and precise object counting for various scenarios like crowd analysis and surveillance, thanks to its state-of-the-art algorithms and [deep learning](https://www.ultralytics.com/glossary/deep-learning-dl) capabilities.

diff --git a/docs/en/guides/sahi-tiled-inference.md b/docs/en/guides/sahi-tiled-inference.md index b656fdcac4..d76993ffc6 100644 --- a/docs/en/guides/sahi-tiled-inference.md +++ b/docs/en/guides/sahi-tiled-inference.md @@ -6,6 +6,8 @@ keywords: YOLO11, SAHI, Sliced Inference, Object Detection, Ultralytics, High-re # Ultralytics Docs: Using YOLO11 with SAHI for Sliced Inference +Open SAHI for Sliced Inference In Colab + Welcome to the Ultralytics documentation on how to use YOLO11 with [SAHI](https://github.com/obss/sahi) (Slicing Aided Hyper Inference). This comprehensive guide aims to furnish you with all the essential knowledge you'll need to implement SAHI alongside YOLO11. We'll deep-dive into what SAHI is, why sliced inference is critical for large-scale applications, and how to integrate these functionalities with YOLO11 for enhanced [object detection](https://www.ultralytics.com/glossary/object-detection) performance.

@@ -117,7 +119,7 @@ from sahi.predict import get_prediction result = get_prediction("demo_data/small-vehicles1.jpeg", detection_model) # With a numpy image -result = get_prediction(read_image("demo_data/small-vehicles1.jpeg"), detection_model) +result_with_np_image = get_prediction(read_image("demo_data/small-vehicles1.jpeg"), detection_model) ``` ### Visualize Results diff --git a/docs/en/guides/trackzone.md b/docs/en/guides/trackzone.md index ec98221385..eeab86f491 100644 --- a/docs/en/guides/trackzone.md +++ b/docs/en/guides/trackzone.md @@ -6,6 +6,8 @@ keywords: TrackZone, object tracking, YOLO11, Ultralytics, real-time object dete # TrackZone using Ultralytics YOLO11 +Open TrackZone In Colab + ## What is TrackZone? TrackZone specializes in monitoring objects within designated areas of a frame instead of the whole frame. Built on [Ultralytics YOLO11](https://github.com/ultralytics/ultralytics/), it integrates object detection and tracking specifically within zones for videos and live camera feeds. YOLO11's advanced algorithms and [deep learning](https://www.ultralytics.com/glossary/deep-learning-dl) technologies make it a perfect choice for real-time use cases, offering precise and efficient object tracking in applications like crowd monitoring and surveillance. diff --git a/docs/en/guides/workouts-monitoring.md b/docs/en/guides/workouts-monitoring.md index e2ec839d25..3919a708e7 100644 --- a/docs/en/guides/workouts-monitoring.md +++ b/docs/en/guides/workouts-monitoring.md @@ -6,6 +6,8 @@ keywords: workouts monitoring, Ultralytics YOLO11, pose estimation, fitness trac # Workouts Monitoring using Ultralytics YOLO11 +Open Workouts Monitoring In Colab + Monitoring workouts through pose estimation with [Ultralytics YOLO11](https://github.com/ultralytics/ultralytics/) enhances exercise assessment by accurately tracking key body landmarks and joints in real-time. This technology provides instant feedback on exercise form, tracks workout routines, and measures performance metrics, optimizing training sessions for users and trainers alike.

diff --git a/docs/en/macros/sam-auto-annotate.md b/docs/en/macros/sam-auto-annotate.md index 1d94e2e7fa..6cadbf0e76 100644 --- a/docs/en/macros/sam-auto-annotate.md +++ b/docs/en/macros/sam-auto-annotate.md @@ -1,12 +1,12 @@ -| Argument | Type | Default | Description | -| ------------ | ----------- | -------------- | --------------------------------------------------------------------------------- | -| `data` | `str` | required | Path to directory containing target images/videos for annotation or segmentation. | -| `det_model` | `str` | `"yolo11x.pt"` | YOLO detection model path for initial object detection. | -| `sam_model` | `str` | `"sam2_b.pt"` | SAM2 model path for segmentation (supports t/s/b/l variants and SAM2.1 models). | -| `device` | `str` | `""` | Computation device (e.g., 'cuda:0', 'cpu', or '' for automatic device detection). | -| `conf` | `float` | `0.25` | YOLO detection confidence threshold for filtering weak detections. | -| `iou` | `float` | `0.45` | IoU threshold for Non-Maximum Suppression to filter overlapping boxes. | -| `imgsz` | `int` | `640` | Input size for resizing images (must be multiple of 32). | -| `max_det` | `int` | `300` | Maximum number of detections per image for memory efficiency. | -| `classes` | `list[int]` | `None` | List of class indices to detect (e.g., `[0, 1]` for person & bicycle). | -| `output_dir` | `str` | `None` | Save directory for annotations (defaults to './labels' relative to data path). | +| Argument | Type | Default | Description | +| ------------ | ----------- | -------------- | ---------------------------------------------------------------------------------------------- | +| `data` | `str` | required | Path to directory containing target images/videos for annotation or segmentation. | +| `det_model` | `str` | `"yolo11x.pt"` | YOLO detection model path for initial object detection. | +| `sam_model` | `str` | `"sam2_b.pt"` | SAM2 model path for segmentation (supports t/s/b/l variants and SAM2.1) and mobile_sam models. | +| `device` | `str` | `""` | Computation device (e.g., 'cuda:0', 'cpu', or '' for automatic device detection). | +| `conf` | `float` | `0.25` | YOLO detection confidence threshold for filtering weak detections. | +| `iou` | `float` | `0.45` | IoU threshold for Non-Maximum Suppression to filter overlapping boxes. | +| `imgsz` | `int` | `640` | Input size for resizing images (must be multiple of 32). | +| `max_det` | `int` | `300` | Maximum number of detections per image for memory efficiency. | +| `classes` | `list[int]` | `None` | List of class indices to detect (e.g., `[0, 1]` for person & bicycle). | +| `output_dir` | `str` | `None` | Save directory for annotations (defaults to './labels' relative to data path). | diff --git a/docs/en/modes/val.md b/docs/en/modes/val.md index da275d6316..a1cd313910 100644 --- a/docs/en/modes/val.md +++ b/docs/en/modes/val.md @@ -47,7 +47,7 @@ These are the notable functionalities offered by YOLO11's Val mode: ## Usage Examples -Validate trained YOLO11n model [accuracy](https://www.ultralytics.com/glossary/accuracy) on the COCO8 dataset. No arguments are needed as the `model` retains its training `data` and arguments as model attributes. See Arguments section below for a full list of export arguments. +Validate trained YOLO11n model [accuracy](https://www.ultralytics.com/glossary/accuracy) on the COCO8 dataset. No arguments are needed as the `model` retains its training `data` and arguments as model attributes. See Arguments section below for a full list of validation arguments. !!! example diff --git a/ultralytics/__init__.py b/ultralytics/__init__.py index ec8851ed2f..67d53341f9 100644 --- a/ultralytics/__init__.py +++ b/ultralytics/__init__.py @@ -1,6 +1,6 @@ # Ultralytics YOLO 🚀, AGPL-3.0 license -__version__ = "8.3.59" +__version__ = "8.3.61" import os diff --git a/ultralytics/cfg/__init__.py b/ultralytics/cfg/__init__.py index a6551df8d2..8cb29bc2bf 100644 --- a/ultralytics/cfg/__init__.py +++ b/ultralytics/cfg/__init__.py @@ -280,7 +280,7 @@ def get_cfg(cfg: Union[str, Path, Dict, SimpleNamespace] = DEFAULT_CFG_DICT, ove Examples: >>> from ultralytics.cfg import get_cfg >>> config = get_cfg() # Load default configuration - >>> config = get_cfg("path/to/config.yaml", overrides={"epochs": 50, "batch_size": 16}) + >>> config_with_overrides = get_cfg("path/to/config.yaml", overrides={"epochs": 50, "batch_size": 16}) Notes: - If both `cfg` and `overrides` are provided, the values in `overrides` will take precedence. @@ -473,8 +473,7 @@ def check_dict_alignment(base: Dict, custom: Dict, e=None): """ custom = _handle_deprecation(custom) base_keys, custom_keys = (set(x.keys()) for x in (base, custom)) - mismatched = [k for k in custom_keys if k not in base_keys] - if mismatched: + if mismatched := [k for k in custom_keys if k not in base_keys]: from difflib import get_close_matches string = "" @@ -914,8 +913,19 @@ def entrypoint(debug=""): # Task task = overrides.pop("task", None) if task: - if task not in TASKS: - raise ValueError(f"Invalid 'task={task}'. Valid tasks are {TASKS}.\n{CLI_HELP_MSG}") + if task == "classify" and mode == "track": + raise ValueError( + f"❌ Classification doesn't support 'mode=track'. Valid modes for classification are" + f" {MODES - {'track'}}.\n{CLI_HELP_MSG}" + ) + elif task not in TASKS: + if task == "track": + LOGGER.warning( + "WARNING ⚠️ invalid 'task=track', setting 'task=detect' and 'mode=track'. Valid tasks are {TASKS}.\n{CLI_HELP_MSG}." + ) + task, mode = "detect", "track" + else: + raise ValueError(f"Invalid 'task={task}'. Valid tasks are {TASKS}.\n{CLI_HELP_MSG}") if "model" not in overrides: overrides["model"] = TASK2MODEL[task] diff --git a/ultralytics/data/utils.py b/ultralytics/data/utils.py index 5f9e26a84c..e968ae12bd 100644 --- a/ultralytics/data/utils.py +++ b/ultralytics/data/utils.py @@ -61,8 +61,7 @@ def exif_size(img: Image.Image): s = img.size # (width, height) if img.format == "JPEG": # only support JPEG images try: - exif = img.getexif() - if exif: + if exif := img.getexif(): rotation = exif.get(274, None) # the EXIF key for the orientation tag is 274 if rotation in {6, 8}: # rotation 270 or 90 s = s[1], s[0] @@ -126,8 +125,7 @@ def verify_image_label(args): segments = [np.array(x[1:], dtype=np.float32).reshape(-1, 2) for x in lb] # (cls, xy1...) lb = np.concatenate((classes.reshape(-1, 1), segments2boxes(segments)), 1) # (cls, xywh) lb = np.array(lb, dtype=np.float32) - nl = len(lb) - if nl: + if nl := len(lb): if keypoint: assert lb.shape[1] == (5 + nkpt * ndim), f"labels require {(5 + nkpt * ndim)} columns each" points = lb[:, 5:].reshape(-1, ndim)[:, :2] diff --git a/ultralytics/engine/results.py b/ultralytics/engine/results.py index 8de0a2e6a1..eefd29f5f0 100644 --- a/ultralytics/engine/results.py +++ b/ultralytics/engine/results.py @@ -652,12 +652,11 @@ class Results(SimpleClass): """ log_string = "" probs = self.probs - boxes = self.boxes if len(self) == 0: return log_string if probs is not None else f"{log_string}(no detections), " if probs is not None: log_string += f"{', '.join(f'{self.names[j]} {probs.data[j]:.2f}' for j in probs.top5)}, " - if boxes: + if boxes := self.boxes: for c in boxes.cls.unique(): n = (boxes.cls == c).sum() # detections per class log_string += f"{n} {self.names[int(c)]}{'s' * (n > 1)}, " diff --git a/ultralytics/models/sam/predict.py b/ultralytics/models/sam/predict.py index b74704c59e..0a2776f339 100644 --- a/ultralytics/models/sam/predict.py +++ b/ultralytics/models/sam/predict.py @@ -73,8 +73,8 @@ class Predictor(BasePredictor): >>> predictor = Predictor() >>> predictor.setup_model(model_path="sam_model.pt") >>> predictor.set_image("image.jpg") - >>> masks, scores, boxes = predictor.generate() - >>> results = predictor.postprocess((masks, scores, boxes), im, orig_img) + >>> bboxes = [[100, 100, 200, 200]] + >>> results = predictor(bboxes=bboxes) """ def __init__(self, cfg=DEFAULT_CFG, overrides=None, _callbacks=None): @@ -191,7 +191,7 @@ class Predictor(BasePredictor): >>> predictor = Predictor() >>> predictor.setup_model(model_path="sam_model.pt") >>> predictor.set_image("image.jpg") - >>> masks, scores, logits = predictor.inference(im, bboxes=[[0, 0, 100, 100]]) + >>> results = predictor(bboxes=[[0, 0, 100, 100]]) """ # Override prompts if any stored in self.prompts bboxes = self.prompts.pop("bboxes", bboxes) @@ -646,8 +646,8 @@ class SAM2Predictor(Predictor): >>> predictor = SAM2Predictor(cfg) >>> predictor.set_image("path/to/image.jpg") >>> bboxes = [[100, 100, 200, 200]] - >>> masks, scores, _ = predictor.prompt_inference(predictor.im, bboxes=bboxes) - >>> print(f"Predicted {len(masks)} masks with average score {scores.mean():.2f}") + >>> result = predictor(bboxes=bboxes)[0] + >>> print(f"Predicted {len(result.masks)} masks with average score {result.boxes.conf.mean():.2f}") """ _bb_feat_sizes = [ @@ -694,8 +694,8 @@ class SAM2Predictor(Predictor): >>> predictor = SAM2Predictor(cfg) >>> image = torch.rand(1, 3, 640, 640) >>> bboxes = [[100, 100, 200, 200]] - >>> masks, scores, logits = predictor.prompt_inference(image, bboxes=bboxes) - >>> print(f"Generated {masks.shape[0]} masks with average score {scores.mean():.2f}") + >>> result = predictor(image, bboxes=bboxes)[0] + >>> print(f"Generated {result.masks.shape[0]} masks with average score {result.boxes.conf.mean():.2f}") Notes: - The method supports batched inference for multiple objects when points or bboxes are provided. diff --git a/ultralytics/models/utils/loss.py b/ultralytics/models/utils/loss.py index a42b13413f..54aed90957 100644 --- a/ultralytics/models/utils/loss.py +++ b/ultralytics/models/utils/loss.py @@ -243,9 +243,10 @@ class DETRLoss(nn.Module): if len(gt_bboxes): gt_scores[idx] = bbox_iou(pred_bboxes.detach(), gt_bboxes, xywh=True).squeeze(-1) - loss = {} - loss.update(self._get_loss_class(pred_scores, targets, gt_scores, len(gt_bboxes), postfix)) - loss.update(self._get_loss_bbox(pred_bboxes, gt_bboxes, postfix)) + loss = { + **self._get_loss_class(pred_scores, targets, gt_scores, len(gt_bboxes), postfix), + **self._get_loss_bbox(pred_bboxes, gt_bboxes, postfix), + } # if masks is not None and gt_mask is not None: # loss.update(self._get_loss_mask(masks, gt_mask, match_indices, postfix)) return loss diff --git a/ultralytics/nn/autobackend.py b/ultralytics/nn/autobackend.py index 70962e8ed8..a89c8cfa2f 100644 --- a/ultralytics/nn/autobackend.py +++ b/ultralytics/nn/autobackend.py @@ -617,10 +617,9 @@ class AutoBackend(nn.Module): # box = xywh2xyxy(y['coordinates'] * [[w, h, w, h]]) # xyxy pixels # conf, cls = y['confidence'].max(1), y['confidence'].argmax(1).astype(np.float32) # y = np.concatenate((box, conf.reshape(-1, 1), cls.reshape(-1, 1)), 1) - elif len(y) == 1: # classification model - y = list(y.values()) - elif len(y) == 2: # segmentation model - y = list(reversed(y.values())) # reversed for segmentation models (pred, proto) + y = list(y.values()) + if len(y) == 2 and len(y[1].shape) != 4: # segmentation model + y = list(reversed(y)) # reversed for segmentation models (pred, proto) # PaddlePaddle elif self.paddle: diff --git a/ultralytics/solutions/streamlit_inference.py b/ultralytics/solutions/streamlit_inference.py index 31a88baec8..fe56a3a41f 100644 --- a/ultralytics/solutions/streamlit_inference.py +++ b/ultralytics/solutions/streamlit_inference.py @@ -62,8 +62,7 @@ class Inference: self.selected_ind = [] # List of selected classes for detection or tracking self.model = None # Container for the loaded model instance - self.temp_dict = {"model": None} # Temporary dict to store the model path - self.temp_dict.update(kwargs) + self.temp_dict = {"model": None, **kwargs} self.model_path = None # Store model file name with path if self.temp_dict["model"] is not None: self.model_path = self.temp_dict["model"] diff --git a/ultralytics/utils/callbacks/hub.py b/ultralytics/utils/callbacks/hub.py index b1fbea1847..aa2d158537 100644 --- a/ultralytics/utils/callbacks/hub.py +++ b/ultralytics/utils/callbacks/hub.py @@ -15,16 +15,14 @@ def on_pretrain_routine_start(trainer): def on_pretrain_routine_end(trainer): """Logs info before starting timer for upload rate limit.""" - session = getattr(trainer, "hub_session", None) - if session: + if session := getattr(trainer, "hub_session", None): # Start timer for upload rate limit session.timers = {"metrics": time(), "ckpt": time()} # start timer on session.rate_limit def on_fit_epoch_end(trainer): """Uploads training progress metrics at the end of each epoch.""" - session = getattr(trainer, "hub_session", None) - if session: + if session := getattr(trainer, "hub_session", None): # Upload metrics after val end all_plots = { **trainer.label_loss_items(trainer.tloss, prefix="train"), @@ -49,8 +47,7 @@ def on_fit_epoch_end(trainer): def on_model_save(trainer): """Saves checkpoints to Ultralytics HUB with rate limiting.""" - session = getattr(trainer, "hub_session", None) - if session: + if session := getattr(trainer, "hub_session", None): # Upload checkpoints with rate limiting is_best = trainer.best_fitness == trainer.fitness if time() - session.timers["ckpt"] > session.rate_limits["ckpt"]: @@ -61,8 +58,7 @@ def on_model_save(trainer): def on_train_end(trainer): """Upload final model and metrics to Ultralytics HUB at the end of training.""" - session = getattr(trainer, "hub_session", None) - if session: + if session := getattr(trainer, "hub_session", None): # Upload final model and metrics with exponential standoff LOGGER.info(f"{PREFIX}Syncing final model...") session.upload_model( diff --git a/ultralytics/utils/checks.py b/ultralytics/utils/checks.py index d9e42cf8be..335b53aea8 100644 --- a/ultralytics/utils/checks.py +++ b/ultralytics/utils/checks.py @@ -75,8 +75,7 @@ def parse_requirements(file_path=ROOT.parent / "requirements.txt", package=""): line = line.strip() if line and not line.startswith("#"): line = line.split("#")[0].strip() # ignore inline comments - match = re.match(r"([a-zA-Z0-9-_]+)\s*([<>!=~]+.*)?", line) - if match: + if match := re.match(r"([a-zA-Z0-9-_]+)\s*([<>!=~]+.*)?", line): requirements.append(SimpleNamespace(name=match[1], specifier=match[2].strip() if match[2] else "")) return requirements diff --git a/ultralytics/utils/downloads.py b/ultralytics/utils/downloads.py index 555fbaf5be..5d535b6f96 100644 --- a/ultralytics/utils/downloads.py +++ b/ultralytics/utils/downloads.py @@ -269,8 +269,7 @@ def get_google_drive_file_info(link): for k, v in response.cookies.items(): if k.startswith("download_warning"): drive_url += f"&confirm={v}" # v is token - cd = response.headers.get("content-disposition") - if cd: + if cd := response.headers.get("content-disposition"): filename = re.findall('filename="(.+)"', cd)[0] return drive_url, filename diff --git a/ultralytics/utils/loss.py b/ultralytics/utils/loss.py index c6557df4c0..857fccf4f8 100644 --- a/ultralytics/utils/loss.py +++ b/ultralytics/utils/loss.py @@ -189,8 +189,7 @@ class v8DetectionLoss: out = torch.zeros(batch_size, counts.max(), ne - 1, device=self.device) for j in range(batch_size): matches = i == j - n = matches.sum() - if n: + if n := matches.sum(): out[j, :n] = targets[matches, 1:] out[..., 1:5] = xywh2xyxy(out[..., 1:5].mul_(scale_tensor)) return out @@ -630,8 +629,7 @@ class v8OBBLoss(v8DetectionLoss): out = torch.zeros(batch_size, counts.max(), 6, device=self.device) for j in range(batch_size): matches = i == j - n = matches.sum() - if n: + if n := matches.sum(): bboxes = targets[matches, 2:] bboxes[..., :4].mul_(scale_tensor) out[j, :n] = torch.cat([targets[matches, 1:2], bboxes], dim=-1)