Merge branch 'main' into afpn

afpn
Glenn Jocher 1 year ago committed by GitHub
commit 1022d63586
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      .github/workflows/ci.yaml
  2. 2
      .github/workflows/publish.yml
  3. 2
      docker/Dockerfile
  4. 2
      docker/Dockerfile-cpu
  5. 2
      docker/Dockerfile-python
  6. 2
      docs/README.md
  7. 2
      docs/integrations/ray-tune.md
  8. 5
      docs/reference/utils/__init__.md
  9. 2
      docs/yolov5/tutorials/neural_magic_pruning_quantization.md
  10. 2
      setup.py
  11. 2
      ultralytics/__init__.py
  12. 2
      ultralytics/engine/exporter.py
  13. 61
      ultralytics/utils/plotting.py
  14. 2
      ultralytics/utils/tuner.py

@ -107,9 +107,9 @@ jobs:
run: |
python -m pip install --upgrade pip wheel
if [ "${{ matrix.os }}" == "macos-latest" ]; then
pip install -e '.[export]' --extra-index-url https://download.pytorch.org/whl/cpu
pip install -e ".[export]" --extra-index-url https://download.pytorch.org/whl/cpu
else
pip install -e '.[export]' --extra-index-url https://download.pytorch.org/whl/cpu
pip install -e ".[export]" --extra-index-url https://download.pytorch.org/whl/cpu
fi
yolo export format=tflite imgsz=32
- name: Check environment
@ -165,9 +165,9 @@ jobs:
run: | # CoreML must be installed before export due to protobuf error from AutoInstall
python -m pip install --upgrade pip wheel
if [ "${{ matrix.torch }}" == "1.8.0" ]; then
pip install -e . torch==1.8.0 torchvision==0.9.0 pytest 'coremltools>=6.0,<=6.2' --extra-index-url https://download.pytorch.org/whl/cpu
pip install -e . torch==1.8.0 torchvision==0.9.0 pytest "coremltools>=6.0,<=6.2" --extra-index-url https://download.pytorch.org/whl/cpu
else
pip install -e . pytest 'coremltools>=6.0,<=6.2' --extra-index-url https://download.pytorch.org/whl/cpu
pip install -e . pytest "coremltools>=6.0,<=6.2" --extra-index-url https://download.pytorch.org/whl/cpu
fi
- name: Check environment
run: |

@ -33,7 +33,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip wheel build twine
pip install -e '.[dev]' --extra-index-url https://download.pytorch.org/whl/cpu
pip install -e ".[dev]" --extra-index-url https://download.pytorch.org/whl/cpu
- name: Check PyPI version
shell: python
run: |

@ -30,7 +30,7 @@ ADD https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov8n.pt /u
# Install pip packages
RUN python3 -m pip install --upgrade pip wheel
RUN pip install --no-cache -e '.[export]' thop albumentations comet pycocotools
RUN pip install --no-cache -e ".[export]" thop albumentations comet pycocotools
# Run exports to AutoInstall packages
RUN yolo export model=tmp/yolov8n.pt format=edgetpu imgsz=32

@ -28,7 +28,7 @@ RUN rm -rf /usr/lib/python3.11/EXTERNALLY-MANAGED
# Install pip packages
RUN python3 -m pip install --upgrade pip wheel
RUN pip install --no-cache -e '.[export]' thop --extra-index-url https://download.pytorch.org/whl/cpu
RUN pip install --no-cache -e ".[export]" thop --extra-index-url https://download.pytorch.org/whl/cpu
# Run exports to AutoInstall packages
RUN yolo export model=tmp/yolov8n.pt format=edgetpu imgsz=32

@ -28,7 +28,7 @@ ADD https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov8n.pt /u
# Install pip packages
RUN python3 -m pip install --upgrade pip wheel
RUN pip install --no-cache -e '.[export]' thop --extra-index-url https://download.pytorch.org/whl/cpu
RUN pip install --no-cache -e ".[export]" thop --extra-index-url https://download.pytorch.org/whl/cpu
# Run exports to AutoInstall packages
RUN yolo export model=tmp/yolov8n.pt format=edgetpu imgsz=32

@ -27,7 +27,7 @@ cd ultralytics
3. Install the package in developer mode using pip:
```bash
pip install -e '.[dev]'
pip install -e ".[dev]"
```
This will install the ultralytics package and its dependencies in developer mode, allowing you to make changes to the

@ -30,7 +30,7 @@ To install the required packages, run:
```bash
# Install and update Ultralytics and Ray Tune packages
pip install -U ultralytics 'ray[tune]'
pip install -U ultralytics "ray[tune]"
# Optionally install W&B for logging
pip install wandb

@ -153,11 +153,6 @@ keywords: Ultralytics, Utils, utilitarian functions, colorstr, yaml_save, set_lo
### ::: ultralytics.utils.set_sentry
<br><br>
## update_dict_recursive
---
### ::: ultralytics.utils.update_dict_recursive
<br><br>
## deprecation_warn
---
### ::: ultralytics.utils.deprecation_warn

@ -67,7 +67,7 @@ We will walk through an example benchmarking and deploying a sparse version of Y
Run the following to install DeepSparse. We recommend you use a virtual environment with Python.
```bash
pip install deepsparse[server,yolo,onnxruntime]
pip install "deepsparse[server,yolo,onnxruntime]"
```
### Collect an ONNX File

@ -46,7 +46,7 @@ setup(
'mkdocs-material',
'mkdocstrings[python]',
'mkdocs-redirects', # for 301 redirects
'mkdocs-ultralytics-plugin>=0.0.22', # for meta descriptions and images, dates and authors
'mkdocs-ultralytics-plugin>=0.0.24', # for meta descriptions and images, dates and authors
],
'export': [
'coremltools>=6.0,<=6.2',

@ -1,6 +1,6 @@
# Ultralytics YOLO 🚀, AGPL-3.0 license
__version__ = '8.0.146'
__version__ = '8.0.147'
from ultralytics.hub import start
from ultralytics.models import RTDETR, SAM, YOLO

@ -19,7 +19,7 @@ PaddlePaddle | `paddle` | yolov8n_paddle_model/
ncnn | `ncnn` | yolov8n_ncnn_model/
Requirements:
$ pip install ultralytics[export]
$ pip install "ultralytics[export]"
Python:
from ultralytics import YOLO

@ -21,7 +21,16 @@ from .ops import clip_boxes, scale_image, xywh2xyxy, xyxy2xywh
class Colors:
"""Ultralytics color palette https://ultralytics.com/."""
"""Ultralytics default color palette https://ultralytics.com/.
This class provides methods to work with the Ultralytics color palette, including converting hex color codes to
RGB values.
Attributes:
palette (list of tuple): List of RGB color values.
n (int): The number of colors in the palette.
pose_palette (np.array): A specific color palette array with dtype np.uint8.
"""
def __init__(self):
"""Initialize colors as hex = matplotlib.colors.TABLEAU_COLORS.values()."""
@ -36,12 +45,13 @@ class Colors:
dtype=np.uint8)
def __call__(self, i, bgr=False):
"""Converts hex color codes to rgb values."""
"""Converts hex color codes to RGB values."""
c = self.palette[int(i) % self.n]
return (c[2], c[1], c[0]) if bgr else c
@staticmethod
def hex2rgb(h): # rgb order (PIL)
def hex2rgb(h):
"""Converts hex color codes to RGB values (i.e. default PIL order)."""
return tuple(int(h[1 + i:1 + i + 2], 16) for i in (0, 2, 4))
@ -49,7 +59,17 @@ colors = Colors() # create instance for 'from utils.plots import colors'
class Annotator:
"""YOLOv8 Annotator for train/val mosaics and jpgs and detect/hub inference annotations."""
"""Ultralytics Annotator for train/val mosaics and JPGs and predictions annotations.
Attributes:
im (Image.Image or numpy array): The image to annotate.
pil (bool): Whether to use PIL or cv2 for drawing annotations.
font (ImageFont.truetype or ImageFont.load_default): Font used for text annotations.
lw (float): Line width for drawing.
skeleton (List[List[int]]): Skeleton structure for keypoints.
limb_color (List[int]): Color palette for limbs.
kpt_color (List[int]): Color palette for keypoints.
"""
def __init__(self, im, line_width=None, font_size=None, font='Arial.ttf', pil=False, example='abc'):
"""Initialize the Annotator class with image and line width along with color palette for keypoints and limbs."""
@ -113,6 +133,7 @@ class Annotator:
def masks(self, masks, colors, im_gpu, alpha=0.5, retina_masks=False):
"""Plot masks at once.
Args:
masks (tensor): predicted masks on cuda, shape: [n, h, w]
colors (List[List[Int]]): colors for predicted masks, [[r, g, b] * n]
@ -292,7 +313,37 @@ def plot_labels(boxes, cls, names=(), save_dir=Path(''), on_plot=None):
def save_one_box(xyxy, im, file=Path('im.jpg'), gain=1.02, pad=10, square=False, BGR=False, save=True):
"""Save image crop as {file} with crop size multiple {gain} and {pad} pixels. Save and/or return crop."""
"""Save image crop as {file} with crop size multiple {gain} and {pad} pixels. Save and/or return crop.
This function takes a bounding box and an image, and then saves a cropped portion of the image according
to the bounding box. Optionally, the crop can be squared, and the function allows for gain and padding
adjustments to the bounding box.
Args:
xyxy (torch.Tensor or list): A tensor or list representing the bounding box in xyxy format.
im (numpy.ndarray): The input image.
file (Path, optional): The path where the cropped image will be saved. Defaults to 'im.jpg'.
gain (float, optional): A multiplicative factor to increase the size of the bounding box. Defaults to 1.02.
pad (int, optional): The number of pixels to add to the width and height of the bounding box. Defaults to 10.
square (bool, optional): If True, the bounding box will be transformed into a square. Defaults to False.
BGR (bool, optional): If True, the image will be saved in BGR format, otherwise in RGB. Defaults to False.
save (bool, optional): If True, the cropped image will be saved to disk. Defaults to True.
Returns:
(numpy.ndarray): The cropped image.
Examples:
```python
from ultralytics.utils.plotting import save_one_box
xyxy = [50, 50, 150, 150]
im = cv2.imread('image.jpg')
cropped_im = save_one_box(xyxy, im, file='cropped.jpg', square=True)
```
"""
if not isinstance(xyxy, torch.Tensor): # may be list
xyxy = torch.stack(xyxy)
b = xyxy2xywh(xyxy.view(-1, 4)) # boxes
if square:
b[:, 2:] = b[:, 2:].max(1)[0].unsqueeze(1) # attempt rectangle to square

@ -35,7 +35,7 @@ def run_ray_tune(model,
from ray.air.integrations.wandb import WandbLoggerCallback
from ray.tune.schedulers import ASHAScheduler
except ImportError:
raise ModuleNotFoundError("Tuning hyperparameters requires Ray Tune. Install with: pip install 'ray[tune]'")
raise ModuleNotFoundError('Tuning hyperparameters requires Ray Tune. Install with: pip install "ray[tune]"')
try:
import wandb

Loading…
Cancel
Save