From 15c027a9fc04a4df109e51fe166833d1a4ebec96 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Sun, 25 Jun 2023 02:52:00 +0200 Subject: [PATCH] Add `torch.Tensor` checks and pip badges (#3368) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- README.md | 4 +++- README.zh-CN.md | 4 +++- docs/quickstart.md | 9 ++++++++ .../yolo/data/dataloaders/stream_loaders.py | 22 ++++++++++++++----- 4 files changed, 32 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index eaab62f..cac3064 100644 --- a/README.md +++ b/README.md @@ -59,11 +59,13 @@ See below for a quickstart installation and usage example, and see the [YOLOv8 D Pip install the ultralytics package including all [requirements](https://github.com/ultralytics/ultralytics/blob/main/requirements.txt) in a [**Python>=3.8**](https://www.python.org/) environment with [**PyTorch>=1.7**](https://pytorch.org/get-started/locally/). +[![PyPI version](https://badge.fury.io/py/ultralytics.svg)](https://badge.fury.io/py/ultralytics) [![Downloads](https://static.pepy.tech/badge/ultralytics)](https://pepy.tech/project/ultralytics) + ```bash pip install ultralytics ``` -For alternative installation methods including Conda, Docker, and Git, please refer to the [Ultralytics Quickstart Guide](https://docs.ultralytics.com/quickstart). +For alternative installation methods including Conda, Docker, and Git, please refer to the [Quickstart Guide](https://docs.ultralytics.com/quickstart). diff --git a/README.zh-CN.md b/README.zh-CN.md index b171f32..38e6b7a 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -59,11 +59,13 @@ 使用Pip在一个[**Python>=3.8**](https://www.python.org/)环境中安装`ultralytics`包,此环境还需包含[**PyTorch>=1.7**](https://pytorch.org/get-started/locally/)。这也会安装所有必要的[依赖项](https://github.com/ultralytics/ultralytics/blob/main/requirements.txt)。 +[![PyPI version](https://badge.fury.io/py/ultralytics.svg)](https://badge.fury.io/py/ultralytics) [![Downloads](https://static.pepy.tech/badge/ultralytics)](https://pepy.tech/project/ultralytics) + ```bash pip install ultralytics ``` -如需使用包括Conda、Docker和Git在内的其他安装方法,请参考[Ultralytics快速入门指南](https://docs.ultralytics.com/quickstart)。 +如需使用包括Conda、Docker和Git在内的其他安装方法,请参考[快速入门指南](https://docs.ultralytics.com/quickstart)。 diff --git a/docs/quickstart.md b/docs/quickstart.md index 6d0db2c..cd8d630 100644 --- a/docs/quickstart.md +++ b/docs/quickstart.md @@ -12,6 +12,9 @@ Ultralytics provides various installation methods including pip, conda, and Dock === "Pip install (recommended)" Install the `ultralytics` package using pip, or update an existing installation by running `pip install -U ultralytics`. Visit the Python Package Index (PyPI) for more details on the `ultralytics` package: [https://pypi.org/project/ultralytics/](https://pypi.org/project/ultralytics/). + + [![PyPI version](https://badge.fury.io/py/ultralytics.svg)](https://badge.fury.io/py/ultralytics) [![Downloads](https://static.pepy.tech/badge/ultralytics)](https://pepy.tech/project/ultralytics) + ```bash # Install the ultralytics package using pip pip install ultralytics @@ -19,6 +22,10 @@ Ultralytics provides various installation methods including pip, conda, and Dock === "Conda install" Conda is an alternative package manager to pip which may also be used for installation. Visit Anaconda for more details at [https://anaconda.org/conda-forge/ultralytics](https://anaconda.org/conda-forge/ultralytics). Ultralytics feedstock repository for updating the conda package is at [https://github.com/conda-forge/ultralytics-feedstock/](https://github.com/conda-forge/ultralytics-feedstock/). + + + [![Conda Recipe](https://img.shields.io/badge/recipe-ultralytics-green.svg)](https://anaconda.org/conda-forge/ultralytics) [![Conda Downloads](https://img.shields.io/conda/dn/conda-forge/ultralytics.svg)](https://anaconda.org/conda-forge/ultralytics) [![Conda Version](https://img.shields.io/conda/vn/conda-forge/ultralytics.svg)](https://anaconda.org/conda-forge/ultralytics) [![Conda Platforms](https://img.shields.io/conda/pn/conda-forge/ultralytics.svg)](https://anaconda.org/conda-forge/ultralytics) + ```bash # Install the ultralytics package using conda conda install ultralytics @@ -39,6 +46,8 @@ Ultralytics provides various installation methods including pip, conda, and Dock === "Docker" Utilize Docker to execute the `ultralytics` package in an isolated container. By employing the official `ultralytics` image from [Docker Hub](https://hub.docker.com/r/ultralytics/ultralytics), you can avoid local installation. Below are the commands to get the latest image and execute it: + + Docker Pulls ```bash # Set image name as a variable diff --git a/ultralytics/yolo/data/dataloaders/stream_loaders.py b/ultralytics/yolo/data/dataloaders/stream_loaders.py index 95b22bd..ae28fcb 100644 --- a/ultralytics/yolo/data/dataloaders/stream_loaders.py +++ b/ultralytics/yolo/data/dataloaders/stream_loaders.py @@ -301,11 +301,23 @@ class LoadTensor: self.paths = [getattr(im, 'filename', f'image{i}.jpg') for i, im in enumerate(im0)] @staticmethod - def _single_check(im): - """Validate and format an image to numpy array.""" - if len(im.shape) < 4: - LOGGER.warning('WARNING ⚠️ torch.Tensor inputs should be BCHW format, i.e. shape(1,3,640,640).') - im = im.unsqueeze(0) + def _single_check(im, stride=32): + """Validate and format an image to torch.Tensor.""" + s = f'WARNING ⚠️ torch.Tensor inputs should be BCHW i.e. shape(1, 3, 640, 640) ' \ + f'divisible by stride {stride}. Input shape{tuple(im.shape)} is incompatible.' + if len(im.shape) != 4: + if len(im.shape) == 3: + LOGGER.warning(s) + im = im.unsqueeze(0) + else: + raise ValueError(s) + if im.shape[2] % stride or im.shape[3] % stride: + raise ValueError(s) + if im.max() > 1.0: + LOGGER.warning(f'WARNING ⚠️ torch.Tensor inputs should be normalized 0.0-1.0 but max value is {im.max()}. ' + f'Dividing input by 255.') + im = im.float() / 255.0 + return im def __iter__(self):