Merge branch 'main' into action-recog

action-recog
Ultralytics Assistant 7 months ago committed by GitHub
commit 7f933f94ea
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 49
      CONTRIBUTING.md
  2. 2
      docs/en/guides/ros-quickstart.md
  3. 14
      docs/en/help/contributing.md
  4. 3
      tests/test_cli.py
  5. 2
      ultralytics/__init__.py
  6. 25
      ultralytics/models/sam2/predict.py
  7. 4
      ultralytics/nn/modules/transformer.py
  8. 4
      ultralytics/utils/downloads.py
  9. 4
      ultralytics/utils/ops.py
  10. 6
      ultralytics/utils/plotting.py

@ -18,10 +18,11 @@ Thank you for your interest in contributing to Ultralytics open-source YOLO repo
3. [Reporting Bugs](#reporting-bugs)
4. [License](#license)
5. [Conclusion](#conclusion)
6. [FAQ](#faq)
## Code of Conduct
All contributors must adhere to the [Code of Conduct](code_of_conduct.md) to ensure a welcoming and inclusive environment for everyone.
All contributors must adhere to the [Code of Conduct](https://docs.ultralytics.com/help/code_of_conduct) to ensure a welcoming and inclusive environment for everyone.
## Contributing via Pull Requests
@ -41,7 +42,7 @@ We welcome contributions in the form of pull requests. To streamline the review
### CLA Signing
Before we can accept your pull request, you must sign a [Contributor License Agreement (CLA)](CLA.md). This legal document ensures that your contributions are properly licensed and that the project can continue to be distributed under the AGPL-3.0 license.
Before we can accept your pull request, you must sign a [Contributor License Agreement (CLA)](https://docs.ultralytics.com/help/CLA). This legal document ensures that your contributions are properly licensed and that the project can continue to be distributed under the AGPL-3.0 license.
To sign the CLA, follow the instructions provided by the CLA bot after you submit your PR and add a comment in your PR saying:
@ -55,13 +56,12 @@ When adding new functions or classes, include a [Google-style docstring](https:/
#### Google-style
This example shows a Google-style docstring. Note that both input and output `types` must always be enclosed by parentheses, i.e. `(bool)`.
This example shows a Google-style docstring. Note that both input and output `types` must always be enclosed by parentheses, i.e., `(bool)`.
```python
def example_function(arg1, arg2=4):
"""
This example shows a Google-style docstring. Note that both input and output `types` must always be enclosed by
parentheses, i.e., `(bool)`.
Example function that demonstrates Google-style docstrings.
Args:
arg1 (int): The first argument.
@ -80,13 +80,12 @@ def example_function(arg1, arg2=4):
#### Google-style with type hints
This example shows both a Google-style docstring and argument and return type hints, though both are not required, one can be used without the other.
This example shows both a Google-style docstring and argument and return type hints, though both are not required; one can be used without the other.
```python
def example_function(arg1: int, arg2: int = 4) -> bool:
"""
This example shows both a Google-style docstring and argument and return type hints, though both are not required;
one can be used without the other.
Example function that demonstrates Google-style docstrings.
Args:
arg1: The first argument.
@ -105,7 +104,7 @@ def example_function(arg1: int, arg2: int = 4) -> bool:
#### Single-line
Smaller or simpler functions can utilize a single-line docstring. Note the docstring must use 3 double-quotes, and be a complete sentence starting with a capital letter and ending with a period.
Smaller or simpler functions can utilize a single-line docstring. Note the docstring must use 3 double-quotes and be a complete sentence starting with a capital letter and ending with a period.
```python
def example_small_function(arg1: int, arg2: int = 4) -> bool:
@ -115,11 +114,11 @@ def example_small_function(arg1: int, arg2: int = 4) -> bool:
### GitHub Actions CI Tests
Before your pull request can be merged, all GitHub Actions [Continuous Integration](https://docs.ultralytics.com/help/CI/) (CI) tests must pass. These tests include linting, unit tests, and other checks to ensure that your changes meet the quality standards of the project. Make sure to review the output of the GitHub Actions and fix any issues
Before your pull request can be merged, all GitHub Actions [Continuous Integration](https://docs.ultralytics.com/help/CI) (CI) tests must pass. These tests include linting, unit tests, and other checks to ensure your changes meet the project's quality standards. Review the output of the GitHub Actions and fix any issues.
## Reporting Bugs
We appreciate bug reports as they play a crucial role in maintaining the project's quality. When reporting bugs it is important to provide a [Minimum Reproducible Example](https://docs.ultralytics.com/help/minimum_reproducible_example/): a clear, concise code example that replicates the issue. This helps in quick identification and resolution of the bug.
We appreciate bug reports as they play a crucial role in maintaining the project's quality. When reporting bugs, it is important to provide a [Minimum Reproducible Example](https://docs.ultralytics.com/help/minimum_reproducible_example): a clear, concise code example that replicates the issue. This helps in quick identification and resolution of the bug.
## License
@ -132,3 +131,31 @@ Users and developers are encouraged to familiarize themselves with the terms of
Thank you for your interest in contributing to [Ultralytics open-source](https://github.com/ultralytics) YOLO projects. Your participation is crucial in shaping the future of our software and fostering a community of innovation and collaboration. Whether you're improving code, reporting bugs, or suggesting features, your contributions make a significant impact.
We look forward to seeing your ideas in action and appreciate your commitment to advancing object detection technology. Let's continue to grow and innovate together in this exciting open-source journey. Happy coding! 🚀🌟
## FAQ
### Why should I contribute to Ultralytics YOLO open-source repositories?
Contributing to Ultralytics YOLO open-source repositories helps improve the software, making it more robust and feature-rich for the entire community. Contributions can include code enhancements, bug fixes, documentation improvements, and new feature implementations. Additionally, contributing offers the chance to collaborate with other skilled developers and experts in the field, boosting your own skills and reputation. For information on how to get started, refer to the [Contributing via Pull Requests](#contributing-via-pull-requests) section.
### How do I sign the Contributor License Agreement (CLA) for Ultralytics YOLO?
To sign the Contributor License Agreement (CLA), follow the instructions provided by the CLA bot after submitting your pull request. This will ensure your contributions are properly licensed under the AGPL-3.0 license, maintaining the legal integrity of the open-source project. Add a comment in your pull request mentioning:
```
I have read the CLA Document and I sign the CLA
```
For more information, see the [CLA Signing](#cla-signing) section.
### What are Google-style docstrings and why are they required for Ultralytics YOLO contributions?
Google-style docstrings provide clear and concise documentation for functions and classes, enhancing readability and maintainability of the code. These docstrings outline the function's purpose, arguments, and return values with specific formatting rules. When contributing to Ultralytics YOLO, adhering to Google-style docstrings ensures that your additions are comprehensible and well-documented. For examples and guidelines, visit the [Google-Style Docstrings](#google-style-docstrings) section.
### How can I ensure my changes pass the GitHub Actions CI tests?
Before your pull request is merged, it must pass all GitHub Actions Continuous Integration (CI) tests. These tests include linting, unit tests, and other checks to ensure the code meets the project's quality standards. Review the output of the GitHub Actions and address any issues. For detailed information on the CI process and troubleshooting tips, see the [GitHub Actions CI Tests](#github-actions-ci-tests) section.
### How do I report a bug in Ultralytics YOLO repositories?
To report a bug, provide a clear and concise [Minimum Reproducible Example](https://docs.ultralytics.com/help/minimum_reproducible_example) along with your bug report. This helps developers quickly identify and fix the issue. Ensure your example is minimal yet sufficient to replicate the problem. For more detailed steps on reporting bugs, refer to the [Reporting Bugs](#reporting-bugs) section.

@ -1,6 +1,6 @@
---
comments: true
description: todo
description: Learn to integrate Ultralytics YOLO with your robot running ROS Noetic, utilizing RGB images, depth images, and point clouds for efficient object detection, segmentation, and enhanced robotic perception.
keywords: Ultralytics, YOLO, object detection, deep learning, machine learning, guide, ROS, Robot Operating System, robotics, ROS Noetic, Python, Ubuntu, simulation, visualization, communication, middleware, hardware abstraction, tools, utilities, ecosystem, Noetic Ninjemys, autonomous vehicle, AMV
---

@ -18,10 +18,11 @@ Thank you for your interest in contributing to Ultralytics open-source YOLO repo
3. [Reporting Bugs](#reporting-bugs)
4. [License](#license)
5. [Conclusion](#conclusion)
6. [FAQ](#faq)
## Code of Conduct
All contributors must adhere to the [Code of Conduct](code_of_conduct.md) to ensure a welcoming and inclusive environment for everyone.
All contributors must adhere to the [Code of Conduct](https://docs.ultralytics.com/help/code_of_conduct) to ensure a welcoming and inclusive environment for everyone.
## Contributing via Pull Requests
@ -41,7 +42,7 @@ We welcome contributions in the form of pull requests. To streamline the review
### CLA Signing
Before we can accept your pull request, you must sign a [Contributor License Agreement (CLA)](CLA.md). This legal document ensures that your contributions are properly licensed and that the project can continue to be distributed under the AGPL-3.0 license.
Before we can accept your pull request, you must sign a [Contributor License Agreement (CLA)](https://docs.ultralytics.com/help/CLA). This legal document ensures that your contributions are properly licensed and that the project can continue to be distributed under the AGPL-3.0 license.
To sign the CLA, follow the instructions provided by the CLA bot after you submit your PR and add a comment in your PR saying:
@ -58,6 +59,7 @@ When adding new functions or classes, include a [Google-style docstring](https:/
=== "Google-style"
This example shows a Google-style docstring. Note that both input and output `types` must always be enclosed by parentheses, i.e., `(bool)`.
```python
def example_function(arg1, arg2=4):
"""
@ -81,6 +83,7 @@ When adding new functions or classes, include a [Google-style docstring](https:/
=== "Google-style with type hints"
This example shows both a Google-style docstring and argument and return type hints, though both are not required; one can be used without the other.
```python
def example_function(arg1: int, arg2: int = 4) -> bool:
"""
@ -104,6 +107,7 @@ When adding new functions or classes, include a [Google-style docstring](https:/
=== "Single-line"
Smaller or simpler functions can utilize a single-line docstring. Note the docstring must use 3 double-quotes and be a complete sentence starting with a capital letter and ending with a period.
```python
def example_small_function(arg1: int, arg2: int = 4) -> bool:
"""Example function that demonstrates a single-line docstring."""
@ -112,11 +116,11 @@ When adding new functions or classes, include a [Google-style docstring](https:/
### GitHub Actions CI Tests
Before your pull request can be merged, all GitHub Actions [Continuous Integration](CI.md) (CI) tests must pass. These tests include linting, unit tests, and other checks to ensure your changes meet the project's quality standards. Review the output of the GitHub Actions and fix any issues.
Before your pull request can be merged, all GitHub Actions [Continuous Integration](https://docs.ultralytics.com/help/CI) (CI) tests must pass. These tests include linting, unit tests, and other checks to ensure your changes meet the project's quality standards. Review the output of the GitHub Actions and fix any issues.
## Reporting Bugs
We appreciate bug reports as they play a crucial role in maintaining the project's quality. When reporting bugs, it is important to provide a [Minimum Reproducible Example](minimum_reproducible_example.md): a clear, concise code example that replicates the issue. This helps in quick identification and resolution of the bug.
We appreciate bug reports as they play a crucial role in maintaining the project's quality. When reporting bugs, it is important to provide a [Minimum Reproducible Example](https://docs.ultralytics.com/help/minimum_reproducible_example): a clear, concise code example that replicates the issue. This helps in quick identification and resolution of the bug.
## License
@ -156,4 +160,4 @@ Before your pull request is merged, it must pass all GitHub Actions Continuous I
### How do I report a bug in Ultralytics YOLO repositories?
To report a bug, provide a clear and concise [Minimum Reproducible Example](../help/minimum_reproducible_example.md) along with your bug report. This helps developers quickly identify and fix the issue. Ensure your example is minimal yet sufficient to replicate the problem. For more detailed steps on reporting bugs, refer to the [Reporting Bugs](#reporting-bugs) section.
To report a bug, provide a clear and concise [Minimum Reproducible Example](https://docs.ultralytics.com/help/minimum_reproducible_example) along with your bug report. This helps developers quickly identify and fix the issue. Ensure your example is minimal yet sufficient to replicate the problem. For more detailed steps on reporting bugs, refer to the [Reporting Bugs](#reporting-bugs) section.

@ -8,6 +8,7 @@ from PIL import Image
from tests import CUDA_DEVICE_COUNT, CUDA_IS_AVAILABLE
from ultralytics.cfg import TASK2DATA, TASK2MODEL, TASKS
from ultralytics.utils import ASSETS, WEIGHTS_DIR, checks
from ultralytics.utils.torch_utils import TORCH_1_9
# Constants
TASK_MODEL_DATA = [(task, WEIGHTS_DIR / TASK2MODEL[task], TASK2DATA[task]) for task in TASKS]
@ -57,6 +58,8 @@ def test_rtdetr(task="detect", model="yolov8n-rtdetr.yaml", data="coco8.yaml"):
# Warning: must use imgsz=640 (note also add coma, spaces, fraction=0.25 args to test single-image training)
run(f"yolo train {task} model={model} data={data} --imgsz= 160 epochs =1, cache = disk fraction=0.25")
run(f"yolo predict {task} model={model} source={ASSETS / 'bus.jpg'} imgsz=160 save save_crop save_txt")
if TORCH_1_9:
run(f"yolo predict {task} model='rtdetr-l.pt' source={ASSETS / 'bus.jpg'} imgsz=160 save save_crop save_txt")
@pytest.mark.skipif(checks.IS_PYTHON_3_12, reason="MobileSAM with CLIP is not supported in Python 3.12")

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

@ -102,28 +102,23 @@ class SAM2Predictor(Predictor):
if bboxes is not None:
bboxes = torch.as_tensor(bboxes, dtype=torch.float32, device=self.device)
bboxes = bboxes[None] if bboxes.ndim == 1 else bboxes
bboxes *= r
bboxes = bboxes.view(-1, 2, 2) * r
bbox_labels = torch.tensor([[2, 3]], dtype=torch.int32, device=bboxes.device).expand(len(bboxes), -1)
# NOTE: merge "boxes" and "points" into a single "points" input
# (where boxes are added at the beginning) to model.sam_prompt_encoder
if points is not None:
points = torch.cat([bboxes, points], dim=1)
labels = torch.cat([bbox_labels, labels], dim=1)
else:
points, labels = bboxes, bbox_labels
if masks is not None:
masks = torch.as_tensor(masks, dtype=torch.float32, device=self.device).unsqueeze(1)
points = (points, labels) if points is not None else None
# TODO: Embed prompts
# if bboxes is not None:
# box_coords = bboxes.reshape(-1, 2, 2)
# box_labels = torch.tensor([[2, 3]], dtype=torch.int, device=bboxes.device)
# box_labels = box_labels.repeat(bboxes.size(0), 1)
# # we merge "boxes" and "points" into a single "concat_points" input (where
# # boxes are added at the beginning) to sam_prompt_encoder
# if concat_points is not None:
# concat_coords = torch.cat([box_coords, concat_points[0]], dim=1)
# concat_labels = torch.cat([box_labels, concat_points[1]], dim=1)
# concat_points = (concat_coords, concat_labels)
# else:
# concat_points = (box_coords, box_labels)
sparse_embeddings, dense_embeddings = self.model.sam_prompt_encoder(
points=points,
boxes=bboxes,
boxes=None,
masks=masks,
)
# Predict masks

@ -186,8 +186,8 @@ class MLP(nn.Module):
def forward(self, x):
"""Forward pass for the entire MLP."""
for i, layer in enumerate(self.layers):
x = self.act(layer(x)) if i < self.num_layers - 1 else layer(x)
return x.sigmoid() if self.sigmoid else x
x = getattr(self, "act", nn.ReLU())(layer(x)) if i < self.num_layers - 1 else layer(x)
return x.sigmoid() if getattr(self, "sigmoid", False) else x
class LayerNorm2d(nn.Module):

@ -41,7 +41,7 @@ def is_url(url, check=False):
Args:
url (str): The string to be validated as a URL.
check (bool, optional): If True, performs an additional check to see if the URL exists online.
Defaults to True.
Defaults to False.
Returns:
(bool): Returns True for a valid URL. If 'check' is True, also returns True if the URL exists online.
@ -201,7 +201,7 @@ def check_disk_space(url="https://ultralytics.com/assets/coco8.zip", path=Path.c
Args:
url (str, optional): The URL to the file. Defaults to 'https://ultralytics.com/assets/coco8.zip'.
path (str | Path, optional): The path or drive to check the available free space on.
sf (float, optional): Safety factor, the multiplier for the required free space. Defaults to 2.0.
sf (float, optional): Safety factor, the multiplier for the required free space. Defaults to 1.5.
hard (bool, optional): Whether to throw an error or not on insufficient disk space. Defaults to True.
Returns:

@ -528,7 +528,7 @@ def ltwh2xywh(x):
def xyxyxyxy2xywhr(x):
"""
Convert batched Oriented Bounding Boxes (OBB) from [xy1, xy2, xy3, xy4] to [xywh, rotation]. Rotation values are
expected in degrees from 0 to 90.
returned in radians from 0 to pi/2.
Args:
x (numpy.ndarray | torch.Tensor): Input box corners [xy1, xy2, xy3, xy4] of shape (n, 8).
@ -551,7 +551,7 @@ def xyxyxyxy2xywhr(x):
def xywhr2xyxyxyxy(x):
"""
Convert batched Oriented Bounding Boxes (OBB) from [xywh, rotation] to [xy1, xy2, xy3, xy4]. Rotation values should
be in degrees from 0 to 90.
be in radians from 0 to pi/2.
Args:
x (numpy.ndarray | torch.Tensor): Boxes in [cx, cy, w, h, rotation] format of shape (n, 5) or (b, n, 5).

@ -195,12 +195,12 @@ class Annotator:
def circle_label(self, box, label="", color=(128, 128, 128), txt_color=(255, 255, 255), margin=2):
"""
Draws a label with a background rectangle centered within a given bounding box.
Draws a label with a background circle centered within a given bounding box.
Args:
box (tuple): The bounding box coordinates (x1, y1, x2, y2).
label (str): The text label to be displayed.
color (tuple, optional): The background color of the rectangle (R, G, B).
color (tuple, optional): The background color of the rectangle (B, G, R).
txt_color (tuple, optional): The color of the text (R, G, B).
margin (int, optional): The margin between the text and the rectangle border.
"""
@ -242,7 +242,7 @@ class Annotator:
Args:
box (tuple): The bounding box coordinates (x1, y1, x2, y2).
label (str): The text label to be displayed.
color (tuple, optional): The background color of the rectangle (R, G, B).
color (tuple, optional): The background color of the rectangle (B, G, R).
txt_color (tuple, optional): The color of the text (R, G, B).
margin (int, optional): The margin between the text and the rectangle border.
"""

Loading…
Cancel
Save