+ + +
+ +[English](README.md) | [简体中文](README.zh-CN.md) ++ + +
+ +[English](README.md) | [简体中文](README.zh-CN.md) ++ +
+ +## Quickstart from Terminal + +Start your compute and open a Terminal: + ++ +
+ +### Create virtualenv + +Create your conda virtualenv and install pip in it: + +```bash +conda create --name yolov8env -y +conda activate yolov8env +conda install pip -y +``` + +Install the required dependencies: + +```bash +cd ultralytics +pip install -r requirements.txt +pip install ultralytics +pip install onnx>=1.12.0 +``` + +### Perform YOLOv8 tasks + +Predict: + +```bash +yolo predict model=yolov8n.pt source='https://ultralytics.com/images/bus.jpg' +``` + +Train a detection model for 10 epochs with an initial learning_rate of 0.01: + +```bash +yolo train data=coco128.yaml model=yolov8n.pt epochs=10 lr0=0.01 +``` + +You can find more [instructions to use the Ultralytics CLI here](https://docs.ultralytics.com/quickstart/#use-ultralytics-with-cli). + +## Quickstart from a Notebook + +### Create a new IPython kernel + +Open the compute Terminal. + ++ +
+ +From your compute terminal, you need to create a new ipykernel that will be used by your notebook to manage your dependencies: + +```bash +conda create --name yolov8env -y +conda activate yolov8env +conda install pip -y +conda install ipykernel -y +python -m ipykernel install --user --name yolov8env --display-name "yolov8env" +``` + +Close your terminal and create a new notebook. From your Notebook, you can select the new kernel. + +Then you can open a Notebook cell and install the required dependencies: + +```bash +%%bash +source activate yolov8env +cd ultralytics +pip install -r requirements.txt +pip install ultralytics +pip install onnx>=1.12.0 +``` + +Note that we need to use the `source activate yolov8env` for all the %%bash cells, to make sure that the %%bash cell uses environment we want. + +Run some predictions using the [Ultralytics CLI](https://docs.ultralytics.com/quickstart/#use-ultralytics-with-cli): + +```bash +%%bash +source activate yolov8env +yolo predict model=yolov8n.pt source='https://ultralytics.com/images/bus.jpg' +``` + +Or with the [Ultralytics Python interface](https://docs.ultralytics.com/quickstart/#use-ultralytics-with-python), for example to train the model: + +```python +from ultralytics import YOLO + +# Load a model +model = YOLO("yolov8n.pt") # load an official YOLOv8n model + +# Use the model +model.train(data="coco128.yaml", epochs=3) # train the model +metrics = model.val() # evaluate model performance on the validation set +results = model("https://ultralytics.com/images/bus.jpg") # predict on an image +path = model.export(format="onnx") # export the model to ONNX format +``` + +You can use either the Ultralytics CLI or Python interface for running YOLOv8 tasks, as described in the terminal section above. + +By following these steps, you should be able to get YOLOv8 running quickly on AzureML for quick trials. For more advanced uses, you may refer to the full AzureML documentation linked at the beginning of this guide. + +## Explore More with AzureML + +This guide serves as an introduction to get you up and running with YOLOv8 on AzureML. However, it only scratches the surface of what AzureML can offer. To delve deeper and unlock the full potential of AzureML for your machine learning projects, consider exploring the following resources: + +- [Create a Data Asset](https://learn.microsoft.com/azure/machine-learning/how-to-create-data-assets): Learn how to set up and manage your data assets effectively within the AzureML environment. +- [Initiate an AzureML Job](https://learn.microsoft.com/azure/machine-learning/how-to-train-model): Get a comprehensive understanding of how to kickstart your machine learning training jobs on AzureML. +- [Register a Model](https://learn.microsoft.com/azure/machine-learning/how-to-manage-models): Familiarize yourself with model management practices including registration, versioning, and deployment. +- [Train YOLOv8 with AzureML Python SDK](https://medium.com/@ouphi/how-to-train-the-yolov8-model-with-azure-machine-learning-python-sdk-8268696be8ba): Explore a step-by-step guide on using the AzureML Python SDK to train your YOLOv8 models. +- [Train YOLOv8 with AzureML CLI](https://medium.com/@ouphi/how-to-train-the-yolov8-model-with-azureml-and-the-az-cli-73d3c870ba8e): Discover how to utilize the command-line interface for streamlined training and management of YOLOv8 models on AzureML. diff --git a/ultralytics/docs/guides/conda-quickstart.md b/ultralytics/docs/guides/conda-quickstart.md new file mode 100644 index 0000000000000000000000000000000000000000..ca67d9d9926b630d4e0df1bde33c937faeaaac29 --- /dev/null +++ b/ultralytics/docs/guides/conda-quickstart.md @@ -0,0 +1,132 @@ +--- +comments: true +description: Comprehensive guide to setting up and using Ultralytics YOLO models in a Conda environment. Learn how to install the package, manage dependencies, and get started with object detection projects. +keywords: Ultralytics, YOLO, Conda, environment setup, object detection, package installation, deep learning, machine learning, guide +--- + +# Conda Quickstart Guide for Ultralytics + ++ +
+ +This guide provides a comprehensive introduction to setting up a Conda environment for your Ultralytics projects. Conda is an open-source package and environment management system that offers an excellent alternative to pip for installing packages and dependencies. Its isolated environments make it particularly well-suited for data science and machine learning endeavors. For more details, visit the Ultralytics Conda package on [Anaconda](https://anaconda.org/conda-forge/ultralytics) and check out the Ultralytics feedstock repository for package updates on [GitHub](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) + +## What You Will Learn + +- Setting up a Conda environment +- Installing Ultralytics via Conda +- Initializing Ultralytics in your environment +- Using Ultralytics Docker images with Conda + +--- + +## Prerequisites + +- You should have Anaconda or Miniconda installed on your system. If not, download and install it from [Anaconda](https://www.anaconda.com/) or [Miniconda](https://docs.conda.io/projects/miniconda/en/latest/). + +--- + +## Setting up a Conda Environment + +First, let's create a new Conda environment. Open your terminal and run the following command: + +```bash +conda create --name ultralytics-env python=3.8 -y +``` + +Activate the new environment: + +```bash +conda activate ultralytics-env +``` + +--- + +## Installing Ultralytics + +You can install the Ultralytics package from the conda-forge channel. Execute the following command: + +```bash +conda install -c conda-forge ultralytics +``` + +### Note on CUDA Environment + +If you're working in a CUDA-enabled environment, it's a good practice to install `ultralytics`, `pytorch`, and `pytorch-cuda` together to resolve any conflicts: + +```bash +conda install -c pytorch -c nvidia -c conda-forge pytorch torchvision pytorch-cuda=11.8 ultralytics +``` + +--- + +## Using Ultralytics + +With Ultralytics installed, you can now start using its robust features for object detection, instance segmentation, and more. For example, to predict an image, you can run: + +```python +from ultralytics import YOLO + +model = YOLO('yolov8n.pt') # initialize model +results = model('path/to/image.jpg') # perform inference +results.show() # display results +``` + +--- + +## Ultralytics Conda Docker Image + +If you prefer using Docker, Ultralytics offers Docker images with a Conda environment included. You can pull these images from [DockerHub](https://hub.docker.com/r/ultralytics/ultralytics). + +Pull the latest Ultralytics image: + +```bash +# Set image name as a variable +t=ultralytics/ultralytics:latest-conda + +# Pull the latest Ultralytics image from Docker Hub +sudo docker pull $t +``` + +Run the image: + +```bash +# Run the Ultralytics image in a container with GPU support +sudo docker run -it --ipc=host --gpus all $t # all GPUs +sudo docker run -it --ipc=host --gpus '"device=2,3"' $t # specify GPUs +``` + +--- + +Certainly, you can include the following section in your Conda guide to inform users about speeding up installation using `libmamba`: + +--- + +## Speeding Up Installation with Libmamba + +If you're looking to [speed up the package installation](https://www.anaconda.com/blog/a-faster-conda-for-a-growing-community) process in Conda, you can opt to use `libmamba`, a fast, cross-platform, and dependency-aware package manager that serves as an alternative solver to Conda's default. + +### How to Enable Libmamba + +To enable `libmamba` as the solver for Conda, you can perform the following steps: + +1. First, install the `conda-libmamba-solver` package. This can be skipped if your Conda version is 4.11 or above, as `libmamba` is included by default. + + ```bash + conda install conda-libmamba-solver + ``` + +2. Next, configure Conda to use `libmamba` as the solver: + + ```bash + conda config --set solver libmamba + ``` + +And that's it! Your Conda installation will now use `libmamba` as the solver, which should result in a faster package installation process. + +--- + +Congratulations! You have successfully set up a Conda environment, installed the Ultralytics package, and are now ready to explore its rich functionalities. Feel free to dive deeper into the [Ultralytics documentation](https://docs.ultralytics.com/) for more advanced tutorials and examples. diff --git a/ultralytics/docs/guides/docker-quickstart.md b/ultralytics/docs/guides/docker-quickstart.md new file mode 100644 index 0000000000000000000000000000000000000000..d1a8ff4f8bf7979c72520c6f51693be2dd754e18 --- /dev/null +++ b/ultralytics/docs/guides/docker-quickstart.md @@ -0,0 +1,119 @@ +--- +comments: true +description: Complete guide to setting up and using Ultralytics YOLO models with Docker. Learn how to install Docker, manage GPU support, and run YOLO models in isolated containers. +keywords: Ultralytics, YOLO, Docker, GPU, containerization, object detection, package installation, deep learning, machine learning, guide +--- + +# Docker Quickstart Guide for Ultralytics + ++ +
+ +This guide serves as a comprehensive introduction to setting up a Docker environment for your Ultralytics projects. [Docker](https://docker.com/) is a platform for developing, shipping, and running applications in containers. It is particularly beneficial for ensuring that the software will always run the same, regardless of where it's deployed. For more details, visit the Ultralytics Docker repository on [Docker Hub](https://hub.docker.com/r/ultralytics/ultralytics). + +[![Docker Pulls](https://img.shields.io/docker/pulls/ultralytics/ultralytics?logo=docker)](https://hub.docker.com/r/ultralytics/ultralytics) + +## What You Will Learn + +- Setting up Docker with NVIDIA support +- Installing Ultralytics Docker images +- Running Ultralytics in a Docker container +- Mounting local directories into the container + +--- + +## Prerequisites + +- Make sure Docker is installed on your system. If not, you can download and install it from [Docker's website](https://www.docker.com/products/docker-desktop). +- Ensure that your system has an NVIDIA GPU and NVIDIA drivers are installed. + +--- + +## Setting up Docker with NVIDIA Support + +First, verify that the NVIDIA drivers are properly installed by running: + +```bash +nvidia-smi +``` + +### Installing NVIDIA Docker Runtime + +Now, let's install the NVIDIA Docker runtime to enable GPU support in Docker containers: + +```bash +# Add NVIDIA package repositories +curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | sudo apt-key add - +distribution=$(lsb_release -cs) +curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list | sudo tee /etc/apt/sources.list.d/nvidia-docker.list + +# Install NVIDIA Docker runtime +sudo apt-get update +sudo apt-get install -y nvidia-docker2 + +# Restart Docker service to apply changes +sudo systemctl restart docker +``` + +### Verify NVIDIA Runtime with Docker + +Run `docker info | grep -i runtime` to ensure that `nvidia` appears in the list of runtimes: + +```bash +docker info | grep -i runtime +``` + +--- + +## Installing Ultralytics Docker Images + +Ultralytics offers several Docker images optimized for various platforms and use-cases: + +- **Dockerfile:** GPU image, ideal for training. +- **Dockerfile-arm64:** For ARM64 architecture, suitable for devices like [Raspberry Pi](raspberry-pi.md). +- **Dockerfile-cpu:** CPU-only version for inference and non-GPU environments. +- **Dockerfile-jetson:** Optimized for NVIDIA Jetson devices. +- **Dockerfile-python:** Minimal Python environment for lightweight applications. +- **Dockerfile-conda:** Includes [Miniconda3](https://docs.conda.io/projects/miniconda/en/latest/) and Ultralytics package installed via Conda. + +To pull the latest image: + +```bash +# Set image name as a variable +t=ultralytics/ultralytics:latest + +# Pull the latest Ultralytics image from Docker Hub +sudo docker pull $t +``` + +--- + +## Running Ultralytics in Docker Container + +Here's how to execute the Ultralytics Docker container: + +```bash +# Run with all GPUs +sudo docker run -it --ipc=host --gpus all $t + +# Run specifying which GPUs to use +sudo docker run -it --ipc=host --gpus '"device=2,3"' $t +``` + +The `-it` flag assigns a pseudo-TTY and keeps stdin open, allowing you to interact with the container. The `--ipc=host` flag enables sharing of host's IPC namespace, essential for sharing memory between processes. The `--gpus` flag allows the container to access the host's GPUs. + +### Note on File Accessibility + +To work with files on your local machine within the container, you can use Docker volumes: + +```bash +# Mount a local directory into the container +sudo docker run -it --ipc=host --gpus all -v /path/on/host:/path/in/container $t +``` + +Replace `/path/on/host` with the directory path on your local machine and `/path/in/container` with the desired path inside the Docker container. + +--- + +Congratulations! You're now set up to use Ultralytics with Docker and ready to take advantage of its powerful capabilities. For alternate installation methods, feel free to explore the [Ultralytics quickstart documentation](https://docs.ultralytics.com/quickstart/). diff --git a/ultralytics/docs/guides/hyperparameter-tuning.md b/ultralytics/docs/guides/hyperparameter-tuning.md new file mode 100644 index 0000000000000000000000000000000000000000..9f16adc6d6c1e48d7c39216476d37e4a7d639766 --- /dev/null +++ b/ultralytics/docs/guides/hyperparameter-tuning.md @@ -0,0 +1,206 @@ +--- +comments: true +description: Dive into hyperparameter tuning in Ultralytics YOLO models. Learn how to optimize performance using the Tuner class and genetic evolution. +keywords: Ultralytics, YOLO, Hyperparameter Tuning, Tuner Class, Genetic Evolution, Optimization +--- + +# Ultralytics YOLO Hyperparameter Tuning Guide + +## Introduction + +Hyperparameter tuning is not just a one-time set-up but an iterative process aimed at optimizing the machine learning model's performance metrics, such as accuracy, precision, and recall. In the context of Ultralytics YOLO, these hyperparameters could range from learning rate to architectural details, such as the number of layers or types of activation functions used. + +### What are Hyperparameters? + +Hyperparameters are high-level, structural settings for the algorithm. They are set prior to the training phase and remain constant during it. Here are some commonly tuned hyperparameters in Ultralytics YOLO: + +- **Learning Rate** `lr0`: Determines the step size at each iteration while moving towards a minimum in the loss function. +- **Batch Size** `batch`: Number of images processed simultaneously in a forward pass. +- **Number of Epochs** `epochs`: An epoch is one complete forward and backward pass of all the training examples. +- **Architecture Specifics**: Such as channel counts, number of layers, types of activation functions, etc. + ++ +
+ +For a full list of augmentation hyperparameters used in YOLOv8 please refer to [https://docs.ultralytics.com/usage/cfg/#augmentation](https://docs.ultralytics.com/usage/cfg/#augmentation). + +### Genetic Evolution and Mutation + +Ultralytics YOLO uses genetic algorithms to optimize hyperparameters. Genetic algorithms are inspired by the mechanism of natural selection and genetics. + +- **Mutation**: In the context of Ultralytics YOLO, mutation helps in locally searching the hyperparameter space by applying small, random changes to existing hyperparameters, producing new candidates for evaluation. +- **Crossover**: Although crossover is a popular genetic algorithm technique, it is not currently used in Ultralytics YOLO for hyperparameter tuning. The focus is mainly on mutation for generating new hyperparameter sets. + +## Preparing for Hyperparameter Tuning + +Before you begin the tuning process, it's important to: + +1. **Identify the Metrics**: Determine the metrics you will use to evaluate the model's performance. This could be AP50, F1-score, or others. +2. **Set the Tuning Budget**: Define how much computational resources you're willing to allocate. Hyperparameter tuning can be computationally intensive. + +## Steps Involved + +### Initialize Hyperparameters + +Start with a reasonable set of initial hyperparameters. This could either be the default hyperparameters set by Ultralytics YOLO or something based on your domain knowledge or previous experiments. + +### Mutate Hyperparameters + +Use the `_mutate` method to produce a new set of hyperparameters based on the existing set. + +### Train Model + +Training is performed using the mutated set of hyperparameters. The training performance is then assessed. + +### Evaluate Model + +Use metrics like AP50, F1-score, or custom metrics to evaluate the model's performance. + +### Log Results + +It's crucial to log both the performance metrics and the corresponding hyperparameters for future reference. + +### Repeat + +The process is repeated until either the set number of iterations is reached or the performance metric is satisfactory. + +## Usage Example + +Here's how to use the `model.tune()` method to utilize the `Tuner` class for hyperparameter tuning of YOLOv8n on COCO8 for 30 epochs with an AdamW optimizer and skipping plotting, checkpointing and validation other than on final epoch for faster Tuning. + +!!! example "" + + === "Python" + + ```python + from ultralytics import YOLO + + # Initialize the YOLO model + model = YOLO('yolov8n.pt') + + # Tune hyperparameters on COCO8 for 30 epochs + model.tune(data='coco8.yaml', epochs=30, iterations=300, optimizer='AdamW', plots=False, save=False, val=False) + ``` + +## Results + +After you've successfully completed the hyperparameter tuning process, you will obtain several files and directories that encapsulate the results of the tuning. The following describes each: + +### File Structure + +Here's what the directory structure of the results will look like. Training directories like `train1/` contain individual tuning iterations, i.e. one model trained with one set of hyperparameters. The `tune/` directory contains tuning results from all the individual model trainings: + +```plaintext +runs/ +└── detect/ + ├── train1/ + ├── train2/ + ├── ... + └── tune/ + ├── best_hyperparameters.yaml + ├── best_fitness.png + ├── tune_results.csv + ├── tune_scatter_plots.png + └── weights/ + ├── last.pt + └── best.pt +``` + +### File Descriptions + +#### best_hyperparameters.yaml + +This YAML file contains the best-performing hyperparameters found during the tuning process. You can use this file to initialize future trainings with these optimized settings. + +- **Format**: YAML +- **Usage**: Hyperparameter results +- **Example**: + ```yaml + # 558/900 iterations complete ✅ (45536.81s) + # Results saved to /usr/src/ultralytics/runs/detect/tune + # Best fitness=0.64297 observed at iteration 498 + # Best fitness metrics are {'metrics/precision(B)': 0.87247, 'metrics/recall(B)': 0.71387, 'metrics/mAP50(B)': 0.79106, 'metrics/mAP50-95(B)': 0.62651, 'val/box_loss': 2.79884, 'val/cls_loss': 2.72386, 'val/dfl_loss': 0.68503, 'fitness': 0.64297} + # Best fitness model is /usr/src/ultralytics/runs/detect/train498 + # Best fitness hyperparameters are printed below. + + lr0: 0.00269 + lrf: 0.00288 + momentum: 0.73375 + weight_decay: 0.00015 + warmup_epochs: 1.22935 + warmup_momentum: 0.1525 + box: 18.27875 + cls: 1.32899 + dfl: 0.56016 + hsv_h: 0.01148 + hsv_s: 0.53554 + hsv_v: 0.13636 + degrees: 0.0 + translate: 0.12431 + scale: 0.07643 + shear: 0.0 + perspective: 0.0 + flipud: 0.0 + fliplr: 0.08631 + mosaic: 0.42551 + mixup: 0.0 + copy_paste: 0.0 + ``` + +#### best_fitness.png + +This is a plot displaying fitness (typically a performance metric like AP50) against the number of iterations. It helps you visualize how well the genetic algorithm performed over time. + +- **Format**: PNG +- **Usage**: Performance visualization + ++ +
+ +#### tune_results.csv + +A CSV file containing detailed results of each iteration during the tuning. Each row in the file represents one iteration, and it includes metrics like fitness score, precision, recall, as well as the hyperparameters used. + +- **Format**: CSV +- **Usage**: Per-iteration results tracking. +- **Example**: + ```csv + fitness,lr0,lrf,momentum,weight_decay,warmup_epochs,warmup_momentum,box,cls,dfl,hsv_h,hsv_s,hsv_v,degrees,translate,scale,shear,perspective,flipud,fliplr,mosaic,mixup,copy_paste + 0.05021,0.01,0.01,0.937,0.0005,3.0,0.8,7.5,0.5,1.5,0.015,0.7,0.4,0.0,0.1,0.5,0.0,0.0,0.0,0.5,1.0,0.0,0.0 + 0.07217,0.01003,0.00967,0.93897,0.00049,2.79757,0.81075,7.5,0.50746,1.44826,0.01503,0.72948,0.40658,0.0,0.0987,0.4922,0.0,0.0,0.0,0.49729,1.0,0.0,0.0 + 0.06584,0.01003,0.00855,0.91009,0.00073,3.42176,0.95,8.64301,0.54594,1.72261,0.01503,0.59179,0.40658,0.0,0.0987,0.46955,0.0,0.0,0.0,0.49729,0.80187,0.0,0.0 + ``` + +#### tune_scatter_plots.png + +This file contains scatter plots generated from `tune_results.csv`, helping you visualize relationships between different hyperparameters and performance metrics. Note that hyperparameters initialized to 0 will not be tuned, such as `degrees` and `shear` below. + +- **Format**: PNG +- **Usage**: Exploratory data analysis + ++ +
+ +#### weights/ + +This directory contains the saved PyTorch models for the last and the best iterations during the hyperparameter tuning process. + +- **`last.pt`**: The last.pt weights for the iteration that achieved the best fitness score. +- **`best.pt`**: The best.pt weights for the iteration that achieved the best fitness score. + +Using these results, you can make more informed decisions for your future model trainings and analyses. Feel free to consult these artifacts to understand how well your model performed and how you might improve it further. + +## Conclusion + +The hyperparameter tuning process in Ultralytics YOLO is simplified yet powerful, thanks to its genetic algorithm-based approach focused on mutation. Following the steps outlined in this guide will assist you in systematically tuning your model to achieve better performance. + +### Further Reading + +1. [Hyperparameter Optimization in Wikipedia](https://en.wikipedia.org/wiki/Hyperparameter_optimization) +2. [YOLOv5 Hyperparameter Evolution Guide](https://docs.ultralytics.com/yolov5/tutorials/hyperparameter_evolution/) +3. [Efficient Hyperparameter Tuning with Ray Tune and YOLOv8](https://docs.ultralytics.com/integrations/ray-tune/) + +For deeper insights, you can explore the `Tuner` class source code and accompanying documentation. Should you have any questions, feature requests, or need further assistance, feel free to reach out to us on [GitHub](https://github.com/ultralytics/ultralytics/issues/new/choose) or [Discord](https://ultralytics.com/discord). diff --git a/ultralytics/docs/guides/index.md b/ultralytics/docs/guides/index.md new file mode 100644 index 0000000000000000000000000000000000000000..a59762e3dffc298fa46aa2a467ef3b31afe9cf62 --- /dev/null +++ b/ultralytics/docs/guides/index.md @@ -0,0 +1,36 @@ +--- +comments: true +description: In-depth exploration of Ultralytics' YOLO. Learn about the YOLO object detection model, how to train it on custom data, multi-GPU training, exporting, predicting, deploying, and more. +keywords: Ultralytics, YOLO, Deep Learning, Object detection, PyTorch, Tutorial, Multi-GPU training, Custom data training, SAHI, Tiled Inference +--- + +# Comprehensive Tutorials to Ultralytics YOLO + +Welcome to the Ultralytics' YOLO 🚀 Guides! Our comprehensive tutorials cover various aspects of the YOLO object detection model, ranging from training and prediction to deployment. Built on PyTorch, YOLO stands out for its exceptional speed and accuracy in real-time object detection tasks. + +Whether you're a beginner or an expert in deep learning, our tutorials offer valuable insights into the implementation and optimization of YOLO for your computer vision projects. Let's dive in! + +## Guides + +Here's a compilation of in-depth guides to help you master different aspects of Ultralytics YOLO. + +* [YOLO Common Issues](yolo-common-issues.md) ⭐ RECOMMENDED: Practical solutions and troubleshooting tips to the most frequently encountered issues when working with Ultralytics YOLO models. +* [YOLO Performance Metrics](yolo-performance-metrics.md) ⭐ ESSENTIAL: Understand the key metrics like mAP, IoU, and F1 score used to evaluate the performance of your YOLO models. Includes practical examples and tips on how to improve detection accuracy and speed. +* [Model Deployment Options](model-deployment-options.md): Overview of YOLO model deployment formats like ONNX, OpenVINO, and TensorRT, with pros and cons for each to inform your deployment strategy. +* [K-Fold Cross Validation](kfold-cross-validation.md) 🚀 NEW: Learn how to improve model generalization using K-Fold cross-validation technique. +* [Hyperparameter Tuning](hyperparameter-tuning.md) 🚀 NEW: Discover how to optimize your YOLO models by fine-tuning hyperparameters using the Tuner class and genetic evolution algorithms. +* [SAHI Tiled Inference](sahi-tiled-inference.md) 🚀 NEW: Comprehensive guide on leveraging SAHI's sliced inference capabilities with YOLOv8 for object detection in high-resolution images. +* [AzureML Quickstart](azureml-quickstart.md) 🚀 NEW: Get up and running with Ultralytics YOLO models on Microsoft's Azure Machine Learning platform. Learn how to train, deploy, and scale your object detection projects in the cloud. +* [Conda Quickstart](conda-quickstart.md) 🚀 NEW: Step-by-step guide to setting up a [Conda](https://anaconda.org/conda-forge/ultralytics) environment for Ultralytics. Learn how to install and start using the Ultralytics package efficiently with Conda. +* [Docker Quickstart](docker-quickstart.md) 🚀 NEW: Complete guide to setting up and using Ultralytics YOLO models with [Docker](https://hub.docker.com/r/ultralytics/ultralytics). Learn how to install Docker, manage GPU support, and run YOLO models in isolated containers for consistent development and deployment. +* [Raspberry Pi](raspberry-pi.md) 🚀 NEW: Quickstart tutorial to run YOLO models to the latest Raspberry Pi hardware. +* [Triton Inference Server Integration](triton-inference-server.md) 🚀 NEW: Dive into the integration of Ultralytics YOLOv8 with NVIDIA's Triton Inference Server for scalable and efficient deep learning inference deployments. +* [YOLO Thread-Safe Inference](yolo-thread-safe-inference.md) 🚀 NEW: Guidelines for performing inference with YOLO models in a thread-safe manner. Learn the importance of thread safety and best practices to prevent race conditions and ensure consistent predictions. + +## Contribute to Our Guides + +We welcome contributions from the community! If you've mastered a particular aspect of Ultralytics YOLO that's not yet covered in our guides, we encourage you to share your expertise. Writing a guide is a great way to give back to the community and help us make our documentation more comprehensive and user-friendly. + +To get started, please read our [Contributing Guide](https://docs.ultralytics.com/help/contributing) for guidelines on how to open up a Pull Request (PR) 🛠️. We look forward to your contributions! + +Let's work together to make the Ultralytics YOLO ecosystem more robust and versatile 🙏! diff --git a/ultralytics/docs/guides/kfold-cross-validation.md b/ultralytics/docs/guides/kfold-cross-validation.md new file mode 100644 index 0000000000000000000000000000000000000000..56a3cc755dd03ff6dd28bcc502c46e79418d000f --- /dev/null +++ b/ultralytics/docs/guides/kfold-cross-validation.md @@ -0,0 +1,279 @@ +--- +comments: true +description: An in-depth guide demonstrating the implementation of K-Fold Cross Validation with the Ultralytics ecosystem for object detection datasets, leveraging Python, YOLO, and sklearn. +keywords: K-Fold cross validation, Ultralytics, YOLO detection format, Python, sklearn, object detection +--- + +# K-Fold Cross Validation with Ultralytics + +## Introduction + +This comprehensive guide illustrates the implementation of K-Fold Cross Validation for object detection datasets within the Ultralytics ecosystem. We'll leverage the YOLO detection format and key Python libraries such as sklearn, pandas, and PyYaml to guide you through the necessary setup, the process of generating feature vectors, and the execution of a K-Fold dataset split. + ++ +
+ +Whether your project involves the Fruit Detection dataset or a custom data source, this tutorial aims to help you comprehend and apply K-Fold Cross Validation to bolster the reliability and robustness of your machine learning models. While we're applying `k=5` folds for this tutorial, keep in mind that the optimal number of folds can vary depending on your dataset and the specifics of your project. + +Without further ado, let's dive in! + +## Setup + +- Your annotations should be in the [YOLO detection format](https://docs.ultralytics.com/datasets/detect/). + +- This guide assumes that annotation files are locally available. + + - For our demonstration, we use the [Fruit Detection](https://www.kaggle.com/datasets/lakshaytyagi01/fruit-detection/code) dataset. + + - This dataset contains a total of 8479 images. + - It includes 6 class labels, each with its total instance counts listed below. + + | Class Label | Instance Count | + |:------------|:--------------:| + | Apple | 7049 | + | Grapes | 7202 | + | Pineapple | 1613 | + | Orange | 15549 | + | Banana | 3536 | + | Watermelon | 1976 | + +- Necessary Python packages include: + + - `ultralytics` + - `sklearn` + - `pandas` + - `pyyaml` + +- This tutorial operates with `k=5` folds. However, you should determine the best number of folds for your specific dataset. + +1. Initiate a new Python virtual environment (`venv`) for your project and activate it. Use `pip` (or your preferred package manager) to install: + + - The Ultralytics library: `pip install -U ultralytics`. Alternatively, you can clone the official [repo](https://github.com/ultralytics/ultralytics). + - Scikit-learn, pandas, and PyYAML: `pip install -U scikit-learn pandas pyyaml`. + +2. Verify that your annotations are in the [YOLO detection format](https://docs.ultralytics.com/datasets/detect/). + + - For this tutorial, all annotation files are found in the `Fruit-Detection/labels` directory. + +## Generating Feature Vectors for Object Detection Dataset + +1. Start by creating a new Python file and import the required libraries. + + ```python + import datetime + import shutil + from pathlib import Path + from collections import Counter + + import yaml + import numpy as np + import pandas as pd + from ultralytics import YOLO + from sklearn.model_selection import KFold + ``` + +2. Proceed to retrieve all label files for your dataset. + + ```python + dataset_path = Path('./Fruit-detection') # replace with 'path/to/dataset' for your custom data + labels = sorted(dataset_path.rglob("*labels/*.txt")) # all data in 'labels' + ``` + +3. Now, read the contents of the dataset YAML file and extract the indices of the class labels. + + ```python + yaml_file = 'path/to/data.yaml' # your data YAML with data directories and names dictionary + with open(yaml_file, 'r', encoding="utf8") as y: + classes = yaml.safe_load(y)['names'] + cls_idx = sorted(classes.keys()) + ``` + +4. Initialize an empty `pandas` DataFrame. + + ```python + indx = [l.stem for l in labels] # uses base filename as ID (no extension) + labels_df = pd.DataFrame([], columns=cls_idx, index=indx) + ``` + +5. Count the instances of each class-label present in the annotation files. + + ```python + for label in labels: + lbl_counter = Counter() + + with open(label,'r') as lf: + lines = lf.readlines() + + for l in lines: + # classes for YOLO label uses integer at first position of each line + lbl_counter[int(l.split(' ')[0])] += 1 + + labels_df.loc[label.stem] = lbl_counter + + labels_df = labels_df.fillna(0.0) # replace `nan` values with `0.0` + ``` + +6. The following is a sample view of the populated DataFrame: + + ```pandas + 0 1 2 3 4 5 + '0000a16e4b057580_jpg.rf.00ab48988370f64f5ca8ea4...' 0.0 0.0 0.0 0.0 0.0 7.0 + '0000a16e4b057580_jpg.rf.7e6dce029fb67f01eb19aa7...' 0.0 0.0 0.0 0.0 0.0 7.0 + '0000a16e4b057580_jpg.rf.bc4d31cdcbe229dd022957a...' 0.0 0.0 0.0 0.0 0.0 7.0 + '00020ebf74c4881c_jpg.rf.508192a0a97aa6c4a3b6882...' 0.0 0.0 0.0 1.0 0.0 0.0 + '00020ebf74c4881c_jpg.rf.5af192a2254c8ecc4188a25...' 0.0 0.0 0.0 1.0 0.0 0.0 + ... ... ... ... ... ... ... + 'ff4cd45896de38be_jpg.rf.c4b5e967ca10c7ced3b9e97...' 0.0 0.0 0.0 0.0 0.0 2.0 + 'ff4cd45896de38be_jpg.rf.ea4c1d37d2884b3e3cbce08...' 0.0 0.0 0.0 0.0 0.0 2.0 + 'ff5fd9c3c624b7dc_jpg.rf.bb519feaa36fc4bf630a033...' 1.0 0.0 0.0 0.0 0.0 0.0 + 'ff5fd9c3c624b7dc_jpg.rf.f0751c9c3aa4519ea3c9d6a...' 1.0 0.0 0.0 0.0 0.0 0.0 + 'fffe28b31f2a70d4_jpg.rf.7ea16bd637ba0711c53b540...' 0.0 6.0 0.0 0.0 0.0 0.0 + ``` + +The rows index the label files, each corresponding to an image in your dataset, and the columns correspond to your class-label indices. Each row represents a pseudo feature-vector, with the count of each class-label present in your dataset. This data structure enables the application of K-Fold Cross Validation to an object detection dataset. + +## K-Fold Dataset Split + +1. Now we will use the `KFold` class from `sklearn.model_selection` to generate `k` splits of the dataset. + + - Important: + - Setting `shuffle=True` ensures a randomized distribution of classes in your splits. + - By setting `random_state=M` where `M` is a chosen integer, you can obtain repeatable results. + + ```python + ksplit = 5 + kf = KFold(n_splits=ksplit, shuffle=True, random_state=20) # setting random_state for repeatable results + + kfolds = list(kf.split(labels_df)) + ``` + +2. The dataset has now been split into `k` folds, each having a list of `train` and `val` indices. We will construct a DataFrame to display these results more clearly. + + ```python + folds = [f'split_{n}' for n in range(1, ksplit + 1)] + folds_df = pd.DataFrame(index=indx, columns=folds) + + for idx, (train, val) in enumerate(kfolds, start=1): + folds_df[f'split_{idx}'].loc[labels_df.iloc[train].index] = 'train' + folds_df[f'split_{idx}'].loc[labels_df.iloc[val].index] = 'val' + ``` + +3. Now we will calculate the distribution of class labels for each fold as a ratio of the classes present in `val` to those present in `train`. + + ```python + fold_lbl_distrb = pd.DataFrame(index=folds, columns=cls_idx) + + for n, (train_indices, val_indices) in enumerate(kfolds, start=1): + train_totals = labels_df.iloc[train_indices].sum() + val_totals = labels_df.iloc[val_indices].sum() + + # To avoid division by zero, we add a small value (1E-7) to the denominator + ratio = val_totals / (train_totals + 1E-7) + fold_lbl_distrb.loc[f'split_{n}'] = ratio + ``` + +The ideal scenario is for all class ratios to be reasonably similar for each split and across classes. This, however, will be subject to the specifics of your dataset. + +4. Next, we create the directories and dataset YAML files for each split. + + ```python + supported_extensions = ['.jpg', '.jpeg', '.png'] + + # Initialize an empty list to store image file paths + images = [] + + # Loop through supported extensions and gather image files + for ext in supported_extensions: + images.extend(sorted((dataset_path / 'images').rglob(f"*{ext}"))) + + # Create the necessary directories and dataset YAML files (unchanged) + save_path = Path(dataset_path / f'{datetime.date.today().isoformat()}_{ksplit}-Fold_Cross-val') + save_path.mkdir(parents=True, exist_ok=True) + ds_yamls = [] + + for split in folds_df.columns: + # Create directories + split_dir = save_path / split + split_dir.mkdir(parents=True, exist_ok=True) + (split_dir / 'train' / 'images').mkdir(parents=True, exist_ok=True) + (split_dir / 'train' / 'labels').mkdir(parents=True, exist_ok=True) + (split_dir / 'val' / 'images').mkdir(parents=True, exist_ok=True) + (split_dir / 'val' / 'labels').mkdir(parents=True, exist_ok=True) + + # Create dataset YAML files + dataset_yaml = split_dir / f'{split}_dataset.yaml' + ds_yamls.append(dataset_yaml) + + with open(dataset_yaml, 'w') as ds_y: + yaml.safe_dump({ + 'path': split_dir.as_posix(), + 'train': 'train', + 'val': 'val', + 'names': classes + }, ds_y) + ``` + +5. Lastly, copy images and labels into the respective directory ('train' or 'val') for each split. + + - __NOTE:__ The time required for this portion of the code will vary based on the size of your dataset and your system hardware. + + ```python + for image, label in zip(images, labels): + for split, k_split in folds_df.loc[image.stem].items(): + # Destination directory + img_to_path = save_path / split / k_split / 'images' + lbl_to_path = save_path / split / k_split / 'labels' + + # Copy image and label files to new directory (SamefileError if file already exists) + shutil.copy(image, img_to_path / image.name) + shutil.copy(label, lbl_to_path / label.name) + ``` + +## Save Records (Optional) + +Optionally, you can save the records of the K-Fold split and label distribution DataFrames as CSV files for future reference. + +```python +folds_df.to_csv(save_path / "kfold_datasplit.csv") +fold_lbl_distrb.to_csv(save_path / "kfold_label_distribution.csv") +``` + +## Train YOLO using K-Fold Data Splits + +1. First, load the YOLO model. + + ```python + weights_path = 'path/to/weights.pt' + model = YOLO(weights_path, task='detect') + ``` + +2. Next, iterate over the dataset YAML files to run training. The results will be saved to a directory specified by the `project` and `name` arguments. By default, this directory is 'exp/runs#' where # is an integer index. + + ```python + results = {} + + # Define your additional arguments here + batch = 16 + project = 'kfold_demo' + epochs = 100 + + for k in range(ksplit): + dataset_yaml = ds_yamls[k] + model.train(data=dataset_yaml,epochs=epochs, batch=batch, project=project) # include any train arguments + results[k] = model.metrics # save output metrics for further analysis + ``` + +## Conclusion + +In this guide, we have explored the process of using K-Fold cross-validation for training the YOLO object detection model. We learned how to split our dataset into K partitions, ensuring a balanced class distribution across the different folds. + +We also explored the procedure for creating report DataFrames to visualize the data splits and label distributions across these splits, providing us a clear insight into the structure of our training and validation sets. + +Optionally, we saved our records for future reference, which could be particularly useful in large-scale projects or when troubleshooting model performance. + +Finally, we implemented the actual model training using each split in a loop, saving our training results for further analysis and comparison. + +This technique of K-Fold cross-validation is a robust way of making the most out of your available data, and it helps to ensure that your model performance is reliable and consistent across different data subsets. This results in a more generalizable and reliable model that is less likely to overfit to specific data patterns. + +Remember that although we used YOLO in this guide, these steps are mostly transferable to other machine learning models. Understanding these steps allows you to apply cross-validation effectively in your own machine learning projects. Happy coding! diff --git a/ultralytics/docs/guides/model-deployment-options.md b/ultralytics/docs/guides/model-deployment-options.md new file mode 100644 index 0000000000000000000000000000000000000000..dca36d1d9a8ce1f6cfc62f6034f9eb23a6820c9a --- /dev/null +++ b/ultralytics/docs/guides/model-deployment-options.md @@ -0,0 +1,305 @@ +--- +comments: true +Description: A guide to help determine which deployment option to choose for your YOLOv8 model, including essential considerations. +keywords: YOLOv8, Deployment, PyTorch, TorchScript, ONNX, OpenVINO, TensorRT, CoreML, TensorFlow, Export +--- + +# Understanding YOLOv8’s Deployment Options + +## Introduction + +*Setting the Scene:* You've come a long way on your journey with YOLOv8. You've diligently collected data, meticulously annotated it, and put in the hours to train and rigorously evaluate your custom YOLOv8 model. Now, it’s time to put your model to work for your specific application, use case, or project. But there's a critical decision that stands before you: how to export and deploy your model effectively. + +This guide walks you through YOLOv8’s deployment options and the essential factors to consider to choose the right option for your project. + +## How to Select the Right Deployment Option for Your YOLOv8 Model + +When it's time to deploy your YOLOv8 model, selecting a suitable export format is very important. As outlined in the [Ultralytics YOLOv8 Modes documentation](https://docs.ultralytics.com/modes/export/#usage-examples), the model.export() function allows for converting your trained model into a variety of formats tailored to diverse environments and performance requirements. + +The ideal format depends on your model's intended operational context, balancing speed, hardware constraints, and ease of integration. In the following section, we'll take a closer look at each export option, understanding when to choose each one. + +### YOLOv8’s Deployment Options + +Let’s walk through the different YOLOv8 deployment options. For a detailed walkthrough of the export process, visit the [Ultralytics documentation page on exporting](https://docs.ultralytics.com/modes/export/). + +#### PyTorch + +PyTorch is an open-source machine learning library widely used for applications in deep learning and artificial intelligence. It provides a high level of flexibility and speed, which has made it a favorite among researchers and developers. + +- **Performance Benchmarks**: PyTorch is known for its ease of use and flexibility, which may result in a slight trade-off in raw performance when compared to other frameworks that are more specialized and optimized. + +- **Compatibility and Integration**: Offers excellent compatibility with various data science and machine learning libraries in Python. + +- **Community Support and Ecosystem**: One of the most vibrant communities, with extensive resources for learning and troubleshooting. + +- **Case Studies**: Commonly used in research prototypes, many academic papers reference models deployed in PyTorch. + +- **Maintenance and Updates**: Regular updates with active development and support for new features. + +- **Security Considerations**: Regular patches for security issues, but security is largely dependent on the overall environment it’s deployed in. + +- **Hardware Acceleration**: Supports CUDA for GPU acceleration, essential for speeding up model training and inference. + +#### TorchScript + +TorchScript extends PyTorch’s capabilities by allowing the exportation of models to be run in a C++ runtime environment. This makes it suitable for production environments where Python is unavailable. + +- **Performance Benchmarks**: Can offer improved performance over native PyTorch, especially in production environments. + +- **Compatibility and Integration**: Designed for seamless transition from PyTorch to C++ production environments, though some advanced features might not translate perfectly. + +- **Community Support and Ecosystem**: Benefits from PyTorch’s large community but has a narrower scope of specialized developers. + +- **Case Studies**: Widely used in industry settings where Python’s performance overhead is a bottleneck. + +- **Maintenance and Updates**: Maintained alongside PyTorch with consistent updates. + +- **Security Considerations**: Offers improved security by enabling the running of models in environments without full Python installations. + +- **Hardware Acceleration**: Inherits PyTorch’s CUDA support, ensuring efficient GPU utilization. + +#### ONNX + +The Open Neural Network Exchange (ONNX) is a format that allows for model interoperability across different frameworks, which can be critical when deploying to various platforms. + +- **Performance Benchmarks**: ONNX models may experience a variable performance depending on the specific runtime they are deployed on. + +- **Compatibility and Integration**: High interoperability across multiple platforms and hardware due to its framework-agnostic nature. + +- **Community Support and Ecosystem**: Supported by many organizations, leading to a broad ecosystem and a variety of tools for optimization. + +- **Case Studies**: Frequently used to move models between different machine learning frameworks, demonstrating its flexibility. + +- **Maintenance and Updates**: As an open standard, ONNX is regularly updated to support new operations and models. + +- **Security Considerations**: As with any cross-platform tool, it's essential to ensure secure practices in the conversion and deployment pipeline. + +- **Hardware Acceleration**: With ONNX Runtime, models can leverage various hardware optimizations. + +#### OpenVINO + +OpenVINO is an Intel toolkit designed to facilitate the deployment of deep learning models across Intel hardware, enhancing performance and speed. + +- **Performance Benchmarks**: Specifically optimized for Intel CPUs, GPUs, and VPUs, offering significant performance boosts on compatible hardware. + +- **Compatibility and Integration**: Works best within the Intel ecosystem but also supports a range of other platforms. + +- **Community Support and Ecosystem**: Backed by Intel, with a solid user base especially in the computer vision domain. + +- **Case Studies**: Often utilized in IoT and edge computing scenarios where Intel hardware is prevalent. + +- **Maintenance and Updates**: Intel regularly updates OpenVINO to support the latest deep learning models and Intel hardware. + +- **Security Considerations**: Provides robust security features suitable for deployment in sensitive applications. + +- **Hardware Acceleration**: Tailored for acceleration on Intel hardware, leveraging dedicated instruction sets and hardware features. + +For more details on deployment using OpenVINO, refer to the Ultralytics Integration documentation: [Intel OpenVINO Export](https://docs.ultralytics.com/integrations/openvino/). + +#### TensorRT + +TensorRT is a high-performance deep learning inference optimizer and runtime from NVIDIA, ideal for applications needing speed and efficiency. + +- **Performance Benchmarks**: Delivers top-tier performance on NVIDIA GPUs with support for high-speed inference. + +- **Compatibility and Integration**: Best suited for NVIDIA hardware, with limited support outside this environment. + +- **Community Support and Ecosystem**: Strong support network through NVIDIA’s developer forums and documentation. + +- **Case Studies**: Widely adopted in industries requiring real-time inference on video and image data. + +- **Maintenance and Updates**: NVIDIA maintains TensorRT with frequent updates to enhance performance and support new GPU architectures. + +- **Security Considerations**: Like many NVIDIA products, it has a strong emphasis on security, but specifics depend on the deployment environment. + +- **Hardware Acceleration**: Exclusively designed for NVIDIA GPUs, providing deep optimization and acceleration. + +#### CoreML + +CoreML is Apple’s machine learning framework, optimized for on-device performance in the Apple ecosystem, including iOS, macOS, watchOS, and tvOS. + +- **Performance Benchmarks**: Optimized for on-device performance on Apple hardware with minimal battery usage. + +- **Compatibility and Integration**: Exclusively for Apple's ecosystem, providing a streamlined workflow for iOS and macOS applications. + +- **Community Support and Ecosystem**: Strong support from Apple and a dedicated developer community, with extensive documentation and tools. + +- **Case Studies**: Commonly used in applications that require on-device machine learning capabilities on Apple products. + +- **Maintenance and Updates**: Regularly updated by Apple to support the latest machine learning advancements and Apple hardware. + +- **Security Considerations**: Benefits from Apple's focus on user privacy and data security. + +- **Hardware Acceleration**: Takes full advantage of Apple's neural engine and GPU for accelerated machine learning tasks. + +#### TF SavedModel + +TF SavedModel is TensorFlow’s format for saving and serving machine learning models, particularly suited for scalable server environments. + +- **Performance Benchmarks**: Offers scalable performance in server environments, especially when used with TensorFlow Serving. + +- **Compatibility and Integration**: Wide compatibility across TensorFlow's ecosystem, including cloud and enterprise server deployments. + +- **Community Support and Ecosystem**: Large community support due to TensorFlow's popularity, with a vast array of tools for deployment and optimization. + +- **Case Studies**: Extensively used in production environments for serving deep learning models at scale. + +- **Maintenance and Updates**: Supported by Google and the TensorFlow community, ensuring regular updates and new features. + +- **Security Considerations**: Deployment using TensorFlow Serving includes robust security features for enterprise-grade applications. + +- **Hardware Acceleration**: Supports various hardware accelerations through TensorFlow's backends. + +#### TF GraphDef + +TF GraphDef is a TensorFlow format that represents the model as a graph, which is beneficial for environments where a static computation graph is required. + +- **Performance Benchmarks**: Provides stable performance for static computation graphs, with a focus on consistency and reliability. + +- **Compatibility and Integration**: Easily integrates within TensorFlow's infrastructure but less flexible compared to SavedModel. + +- **Community Support and Ecosystem**: Good support from TensorFlow's ecosystem, with many resources available for optimizing static graphs. + +- **Case Studies**: Useful in scenarios where a static graph is necessary, such as in certain embedded systems. + +- **Maintenance and Updates**: Regular updates alongside TensorFlow's core updates. + +- **Security Considerations**: Ensures safe deployment with TensorFlow's established security practices. + +- **Hardware Acceleration**: Can utilize TensorFlow's hardware acceleration options, though not as flexible as SavedModel. + +#### TF Lite + +TF Lite is TensorFlow’s solution for mobile and embedded device machine learning, providing a lightweight library for on-device inference. + +- **Performance Benchmarks**: Designed for speed and efficiency on mobile and embedded devices. + +- **Compatibility and Integration**: Can be used on a wide range of devices due to its lightweight nature. + +- **Community Support and Ecosystem**: Backed by Google, it has a robust community and a growing number of resources for developers. + +- **Case Studies**: Popular in mobile applications that require on-device inference with minimal footprint. + +- **Maintenance and Updates**: Regularly updated to include the latest features and optimizations for mobile devices. + +- **Security Considerations**: Provides a secure environment for running models on end-user devices. + +- **Hardware Acceleration**: Supports a variety of hardware acceleration options, including GPU and DSP. + +#### TF Edge TPU + +TF Edge TPU is designed for high-speed, efficient computing on Google's Edge TPU hardware, perfect for IoT devices requiring real-time processing. + +- **Performance Benchmarks**: Specifically optimized for high-speed, efficient computing on Google's Edge TPU hardware. + +- **Compatibility and Integration**: Works exclusively with TensorFlow Lite models on Edge TPU devices. + +- **Community Support and Ecosystem**: Growing support with resources provided by Google and third-party developers. + +- **Case Studies**: Used in IoT devices and applications that require real-time processing with low latency. + +- **Maintenance and Updates**: Continually improved upon to leverage the capabilities of new Edge TPU hardware releases. + +- **Security Considerations**: Integrates with Google's robust security for IoT and edge devices. + +- **Hardware Acceleration**: Custom-designed to take full advantage of Google Coral devices. + +#### TF.js + +TensorFlow.js (TF.js) is a library that brings machine learning capabilities directly to the browser, offering a new realm of possibilities for web developers and users alike. It allows for the integration of machine learning models in web applications without the need for back-end infrastructure. + +- **Performance Benchmarks**: Enables machine learning directly in the browser with reasonable performance, depending on the client device. + +- **Compatibility and Integration**: High compatibility with web technologies, allowing for easy integration into web applications. + +- **Community Support and Ecosystem**: Support from a community of web and Node.js developers, with a variety of tools for deploying ML models in browsers. + +- **Case Studies**: Ideal for interactive web applications that benefit from client-side machine learning without the need for server-side processing. + +- **Maintenance and Updates**: Maintained by the TensorFlow team with contributions from the open-source community. + +- **Security Considerations**: Runs within the browser's secure context, utilizing the security model of the web platform. + +- **Hardware Acceleration**: Performance can be enhanced with web-based APIs that access hardware acceleration like WebGL. + +#### PaddlePaddle + +PaddlePaddle is an open-source deep learning framework developed by Baidu. It is designed to be both efficient for researchers and easy to use for developers. It's particularly popular in China and offers specialized support for Chinese language processing. + +- **Performance Benchmarks**: Offers competitive performance with a focus on ease of use and scalability. + +- **Compatibility and Integration**: Well-integrated within Baidu's ecosystem and supports a wide range of applications. + +- **Community Support and Ecosystem**: While the community is smaller globally, it's rapidly growing, especially in China. + +- **Case Studies**: Commonly used in Chinese markets and by developers looking for alternatives to other major frameworks. + +- **Maintenance and Updates**: Regularly updated with a focus on serving Chinese language AI applications and services. + +- **Security Considerations**: Emphasizes data privacy and security, catering to Chinese data governance standards. + +- **Hardware Acceleration**: Supports various hardware accelerations, including Baidu's own Kunlun chips. + +#### ncnn + +ncnn is a high-performance neural network inference framework optimized for the mobile platform. It stands out for its lightweight nature and efficiency, making it particularly well-suited for mobile and embedded devices where resources are limited. + +- **Performance Benchmarks**: Highly optimized for mobile platforms, offering efficient inference on ARM-based devices. + +- **Compatibility and Integration**: Suitable for applications on mobile phones and embedded systems with ARM architecture. + +- **Community Support and Ecosystem**: Supported by a niche but active community focused on mobile and embedded ML applications. + +- **Case Studies**: Favoured for mobile applications where efficiency and speed are critical on Android and other ARM-based systems. + +- **Maintenance and Updates**: Continuously improved to maintain high performance on a range of ARM devices. + +- **Security Considerations**: Focuses on running locally on the device, leveraging the inherent security of on-device processing. + +- **Hardware Acceleration**: Tailored for ARM CPUs and GPUs, with specific optimizations for these architectures. + +## Comparative Analysis of YOLOv8 Deployment Options + +The following table provides a snapshot of the various deployment options available for YOLOv8 models, helping you to assess which may best fit your project needs based on several critical criteria. For an in-depth look at each deployment option's format, please see the [Ultralytics documentation page on export formats](https://docs.ultralytics.com/modes/export/#export-formats). + +| Deployment Option | Performance Benchmarks | Compatibility and Integration | Community Support and Ecosystem | Case Studies | Maintenance and Updates | Security Considerations | Hardware Acceleration | +|--------------------|------------------------|-------------------------------|--------------------------------|--------------|------------------------|-------------------------|-----------------------| +| PyTorch | Good flexibility; may trade off raw performance | Excellent with Python libraries | Extensive resources and community | Research and prototypes | Regular, active development | Dependent on deployment environment | CUDA support for GPU acceleration | +| TorchScript | Better for production than PyTorch | Smooth transition from PyTorch to C++ | Specialized but narrower than PyTorch | Industry where Python is a bottleneck | Consistent updates with PyTorch | Improved security without full Python | Inherits CUDA support from PyTorch | +| ONNX | Variable depending on runtime | High across different frameworks | Broad ecosystem, supported by many orgs | Flexibility across ML frameworks | Regular updates for new operations | Ensure secure conversion and deployment practices | Various hardware optimizations | +| OpenVINO | Optimized for Intel hardware | Best within Intel ecosystem | Solid in computer vision domain | IoT and edge with Intel hardware | Regular updates for Intel hardware | Robust features for sensitive applications | Tailored for Intel hardware | +| TensorRT | Top-tier on NVIDIA GPUs | Best for NVIDIA hardware | Strong network through NVIDIA | Real-time video and image inference | Frequent updates for new GPUs | Emphasis on security | Designed for NVIDIA GPUs | +| CoreML | Optimized for on-device Apple hardware | Exclusive to Apple ecosystem | Strong Apple and developer support | On-device ML on Apple products | Regular Apple updates | Focus on privacy and security | Apple neural engine and GPU | +| TF SavedModel | Scalable in server environments | Wide compatibility in TensorFlow ecosystem | Large support due to TensorFlow popularity | Serving models at scale | Regular updates by Google and community | Robust features for enterprise | Various hardware accelerations | +| TF GraphDef | Stable for static computation graphs | Integrates well with TensorFlow infrastructure | Resources for optimizing static graphs | Scenarios requiring static graphs | Updates alongside TensorFlow core | Established TensorFlow security practices | TensorFlow acceleration options | +| TF Lite | Speed and efficiency on mobile/embedded | Wide range of device support | Robust community, Google backed | Mobile applications with minimal footprint | Latest features for mobile | Secure environment on end-user devices | GPU and DSP among others | +| TF Edge TPU | Optimized for Google's Edge TPU hardware | Exclusive to Edge TPU devices | Growing with Google and third-party resources | IoT devices requiring real-time processing | Improvements for new Edge TPU hardware | Google's robust IoT security | Custom-designed for Google Coral | +| TF.js | Reasonable in-browser performance | High with web technologies | Web and Node.js developers support | Interactive web applications | TensorFlow team and community contributions | Web platform security model | Enhanced with WebGL and other APIs | +| PaddlePaddle | Competitive, easy to use and scalable | Baidu ecosystem, wide application support | Rapidly growing, especially in China | Chinese market and language processing | Focus on Chinese AI applications | Emphasizes data privacy and security | Including Baidu's Kunlun chips | +| ncnn | Optimized for mobile ARM-based devices | Mobile and embedded ARM systems | Niche but active mobile/embedded ML community | Android and ARM systems efficiency | High performance maintenance on ARM | On-device security advantages | ARM CPUs and GPUs optimizations | + +This comparative analysis gives you a high-level overview. For deployment, it's essential to consider the specific requirements and constraints of your project, and consult the detailed documentation and resources available for each option. + +## Community and Support + +When you're getting started with YOLOv8, having a helpful community and support can make a significant impact. Here's how to connect with others who share your interests and get the assistance you need. + +### Engage with the Broader Community + +- **GitHub Discussions:** The YOLOv8 repository on GitHub has a "Discussions" section where you can ask questions, report issues, and suggest improvements. + +- **Ultralytics Discord Server:** Ultralytics has a [Discord server](https://ultralytics.com/discord/) where you can interact with other users and developers. + +### Official Documentation and Resources + +- **Ultralytics YOLOv8 Docs:** The [official documentation](https://docs.ultralytics.com/) provides a comprehensive overview of YOLOv8, along with guides on installation, usage, and troubleshooting. + +These resources will help you tackle challenges and stay updated on the latest trends and best practices in the YOLOv8 community. + +## Conclusion + +In this guide, we've explored the different deployment options for YOLOv8. We've also discussed the important factors to consider when making your choice. These options allow you to customize your model for various environments and performance requirements, making it suitable for real-world applications. + +Don't forget that the YOLOv8 and Ultralytics community is a valuable source of help. Connect with other developers and experts to learn unique tips and solutions you might not find in regular documentation. Keep seeking knowledge, exploring new ideas, and sharing your experiences. + +Happy deploying! diff --git a/ultralytics/docs/guides/raspberry-pi.md b/ultralytics/docs/guides/raspberry-pi.md new file mode 100644 index 0000000000000000000000000000000000000000..389db0df4b8545f79ee59b4b9910f5bf7c59bd2b --- /dev/null +++ b/ultralytics/docs/guides/raspberry-pi.md @@ -0,0 +1,196 @@ +--- +comments: true +description: Quick start guide to setting up YOLO on a Raspberry Pi with a Pi Camera using the libcamera stack. Detailed comparison between Raspberry Pi 3, 4 and 5 models. +keywords: Ultralytics, YOLO, Raspberry Pi, Pi Camera, libcamera, quick start guide, Raspberry Pi 4 vs Raspberry Pi 5, YOLO on Raspberry Pi, hardware setup, machine learning, AI +--- + +# Quick Start Guide: Raspberry Pi and Pi Camera with YOLOv5 and YOLOv8 + +This comprehensive guide aims to expedite your journey with YOLO object detection models on a [Raspberry Pi](https://www.raspberrypi.com/) using a [Pi Camera](https://www.raspberrypi.com/products/camera-module-v2/). Whether you're a student, hobbyist, or a professional, this guide is designed to get you up and running in less than 30 minutes. The instructions here are rigorously tested to minimize setup issues, allowing you to focus on utilizing YOLO for your specific projects. + +
+
+
+
+ Watch: Raspberry Pi 5 updates and improvements.
+
+ +
+ +## Introduction to SAHI + +SAHI (Slicing Aided Hyper Inference) is an innovative library designed to optimize object detection algorithms for large-scale and high-resolution imagery. Its core functionality lies in partitioning images into manageable slices, running object detection on each slice, and then stitching the results back together. SAHI is compatible with a range of object detection models, including the YOLO series, thereby offering flexibility while ensuring optimized use of computational resources. + +### Key Features of SAHI + +- **Seamless Integration**: SAHI integrates effortlessly with YOLO models, meaning you can start slicing and detecting without a lot of code modification. +- **Resource Efficiency**: By breaking down large images into smaller parts, SAHI optimizes the memory usage, allowing you to run high-quality detection on hardware with limited resources. +- **High Accuracy**: SAHI maintains the detection accuracy by employing smart algorithms to merge overlapping detection boxes during the stitching process. + +## What is Sliced Inference? + +Sliced Inference refers to the practice of subdividing a large or high-resolution image into smaller segments (slices), conducting object detection on these slices, and then recompiling the slices to reconstruct the object locations on the original image. This technique is invaluable in scenarios where computational resources are limited or when working with extremely high-resolution images that could otherwise lead to memory issues. + +### Benefits of Sliced Inference + +- **Reduced Computational Burden**: Smaller image slices are faster to process, and they consume less memory, enabling smoother operation on lower-end hardware. + +- **Preserved Detection Quality**: Since each slice is treated independently, there is no reduction in the quality of object detection, provided the slices are large enough to capture the objects of interest. + +- **Enhanced Scalability**: The technique allows for object detection to be more easily scaled across different sizes and resolutions of images, making it ideal for a wide range of applications from satellite imagery to medical diagnostics. + +YOLOv8 without SAHI | +YOLOv8 with SAHI | +
---|---|
+ | + |
+
+
+
+ Watch: Getting Started with NVIDIA Triton Inference Server.
+
+ +
+ +## Introduction + +This guide serves as a comprehensive aid for troubleshooting common issues encountered while working with YOLOv8 on your Ultralytics projects. Navigating through these issues can be a breeze with the right guidance, ensuring your projects remain on track without unnecessary delays. + +## Common Issues + +### Installation Errors + +Installation errors can arise due to various reasons, such as incompatible versions, missing dependencies, or incorrect environment setups. First, check to make sure you are doing the following: + +- You're using Python 3.8 or later as recommended. + +- Ensure that you have the correct version of PyTorch (1.8 or later) installed. + +- Consider using virtual environments to avoid conflicts. + +- Follow the [official installation guide](https://docs.ultralytics.com/quickstart/) step by step. + +Additionally, here are some common installation issues users have encountered, along with their respective solutions: + +- Import Errors or Dependency Issues - If you're getting errors during the import of YOLOv8, or you're having issues related to dependencies, consider the following troubleshooting steps: + + - **Fresh Installation**: Sometimes, starting with a fresh installation can resolve unexpected issues. Especially with libraries like Ultralytics, where updates might introduce changes to the file tree structure or functionalities. + + - **Update Regularly**: Ensure you're using the latest version of the library. Older versions might not be compatible with recent updates, leading to potential conflicts or issues. + + - **Check Dependencies**: Verify that all required dependencies are correctly installed and are of the compatible versions. + + - **Review Changes**: If you initially cloned or installed an older version, be aware that significant updates might affect the library's structure or functionalities. Always refer to the official documentation or changelogs to understand any major changes. + + - Remember, keeping your libraries and dependencies up-to-date is crucial for a smooth and error-free experience. + +- Running YOLOv8 on GPU - If you're having trouble running YOLOv8 on GPU, consider the following troubleshooting steps: + + - **Verify CUDA Compatibility and Installation**: Ensure your GPU is CUDA compatible and that CUDA is correctly installed. Use the `nvidia-smi` command to check the status of your NVIDIA GPU and CUDA version. + + - **Check PyTorch and CUDA Integration**: Ensure PyTorch can utilize CUDA by running `import torch; print(torch.cuda.is_available())` in a Python terminal. If it returns 'True', PyTorch is set up to use CUDA. + + - **Environment Activation**: Ensure you're in the correct environment where all necessary packages are installed. + + - **Update Your Packages**: Outdated packages might not be compatible with your GPU. Keep them updated. + + - **Program Configuration**: Check if the program or code specifies GPU usage. In YOLOv8, this might be in the settings or configuration. + +### Model Training Issues + +This section will address common issues faced while training and their respective explanations and solutions. + +#### Verification of Configuration Settings + +**Issue**: You are unsure whether the configuration settings in the `.yaml` file are being applied correctly during model training. + +**Solution**: The configuration settings in the `.yaml` file should be applied when using the `model.train()` function. To ensure that these settings are correctly applied, follow these steps: + +- Confirm that the path to your `.yaml` configuration file is correct. +- Make sure you pass the path to your `.yaml` file as the `data` argument when calling `model.train()`, as shown below: + +```python +model.train(data='/path/to/your/data.yaml', batch=4) +``` + +#### Accelerating Training with Multiple GPUs + +**Issue**: Training is slow on a single GPU, and you want to speed up the process using multiple GPUs. + +**Solution**: Increasing the batch size can accelerate training, but it's essential to consider GPU memory capacity. To speed up training with multiple GPUs, follow these steps: + +- Ensure that you have multiple GPUs available. + +- Modify your .yaml configuration file to specify the number of GPUs to use, e.g., gpus: 4. + +- Increase the batch size accordingly to fully utilize the multiple GPUs without exceeding memory limits. + +- Modify your training command to utilize multiple GPUs: + +```python +# Adjust the batch size and other settings as needed to optimize training speed +model.train(data='/path/to/your/data.yaml', batch=32, multi_scale=True) +``` + +#### Continuous Monitoring Parameters + +**Issue**: You want to know which parameters should be continuously monitored during training, apart from loss. + +**Solution**: While loss is a crucial metric to monitor, it's also essential to track other metrics for model performance optimization. Some key metrics to monitor during training include: + +- Precision +- Recall +- Mean Average Precision (mAP) + +You can access these metrics from the training logs or by using tools like TensorBoard or wandb for visualization. Implementing early stopping based on these metrics can help you achieve better results. + +#### Tools for Tracking Training Progress + +**Issue**: You are looking for recommendations on tools to track training progress. + +**Solution**: To track and visualize training progress, you can consider using the following tools: + +- [TensorBoard](https://www.tensorflow.org/tensorboard): TensorBoard is a popular choice for visualizing training metrics, including loss, accuracy, and more. You can integrate it with your YOLOv8 training process. +- [Comet](https://bit.ly/yolov8-readme-comet): Comet provides an extensive toolkit for experiment tracking and comparison. It allows you to track metrics, hyperparameters, and even model weights. Integration with YOLO models is also straightforward, providing you with a complete overview of your experiment cycle. +- [Ultralytics HUB](https://hub.ultralytics.com): Ultralytics HUB offers a specialized environment for tracking YOLO models, giving you a one-stop platform to manage metrics, datasets, and even collaborate with your team. Given its tailored focus on YOLO, it offers more customized tracking options. + +Each of these tools offers its own set of advantages, so you may want to consider the specific needs of your project when making a choice. + +#### How to Check if Training is Happening on the GPU + +**Issue**: The 'device' value in the training logs is 'null,' and you're unsure if training is happening on the GPU. + +**Solution**: The 'device' value being 'null' typically means that the training process is set to automatically use an available GPU, which is the default behavior. To ensure training occurs on a specific GPU, you can manually set the 'device' value to the GPU index (e.g., '0' for the first GPU) in your .yaml configuration file: + +```yaml +device: 0 +``` + +This will explicitly assign the training process to the specified GPU. If you wish to train on the CPU, set 'device' to 'cpu'. + +Keep an eye on the 'runs' folder for logs and metrics to monitor training progress effectively. + +#### Key Considerations for Effective Model Training + +Here are some things to keep in mind, if you are facing issues related to model training. + +**Dataset Format and Labels** + +- Importance: The foundation of any machine learning model lies in the quality and format of the data it is trained on. + +- Recommendation: Ensure that your custom dataset and its associated labels adhere to the expected format. It's crucial to verify that annotations are accurate and of high quality. Incorrect or subpar annotations can derail the model's learning process, leading to unpredictable outcomes. + +**Model Convergence** + +- Importance: Achieving model convergence ensures that the model has sufficiently learned from the training data. + +- Recommendation: When training a model 'from scratch', it's vital to ensure that the model reaches a satisfactory level of convergence. This might necessitate a longer training duration, with more epochs, compared to when you're fine-tuning an existing model. + +**Learning Rate and Batch Size** + +- Importance: These hyperparameters play a pivotal role in determining how the model updates its weights during training. + +- Recommendation: Regularly evaluate if the chosen learning rate and batch size are optimal for your specific dataset. Parameters that are not in harmony with the dataset's characteristics can hinder the model's performance. + +**Class Distribution** + +- Importance: The distribution of classes in your dataset can influence the model's prediction tendencies. + +- Recommendation: Regularly assess the distribution of classes within your dataset. If there's a class imbalance, there's a risk that the model will develop a bias towards the more prevalent class. This bias can be evident in the confusion matrix, where the model might predominantly predict the majority class. + +**Cross-Check with Pretrained Weights** + +- Importance: Leveraging pretrained weights can provide a solid starting point for model training, especially when data is limited. + +- Recommendation: As a diagnostic step, consider training your model using the same data but initializing it with pretrained weights. If this approach yields a well-formed confusion matrix, it could suggest that the 'from scratch' model might require further training or adjustments. + +### Issues Related to Model Predictions + +This section will address common issues faced during model prediction. + +#### Getting Bounding Box Predictions With Your YOLOv8 Custom Model + +**Issue**: When running predictions with a custom YOLOv8 model, there are challenges with the format and visualization of the bounding box coordinates. + +**Solution**: + +- Coordinate Format: YOLOv8 provides bounding box coordinates in absolute pixel values. To convert these to relative coordinates (ranging from 0 to 1), you need to divide by the image dimensions. For example, let’s say your image size is 640x640. Then you would do the following: + +```python +# Convert absolute coordinates to relative coordinates +x1 = x1 / 640 # Divide x-coordinates by image width +x2 = x2 / 640 +y1 = y1 / 640 # Divide y-coordinates by image height +y2 = y2 / 640 +``` + +- File Name: To obtain the file name of the image you're predicting on, access the image file path directly from the result object within your prediction loop. + +#### Filtering Objects in YOLOv8 Predictions + +**Issue**: Facing issues with how to filter and display only specific objects in the prediction results when running YOLOv8 using the Ultralytics library. + +**Solution**: To detect specific classes use the classes argument to specify the classes you want to include in the output. For instance, to detect only cars (assuming 'cars' have class index 2): + +```shell +yolo task=detect mode=segment model=yolov8n-seg.pt source='path/to/car.mp4' show=True classes=2 +``` + +#### Understanding Precision Metrics in YOLOv8 + +**Issue**: Confusion regarding the difference between box precision, mask precision, and confusion matrix precision in YOLOv8. + +**Solution**: Box precision measures the accuracy of predicted bounding boxes compared to the actual ground truth boxes using IoU (Intersection over Union) as the metric. Mask precision assesses the agreement between predicted segmentation masks and ground truth masks in pixel-wise object classification. Confusion matrix precision, on the other hand, focuses on overall classification accuracy across all classes and does not consider the geometric accuracy of predictions. It's important to note that a bounding box can be geometrically accurate (true positive) even if the class prediction is wrong, leading to differences between box precision and confusion matrix precision. These metrics evaluate distinct aspects of a model's performance, reflecting the need for different evaluation metrics in various tasks. + +#### Extracting Object Dimensions in YOLOv8 + +**Issue**: Difficulty in retrieving the length and height of detected objects in YOLOv8, especially when multiple objects are detected in an image. + +**Solution**: To retrieve the bounding box dimensions, first use the Ultralytics YOLOv8 model to predict objects in an image. Then, extract the width and height information of bounding boxes from the prediction results. + +```python +from ultralytics import YOLO + +# Load a pre-trained YOLOv8 model +model = YOLO('yolov8n.pt') + +# Specify the source image +source = 'https://ultralytics.com/images/bus.jpg' + +# Make predictions +results = model.predict(source, save=True, imgsz=320, conf=0.5) + +# Extract bounding box dimensions +boxes = results[0].boxes.xywh.cpu() +for box in boxes: + x, y, w, h = box + print(f"Width of Box: {w}, Height of Box: {h}") +``` + +### Deployment Challenges + +#### GPU Deployment Issues + +**Issue:** Deploying models in a multi-GPU environment can sometimes lead to unexpected behaviors like unexpected memory usage, inconsistent results across GPUs, etc. + +**Solution:** Check for default GPU initialization. Some frameworks, like PyTorch, might initialize CUDA operations on a default GPU before transitioning to the designated GPUs. To bypass unexpected default initializations, specify the GPU directly during deployment and prediction. Then, use tools to monitor GPU utilization and memory usage to identify any anomalies in real-time. Also, ensure you're using the latest version of the framework or library. + +#### Model Conversion/Exporting Issues + +**Issue:** During the process of converting or exporting machine learning models to different formats or platforms, users might encounter errors or unexpected behaviors. + +**Solution:** + +- Compatibility Check: Ensure that you are using versions of libraries and frameworks that are compatible with each other. Mismatched versions can lead to unexpected errors during conversion. + +- Environment Reset: If you're using an interactive environment like Jupyter or Colab, consider restarting your environment after making significant changes or installations. A fresh start can sometimes resolve underlying issues. + +- Official Documentation: Always refer to the official documentation of the tool or library you are using for conversion. It often contains specific guidelines and best practices for model exporting. + +- Community Support: Check the library or framework's official repository for similar issues reported by other users. The maintainers or community might have provided solutions or workarounds in discussion threads. + +- Update Regularly: Ensure that you are using the latest version of the tool or library. Developers frequently release updates that fix known bugs or improve functionality. + +- Test Incrementally: Before performing a full conversion, test the process with a smaller model or dataset to identify potential issues early on. + +## Community and Support + +Engaging with a community of like-minded individuals can significantly enhance your experience and success in working with YOLOv8. Below are some channels and resources you may find helpful. + +### Forums and Channels for Getting Help + +**GitHub Issues:** The YOLOv8 repository on GitHub has an [Issues tab](https://github.com/ultralytics/ultralytics/issues) where you can ask questions, report bugs, and suggest new features. The community and maintainers are active here, and it’s a great place to get help with specific problems. + +**Ultralytics Discord Server:** Ultralytics has a [Discord server](https://ultralytics.com/discord/) where you can interact with other users and the developers. + +### Official Documentation and Resources + +**Ultralytics YOLOv8 Docs**: The [official documentation](https://docs.ultralytics.com/) provides a comprehensive overview of YOLOv8, along with guides on installation, usage, and troubleshooting. + +These resources should provide a solid foundation for troubleshooting and improving your YOLOv8 projects, as well as connecting with others in the YOLOv8 community. + +## Conclusion + +Troubleshooting is an integral part of any development process, and being equipped with the right knowledge can significantly reduce the time and effort spent in resolving issues. This guide aimed to address the most common challenges faced by users of the YOLOv8 model within the Ultralytics ecosystem. By understanding and addressing these common issues, you can ensure smoother project progress and achieve better results with your computer vision tasks. + +Remember, the Ultralytics community is a valuable resource. Engaging with fellow developers and experts can provide additional insights and solutions that might not be covered in standard documentation. Always keep learning, experimenting, and sharing your experiences to contribute to the collective knowledge of the community. + +Happy troubleshooting! diff --git a/ultralytics/docs/guides/yolo-performance-metrics.md b/ultralytics/docs/guides/yolo-performance-metrics.md new file mode 100644 index 0000000000000000000000000000000000000000..1bd8ee39511f67c91158446d1f565fb9a2a5bdc1 --- /dev/null +++ b/ultralytics/docs/guides/yolo-performance-metrics.md @@ -0,0 +1,165 @@ +--- +comments: true +Description: A comprehensive guide on various performance metrics related to YOLOv8, their significance, and how to interpret them. +keywords: YOLOv8, Performance metrics, Object detection, Intersection over Union (IoU), Average Precision (AP), Mean Average Precision (mAP), Precision, Recall, Validation mode, Ultralytics +--- + +# Performance Metrics Deep Dive + +## Introduction + +Performance metrics are key tools to evaluate the accuracy and efficiency of object detection models. They shed light on how effectively a model can identify and localize objects within images. Additionally, they help in understanding the model's handling of false positives and false negatives. These insights are crucial for evaluating and enhancing the model's performance. In this guide, we will explore various performance metrics associated with YOLOv8, their significance, and how to interpret them. + +## Object Detection Metrics + +Let’s start by discussing some metrics that are not only important to YOLOv8 but are broadly applicable across different object detection models. + +- **Intersection over Union (IoU):** IoU is a measure that quantifies the overlap between a predicted bounding box and a ground truth bounding box. It plays a fundamental role in evaluating the accuracy of object localization. + +- **Average Precision (AP):** AP computes the area under the precision-recall curve, providing a single value that encapsulates the model's precision and recall performance. + +- **Mean Average Precision (mAP):** mAP extends the concept of AP by calculating the average AP values across multiple object classes. This is useful in multi-class object detection scenarios to provide a comprehensive evaluation of the model's performance. + +- **Precision and Recall:** Precision quantifies the proportion of true positives among all positive predictions, assessing the model's capability to avoid false positives. On the other hand, Recall calculates the proportion of true positives among all actual positives, measuring the model's ability to detect all instances of a class. + +- **F1 Score:** The F1 Score is the harmonic mean of precision and recall, providing a balanced assessment of a model's performance while considering both false positives and false negatives. + +## How to Calculate Metrics for YOLOv8 Model + +Now, we can explore [YOLOv8's Validation mode](https://docs.ultralytics.com/modes/val/) that can be used to compute the above discussed evaluation metrics. + +Using the validation mode is simple. Once you have a trained model, you can invoke the model.val() function. This function will then process the validation dataset and return a variety of performance metrics. But what do these metrics mean? And how should you interpret them? + +### Interpreting the Output + +Let's break down the output of the model.val() function and understand each segment of the output. + +#### Class-wise Metrics + +One of the sections of the output is the class-wise breakdown of performance metrics. This granular information is useful when you are trying to understand how well the model is doing for each specific class, especially in datasets with a diverse range of object categories. For each class in the dataset the following is provided: + +- **Class**: This denotes the name of the object class, such as "person", "car", or "dog". + +- **Images**: This metric tells you the number of images in the validation set that contain the object class. + +- **Instances**: This provides the count of how many times the class appears across all images in the validation set. + +- **Box(P, R, mAP50, mAP50-95)**: This metric provides insights into the model's performance in detecting objects: + + - **P (Precision)**: The accuracy of the detected objects, indicating how many detections were correct. + + - **R (Recall)**: The ability of the model to identify all instances of objects in the images. + + - **mAP50**: Mean average precision calculated at an intersection over union (IoU) threshold of 0.50. It's a measure of the model's accuracy considering only the "easy" detections. + + - **mAP50-95**: The average of the mean average precision calculated at varying IoU thresholds, ranging from 0.50 to 0.95. It gives a comprehensive view of the model's performance across different levels of detection difficulty. + +#### Speed Metrics + +The speed of inference can be as critical as accuracy, especially in real-time object detection scenarios. This section breaks down the time taken for various stages of the validation process, from preprocessing to post-processing. + +#### COCO Metrics Evaluation + +For users validating on the COCO dataset, additional metrics are calculated using the COCO evaluation script. These metrics give insights into precision and recall at different IoU thresholds and for objects of different sizes. + +#### Visual Outputs + +The model.val() function, apart from producing numeric metrics, also yields visual outputs that can provide a more intuitive understanding of the model's performance. Here's a breakdown of the visual outputs you can expect: + +- **F1 Score Curve (`F1_curve.png`)**: This curve represents the F1 score across various thresholds. Interpreting this curve can offer insights into the model's balance between false positives and false negatives over different thresholds. + +- **Precision-Recall Curve (`PR_curve.png`)**: An integral visualization for any classification problem, this curve showcases the trade-offs between precision and recall at varied thresholds. It becomes especially significant when dealing with imbalanced classes. + +- **Precision Curve (`P_curve.png`)**: A graphical representation of precision values at different thresholds. This curve helps in understanding how precision varies as the threshold changes. + +- **Recall Curve (`R_curve.png`)**: Correspondingly, this graph illustrates how the recall values change across different thresholds. + +- **Confusion Matrix (`confusion_matrix.png`)**: The confusion matrix provides a detailed view of the outcomes, showcasing the counts of true positives, true negatives, false positives, and false negatives for each class. + +- **Normalized Confusion Matrix (`confusion_matrix_normalized.png`)**: This visualization is a normalized version of the confusion matrix. It represents the data in proportions rather than raw counts. This format makes it simpler to compare the performance across classes. + +- **Validation Batch Labels (`val_batchX_labels.jpg`)**: These images depict the ground truth labels for distinct batches from the validation dataset. They provide a clear picture of what the objects are and their respective locations as per the dataset. + +- **Validation Batch Predictions (`val_batchX_pred.jpg`)**: Contrasting the label images, these visuals display the predictions made by the YOLOv8 model for the respective batches. By comparing these to the label images, you can easily assess how well the model detects and classifies objects visually. + +#### Results Storage + +For future reference, the results are saved to a directory, typically named runs/detect/val. + +## Choosing the Right Metrics + +Choosing the right metrics to evaluate often depends on the specific application. + +- **mAP:** Suitable for a broad assessment of model performance. + +- **IoU:** Essential when precise object location is crucial. + +- **Precision:** Important when minimizing false detections is a priority. + +- **Recall:** Vital when it's important to detect every instance of an object. + +- **F1 Score:** Useful when a balance between precision and recall is needed. + +For real-time applications, speed metrics like FPS (Frames Per Second) and latency are crucial to ensure timely results. + +## Interpretation of Results + +It’s important to understand the metrics. Here's what some of the commonly observed lower scores might suggest: + +- **Low mAP:** Indicates the model may need general refinements. + +- **Low IoU:** The model might be struggling to pinpoint objects accurately. Different bounding box methods could help. + +- **Low Precision:** The model may be detecting too many non-existent objects. Adjusting confidence thresholds might reduce this. + +- **Low Recall:** The model could be missing real objects. Improving feature extraction or using more data might help. + +- **Imbalanced F1 Score:** There's a disparity between precision and recall. + +- **Class-specific AP:** Low scores here can highlight classes the model struggles with. + +## Case Studies + +Real-world examples can help clarify how these metrics work in practice. + +### Case 1 + +- **Situation:** mAP and F1 Score are suboptimal, but while Recall is good, Precision isn't. + +- **Interpretation & Action:** There might be too many incorrect detections. Tightening confidence thresholds could reduce these, though it might also slightly decrease recall. + +### Case 2 + +- **Situation:** mAP and Recall are acceptable, but IoU is lacking. + +- **Interpretation & Action:** The model detects objects well but might not be localizing them precisely. Refining bounding box predictions might help. + +### Case 3 + +- **Situation:** Some classes have a much lower AP than others, even with a decent overall mAP. + +- **Interpretation & Action:** These classes might be more challenging for the model. Using more data for these classes or adjusting class weights during training could be beneficial. + +## Connect and Collaborate + +Tapping into a community of enthusiasts and experts can amplify your journey with YOLOv8. Here are some avenues that can facilitate learning, troubleshooting, and networking. + +### Engage with the Broader Community + +- **GitHub Issues:** The YOLOv8 repository on GitHub has an [Issues tab](https://github.com/ultralytics/ultralytics/issues) where you can ask questions, report bugs, and suggest new features. The community and maintainers are active here, and it’s a great place to get help with specific problems. + +- **Ultralytics Discord Server:** Ultralytics has a [Discord server](https://ultralytics.com/discord/) where you can interact with other users and the developers. + +### Official Documentation and Resources: + +- **Ultralytics YOLOv8 Docs:** The [official documentation](https://docs.ultralytics.com/) provides a comprehensive overview of YOLOv8, along with guides on installation, usage, and troubleshooting. + +Using these resources will not only guide you through any challenges but also keep you updated with the latest trends and best practices in the YOLOv8 community. + +## Conclusion + +In this guide, we've taken a close look at the essential performance metrics for YOLOv8. These metrics are key to understanding how well a model is performing and are vital for anyone aiming to fine-tune their models. They offer the necessary insights for improvements and to make sure the model works effectively in real-life situations. + +Remember, the YOLOv8 and Ultralytics community is an invaluable asset. Engaging with fellow developers and experts can open doors to insights and solutions not found in standard documentation. As you journey through object detection, keep the spirit of learning alive, experiment with new strategies, and share your findings. By doing so, you contribute to the community's collective wisdom and ensure its growth. + +Happy object detecting! diff --git a/ultralytics/docs/guides/yolo-thread-safe-inference.md b/ultralytics/docs/guides/yolo-thread-safe-inference.md new file mode 100644 index 0000000000000000000000000000000000000000..abf7a36198fe2402bec2358e516281afe4267804 --- /dev/null +++ b/ultralytics/docs/guides/yolo-thread-safe-inference.md @@ -0,0 +1,108 @@ +--- +comments: true +description: This guide provides best practices for performing thread-safe inference with YOLO models, ensuring reliable and concurrent predictions in multi-threaded applications. +keywords: thread-safe, YOLO inference, multi-threading, concurrent predictions, YOLO models, Ultralytics, Python threading, safe YOLO usage, AI concurrency +--- + +# Thread-Safe Inference with YOLO Models + +Running YOLO models in a multi-threaded environment requires careful consideration to ensure thread safety. Python's `threading` module allows you to run several threads concurrently, but when it comes to using YOLO models across these threads, there are important safety issues to be aware of. This page will guide you through creating thread-safe YOLO model inference. + +## Understanding Python Threading + +Python threads are a form of parallelism that allow your program to run multiple operations at once. However, Python's Global Interpreter Lock (GIL) means that only one thread can execute Python bytecode at a time. + ++ +
+ +While this sounds like a limitation, threads can still provide concurrency, especially for I/O-bound operations or when using operations that release the GIL, like those performed by YOLO's underlying C libraries. + +## The Danger of Shared Model Instances + +Instantiating a YOLO model outside your threads and sharing this instance across multiple threads can lead to race conditions, where the internal state of the model is inconsistently modified due to concurrent accesses. This is particularly problematic when the model or its components hold state that is not designed to be thread-safe. + +### Non-Thread-Safe Example: Single Model Instance + +When using threads in Python, it's important to recognize patterns that can lead to concurrency issues. Here is what you should avoid: sharing a single YOLO model instance across multiple threads. + +```python +# Unsafe: Sharing a single model instance across threads +from ultralytics import YOLO +from threading import Thread + +# Instantiate the model outside the thread +shared_model = YOLO("yolov8n.pt") + + +def predict(image_path): + results = shared_model.predict(image_path) + # Process results + + +# Starting threads that share the same model instance +Thread(target=predict, args=("image1.jpg",)).start() +Thread(target=predict, args=("image2.jpg",)).start() +``` + +In the example above, the `shared_model` is used by multiple threads, which can lead to unpredictable results because `predict` could be executed simultaneously by multiple threads. + +### Non-Thread-Safe Example: Multiple Model Instances + +Similarly, here is an unsafe pattern with multiple YOLO model instances: + +```python +# Unsafe: Sharing multiple model instances across threads can still lead to issues +from ultralytics import YOLO +from threading import Thread + +# Instantiate multiple models outside the thread +shared_model_1 = YOLO("yolov8n_1.pt") +shared_model_2 = YOLO("yolov8n_2.pt") + + +def predict(model, image_path): + results = model.predict(image_path) + # Process results + + +# Starting threads with individual model instances +Thread(target=predict, args=(shared_model_1, "image1.jpg")).start() +Thread(target=predict, args=(shared_model_2, "image2.jpg")).start() +``` + +Even though there are two separate model instances, the risk of concurrency issues still exists. If the internal implementation of `YOLO` is not thread-safe, using separate instances might not prevent race conditions, especially if these instances share any underlying resources or states that are not thread-local. + +## Thread-Safe Inference + +To perform thread-safe inference, you should instantiate a separate YOLO model within each thread. This ensures that each thread has its own isolated model instance, eliminating the risk of race conditions. + +### Thread-Safe Example + +Here's how to instantiate a YOLO model inside each thread for safe parallel inference: + +```python +# Safe: Instantiating a single model inside each thread +from ultralytics import YOLO +from threading import Thread + + +def thread_safe_predict(image_path): + # Instantiate a new model inside the thread + local_model = YOLO("yolov8n.pt") + results = local_model.predict(image_path) + # Process results + + +# Starting threads that each have their own model instance +Thread(target=thread_safe_predict, args=("image1.jpg",)).start() +Thread(target=thread_safe_predict, args=("image2.jpg",)).start() +``` + +In this example, each thread creates its own `YOLO` instance. This prevents any thread from interfering with the model state of another, thus ensuring that each thread performs inference safely and without unexpected interactions with the other threads. + +## Conclusion + +When using YOLO models with Python's `threading`, always instantiate your models within the thread that will use them to ensure thread safety. This practice avoids race conditions and makes sure that your inference tasks run reliably. + +For more advanced scenarios and to further optimize your multi-threaded inference performance, consider using process-based parallelism with `multiprocessing` or leveraging a task queue with dedicated worker processes. diff --git a/ultralytics/docs/help/CI.md b/ultralytics/docs/help/CI.md new file mode 100644 index 0000000000000000000000000000000000000000..60cd01e39123def77c61ad5f2327db4ff71d0475 --- /dev/null +++ b/ultralytics/docs/help/CI.md @@ -0,0 +1,61 @@ +--- +comments: true +description: Learn how Ultralytics leverages Continuous Integration (CI) for maintaining high-quality code. Explore our CI tests and the status of these tests for our repositories. +keywords: continuous integration, software development, CI tests, Ultralytics repositories, high-quality code, Docker Deployment, Broken Links, CodeQL, PyPi Publishing +--- + +# Continuous Integration (CI) + +Continuous Integration (CI) is an essential aspect of software development which involves integrating changes and testing them automatically. CI allows us to maintain high-quality code by catching issues early and often in the development process. At Ultralytics, we use various CI tests to ensure the quality and integrity of our codebase. + +## CI Actions + +Here's a brief description of our CI actions: + +- **CI:** This is our primary CI test that involves running unit tests, linting checks, and sometimes more comprehensive tests depending on the repository. +- **Docker Deployment:** This test checks the deployment of the project using Docker to ensure the Dockerfile and related scripts are working correctly. +- **Broken Links:** This test scans the codebase for any broken or dead links in our markdown or HTML files. +- **CodeQL:** CodeQL is a tool from GitHub that performs semantic analysis on our code, helping to find potential security vulnerabilities and maintain high-quality code. +- **PyPi Publishing:** This test checks if the project can be packaged and published to PyPi without any errors. + +### CI Results + +Below is the table showing the status of these CI tests for our main repositories: + +| Repository | CI | Docker Deployment | Broken Links | CodeQL | PyPi and Docs Publishing | +|-----------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| [yolov3](https://github.com/ultralytics/yolov3) | [![YOLOv3 CI](https://github.com/ultralytics/yolov3/actions/workflows/ci-testing.yml/badge.svg)](https://github.com/ultralytics/yolov3/actions/workflows/ci-testing.yml) | [![Publish Docker Images](https://github.com/ultralytics/yolov3/actions/workflows/docker.yml/badge.svg)](https://github.com/ultralytics/yolov3/actions/workflows/docker.yml) | [![Check Broken links](https://github.com/ultralytics/yolov3/actions/workflows/links.yml/badge.svg)](https://github.com/ultralytics/yolov3/actions/workflows/links.yml) | [![CodeQL](https://github.com/ultralytics/yolov3/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/ultralytics/yolov3/actions/workflows/codeql-analysis.yml) | | +| [yolov5](https://github.com/ultralytics/yolov5) | [![YOLOv5 CI](https://github.com/ultralytics/yolov5/actions/workflows/ci-testing.yml/badge.svg)](https://github.com/ultralytics/yolov5/actions/workflows/ci-testing.yml) | [![Publish Docker Images](https://github.com/ultralytics/yolov5/actions/workflows/docker.yml/badge.svg)](https://github.com/ultralytics/yolov5/actions/workflows/docker.yml) | [![Check Broken links](https://github.com/ultralytics/yolov5/actions/workflows/links.yml/badge.svg)](https://github.com/ultralytics/yolov5/actions/workflows/links.yml) | [![CodeQL](https://github.com/ultralytics/yolov5/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/ultralytics/yolov5/actions/workflows/codeql-analysis.yml) | | +| [ultralytics](https://github.com/ultralytics/ultralytics) | [![ultralytics CI](https://github.com/ultralytics/ultralytics/actions/workflows/ci.yaml/badge.svg)](https://github.com/ultralytics/ultralytics/actions/workflows/ci.yaml) | [![Publish Docker Images](https://github.com/ultralytics/ultralytics/actions/workflows/docker.yaml/badge.svg)](https://github.com/ultralytics/ultralytics/actions/workflows/docker.yaml) | [![Check Broken links](https://github.com/ultralytics/ultralytics/actions/workflows/links.yml/badge.svg)](https://github.com/ultralytics/ultralytics/actions/workflows/links.yml) | [![CodeQL](https://github.com/ultralytics/ultralytics/actions/workflows/codeql.yaml/badge.svg)](https://github.com/ultralytics/ultralytics/actions/workflows/codeql.yaml) | [![Publish to PyPI and Deploy Docs](https://github.com/ultralytics/ultralytics/actions/workflows/publish.yml/badge.svg)](https://github.com/ultralytics/ultralytics/actions/workflows/publish.yml) | +| [hub](https://github.com/ultralytics/hub) | [![HUB CI](https://github.com/ultralytics/hub/actions/workflows/ci.yaml/badge.svg)](https://github.com/ultralytics/hub/actions/workflows/ci.yaml) | | [![Check Broken links](https://github.com/ultralytics/hub/actions/workflows/links.yml/badge.svg)](https://github.com/ultralytics/hub/actions/workflows/links.yml) | | | +| [docs](https://github.com/ultralytics/docs) | | | [![Check Broken links](https://github.com/ultralytics/docs/actions/workflows/links.yml/badge.svg)](https://github.com/ultralytics/docs/actions/workflows/links.yml) | | [![pages-build-deployment](https://github.com/ultralytics/docs/actions/workflows/pages/pages-build-deployment/badge.svg)](https://github.com/ultralytics/docs/actions/workflows/pages/pages-build-deployment) | + +Each badge shows the status of the last run of the corresponding CI test on the `main` branch of the respective repository. If a test fails, the badge will display a "failing" status, and if it passes, it will display a "passing" status. + +If you notice a test failing, it would be a great help if you could report it through a GitHub issue in the respective repository. + +Remember, a successful CI test does not mean that everything is perfect. It is always recommended to manually review the code before deployment or merging changes. + +## Code Coverage + +Code coverage is a metric that represents the percentage of your codebase that is executed when your tests run. It provides insight into how well your tests exercise your code and can be crucial in identifying untested parts of your application. A high code coverage percentage is often associated with a lower likelihood of bugs. However, it's essential to understand that code coverage doesn't guarantee the absence of defects. It merely indicates which parts of the code have been executed by the tests. + +### Integration with [codecov.io](https://codecov.io/) + +At Ultralytics, we have integrated our repositories with [codecov.io](https://codecov.io/), a popular online platform for measuring and visualizing code coverage. Codecov provides detailed insights, coverage comparisons between commits, and visual overlays directly on your code, indicating which lines were covered. + +By integrating with Codecov, we aim to maintain and improve the quality of our code by focusing on areas that might be prone to errors or need further testing. + +### Coverage Results + +To quickly get a glimpse of the code coverage status of the `ultralytics` python package, we have included a badge and and sunburst visual of the `ultralytics` coverage results. These images show the percentage of code covered by our tests, offering an at-a-glance metric of our testing efforts. For full details please see https://codecov.io/github/ultralytics/ultralytics. + +| Repository | Code Coverage | +|-----------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------| +| [ultralytics](https://github.com/ultralytics/ultralytics) | [![codecov](https://codecov.io/gh/ultralytics/ultralytics/branch/main/graph/badge.svg?token=HHW7IIVFVY)](https://codecov.io/gh/ultralytics/ultralytics) | + +In the sunburst graphic below, the inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively. + + + + diff --git a/ultralytics/docs/help/CLA.md b/ultralytics/docs/help/CLA.md new file mode 100644 index 0000000000000000000000000000000000000000..b33b4880f5b95b35c00705d3560da005cfcd0057 --- /dev/null +++ b/ultralytics/docs/help/CLA.md @@ -0,0 +1,31 @@ +--- +description: Understand terms governing contributions to Ultralytics projects including source code, bug fixes, documentation and more. Read our Contributor License Agreement. +keywords: Ultralytics, Contributor License Agreement, Open Source Software, Contributions, Copyright License, Patent License, Moral Rights +--- + +# Ultralytics Individual Contributor License Agreement + +Thank you for your interest in contributing to open source software projects (“Projects”) made available by Ultralytics SE or its affiliates (“Ultralytics”). This Individual Contributor License Agreement (“Agreement”) sets out the terms governing any source code, object code, bug fixes, configuration changes, tools, specifications, documentation, data, materials, feedback, information or other works of authorship that you submit or have submitted, in any form and in any manner, to Ultralytics in respect of any of the Projects (collectively “Contributions”). If you have any questions respecting this Agreement, please contact hello@ultralytics.com. + +You agree that the following terms apply to all of your past, present and future Contributions. Except for the licenses granted in this Agreement, you retain all of your right, title and interest in and to your Contributions. + +**Copyright License.** You hereby grant, and agree to grant, to Ultralytics a non-exclusive, perpetual, irrevocable, worldwide, fully-paid, royalty-free, transferable copyright license to reproduce, prepare derivative works of, publicly display, publicly perform, and distribute your Contributions and such derivative works, with the right to sublicense the foregoing rights through multiple tiers of sublicensees. + +**Patent License.** You hereby grant, and agree to grant, to Ultralytics a non-exclusive, perpetual, irrevocable, worldwide, fully-paid, royalty-free, transferable patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer your Contributions, where such license applies only to those patent claims licensable by you that are necessarily infringed by your Contributions alone or by combination of your Contributions with the Project to which such Contributions were submitted, with the right to sublicense the foregoing rights through multiple tiers of sublicensees. + +**Moral Rights.** To the fullest extent permitted under applicable law, you hereby waive, and agree not to assert, all of your “moral rights” in or relating to your Contributions for the benefit of Ultralytics, its assigns, and their respective direct and indirect sublicensees. + +**Third Party Content/Rights. +** If your Contribution includes or is based on any source code, object code, bug fixes, configuration changes, tools, specifications, documentation, data, materials, feedback, information or other works of authorship that were not authored by you (“Third Party Content”) or if you are aware of any third party intellectual property or proprietary rights associated with your Contribution (“Third Party Rights”), then you agree to include with the submission of your Contribution full details respecting such Third Party Content and Third Party Rights, including, without limitation, identification of which aspects of your Contribution contain Third Party Content or are associated with Third Party Rights, the owner/author of the Third Party Content and Third Party Rights, where you obtained the Third Party Content, and any applicable third party license terms or restrictions respecting the Third Party Content and Third Party Rights. For greater certainty, the foregoing obligations respecting the identification of Third Party Content and Third Party Rights do not apply to any portion of a Project that is incorporated into your Contribution to that same Project. + +**Representations.** You represent that, other than the Third Party Content and Third Party Rights identified by you in accordance with this Agreement, you are the sole author of your Contributions and are legally entitled to grant the foregoing licenses and waivers in respect of your Contributions. If your Contributions were created in the course of your employment with your past or present employer(s), you represent that such employer(s) has authorized you to make your Contributions on behalf of such employer(s) or such employer +(s) has waived all of their right, title or interest in or to your Contributions. + +**Disclaimer.** To the fullest extent permitted under applicable law, your Contributions are provided on an "asis" +basis, without any warranties or conditions, express or implied, including, without limitation, any implied warranties or conditions of non-infringement, merchantability or fitness for a particular purpose. You are not required to provide support for your Contributions, except to the extent you desire to provide support. + +**No Obligation.** You acknowledge that Ultralytics is under no obligation to use or incorporate your Contributions into any of the Projects. The decision to use or incorporate your Contributions into any of the Projects will be made at the sole discretion of Ultralytics or its authorized delegates .. + +**Disputes.** This Agreement shall be governed by and construed in accordance with the laws of the State of New York, United States of America, without giving effect to its principles or rules regarding conflicts of laws, other than such principles directing application of New York law. The parties hereby submit to venue in, and jurisdiction of the courts located in New York, New York for purposes relating to this Agreement. In the event that any of the provisions of this Agreement shall be held by a court or other tribunal of competent jurisdiction to be unenforceable, the remaining portions hereof shall remain in full force and effect. + +**Assignment.** You agree that Ultralytics may assign this Agreement, and all of its rights, obligations and licenses hereunder. diff --git a/ultralytics/docs/help/FAQ.md b/ultralytics/docs/help/FAQ.md new file mode 100644 index 0000000000000000000000000000000000000000..8e4430a80aad054e7b658af5bb979d505598dfaa --- /dev/null +++ b/ultralytics/docs/help/FAQ.md @@ -0,0 +1,39 @@ +--- +comments: true +description: Find solutions to your common Ultralytics YOLO related queries. Learn about hardware requirements, fine-tuning YOLO models, conversion to ONNX/TensorFlow, and more. +keywords: Ultralytics, YOLO, FAQ, hardware requirements, ONNX, TensorFlow, real-time detection, YOLO accuracy +--- + +# Ultralytics YOLO Frequently Asked Questions (FAQ) + +This FAQ section addresses some common questions and issues users might encounter while working with Ultralytics YOLO repositories. + +## 1. What are the hardware requirements for running Ultralytics YOLO? + +Ultralytics YOLO can be run on a variety of hardware configurations, including CPUs, GPUs, and even some edge devices. However, for optimal performance and faster training and inference, we recommend using a GPU with a minimum of 8GB of memory. NVIDIA GPUs with CUDA support are ideal for this purpose. + +## 2. How do I fine-tune a pre-trained YOLO model on my custom dataset? + +To fine-tune a pre-trained YOLO model on your custom dataset, you'll need to create a dataset configuration file (YAML) that defines the dataset's properties, such as the path to the images, the number of classes, and class names. Next, you'll need to modify the model configuration file to match the number of classes in your dataset. Finally, use the `train.py` script to start the training process with your custom dataset and the pre-trained model. You can find a detailed guide on fine-tuning YOLO in the Ultralytics documentation. + +## 3. How do I convert a YOLO model to ONNX or TensorFlow format? + +Ultralytics provides built-in support for converting YOLO models to ONNX format. You can use the `export.py` script to convert a saved model to ONNX format. If you need to convert the model to TensorFlow format, you can use the ONNX model as an intermediary and then use the ONNX-TensorFlow converter to convert the ONNX model to TensorFlow format. + +## 4. Can I use Ultralytics YOLO for real-time object detection? + +Yes, Ultralytics YOLO is designed to be efficient and fast, making it suitable for real-time object detection tasks. The actual performance will depend on your hardware configuration and the complexity of the model. Using a GPU and optimizing the model for your specific use case can help achieve real-time performance. + +## 5. How can I improve the accuracy of my YOLO model? + +Improving the accuracy of a YOLO model may involve several strategies, such as: + +- Fine-tuning the model on more annotated data +- Data augmentation to increase the variety of training samples +- Using a larger or more complex model architecture +- Adjusting the learning rate, batch size, and other hyperparameters +- Using techniques like transfer learning or knowledge distillation + +Remember that there's often a trade-off between accuracy and inference speed, so finding the right balance is crucial for your specific application. + +If you have any more questions or need assistance, don't hesitate to consult the Ultralytics documentation or reach out to the community through GitHub Issues or the official discussion forum. diff --git a/ultralytics/docs/help/code_of_conduct.md b/ultralytics/docs/help/code_of_conduct.md new file mode 100644 index 0000000000000000000000000000000000000000..c8c7cdc66ed90843164fbf40c3dfc63007feabd4 --- /dev/null +++ b/ultralytics/docs/help/code_of_conduct.md @@ -0,0 +1,88 @@ +--- +comments: true +description: Explore Ultralytics community’s Code of Conduct, ensuring a supportive, inclusive environment for contributors & members at all levels. Find our guidelines on acceptable behavior & enforcement. +keywords: Ultralytics, code of conduct, community, contribution, behavior guidelines, enforcement, open source contributions +--- + +# Ultralytics Contributor Covenant Code of Conduct + +## Our Pledge + +We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation. + +We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community. + +## Our Standards + +Examples of behavior that contributes to a positive environment for our community include: + +- Demonstrating empathy and kindness toward other people +- Being respectful of differing opinions, viewpoints, and experiences +- Giving and gracefully accepting constructive feedback +- Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience +- Focusing on what is best not just for us as individuals, but for the overall community + +Examples of unacceptable behavior include: + +- The use of sexualized language or imagery, and sexual attention or advances of any kind +- Trolling, insulting or derogatory comments, and personal or political attacks +- Public or private harassment +- Publishing others' private information, such as a physical or email address, without their explicit permission +- Other conduct which could reasonably be considered inappropriate in a professional setting + +## Enforcement Responsibilities + +Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful. + +Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate. + +## Scope + +This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at hello@ultralytics.com. All complaints will be reviewed and investigated promptly and fairly. + +All community leaders are obligated to respect the privacy and security of the reporter of any incident. + +## Enforcement Guidelines + +Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct: + +### 1. Correction + +**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community. + +**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested. + +### 2. Warning + +**Community Impact**: A violation through a single incident or series of actions. + +**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban. + +### 3. Temporary Ban + +**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior. + +**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban. + +### 4. Permanent Ban + +**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals. + +**Consequence**: A permanent ban from any sort of public interaction within the community. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0, available at +https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. + +Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity). + +For answers to common questions about this code of conduct, see the FAQ at +https://www.contributor-covenant.org/faq. Translations are available at +https://www.contributor-covenant.org/translations. + +[homepage]: https://www.contributor-covenant.org diff --git a/ultralytics/docs/help/contributing.md b/ultralytics/docs/help/contributing.md new file mode 100644 index 0000000000000000000000000000000000000000..b798e9c2010baac98df7111eeff87acc34c82d5b --- /dev/null +++ b/ultralytics/docs/help/contributing.md @@ -0,0 +1,76 @@ +--- +comments: true +description: Learn how to contribute to Ultralytics YOLO projects – guidelines for pull requests, reporting bugs, code conduct and CLA signing. +keywords: Ultralytics, YOLO, open-source, contribute, pull request, bug report, coding guidelines, CLA, code of conduct, GitHub +--- + +# Contributing to Ultralytics Open-Source YOLO Repositories + +First of all, thank you for your interest in contributing to Ultralytics open-source YOLO repositories! Your contributions will help improve the project and benefit the community. This document provides guidelines and best practices to get you started. + +## Table of Contents + +- [Code of Conduct](#code-of-conduct) +- [Pull Requests](#pull-requests) + - [CLA Signing](#cla-signing) + - [Google-Style Docstrings](#google-style-docstrings) + - [GitHub Actions CI Tests](#github-actions-ci-tests) +- [Bug Reports](#bug-reports) + - [Minimum Reproducible Example](#minimum-reproducible-example) +- [License and Copyright](#license-and-copyright) + +## Code of Conduct + +All contributors are expected to adhere to the [Code of Conduct](code_of_conduct.md) to ensure a welcoming and inclusive environment for everyone. + +## Pull Requests + +We welcome contributions in the form of pull requests. To make the review process smoother, please follow these guidelines: + +1. **Fork the repository**: Fork the Ultralytics YOLO repository to your own GitHub account. + +2. **Create a branch**: Create a new branch in your forked repository with a descriptive name for your changes. + +3. **Make your changes**: Make the changes you want to contribute. Ensure that your changes follow the coding style of the project and do not introduce new errors or warnings. + +4. **Test your changes**: Test your changes locally to ensure that they work as expected and do not introduce new issues. + +5. **Commit your changes**: Commit your changes with a descriptive commit message. Make sure to include any relevant issue numbers in your commit message. + +6. **Create a pull request**: Create a pull request from your forked repository to the main Ultralytics YOLO repository. In the pull request description, provide a clear explanation of your changes and how they improve the project. + +### CLA Signing + +Before we can accept your pull request, you need to sign a [Contributor License Agreement (CLA)](CLA.md). This is a legal document stating that you agree to the terms of contributing to the Ultralytics YOLO repositories. The CLA 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. + +### Google-Style Docstrings + +When adding new functions or classes, please include a [Google-style docstring](https://google.github.io/styleguide/pyguide.html) to provide clear and concise documentation for other developers. This will help ensure that your contributions are easy to understand and maintain. + +Example Google-style docstring: + +```python +def example_function(arg1: int, arg2: int) -> bool: + """ + Example function that demonstrates Google-style docstrings. + + Args: + arg1 (int): The first argument. + arg2 (int): The second argument. + + Returns: + (bool): True if successful, False otherwise. + + Examples: + >>> result = example_function(1, 2) # returns False + """ + if arg1 == arg2: + return True + return False +``` + +### GitHub Actions CI Tests + +Before your pull request can be merged, all GitHub Actions Continuous Integration (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 diff --git a/ultralytics/docs/help/environmental-health-safety.md b/ultralytics/docs/help/environmental-health-safety.md new file mode 100644 index 0000000000000000000000000000000000000000..9fee240b48f94a00e3af36f96bd8f1ef4a92214e --- /dev/null +++ b/ultralytics/docs/help/environmental-health-safety.md @@ -0,0 +1,37 @@ +--- +comments: false +description: Discover Ultralytics’ EHS policy principles and implementation measures. Committed to safety, environment, and continuous improvement for a sustainable future. +keywords: Ultralytics policy, EHS, environment, health and safety, compliance, prevention, continuous improvement, risk management, emergency preparedness, resource allocation, communication +--- + +# Ultralytics Environmental, Health and Safety (EHS) Policy + +At Ultralytics, we recognize that the long-term success of our company relies not only on the products and services we offer, but also the manner in which we conduct our business. We are committed to ensuring the safety and well-being of our employees, stakeholders, and the environment, and we will continuously strive to mitigate our impact on the environment while promoting health and safety. + +## Policy Principles + +1. **Compliance**: We will comply with all applicable laws, regulations, and standards related to EHS, and we will strive to exceed these standards where possible. + +2. **Prevention**: We will work to prevent accidents, injuries, and environmental harm by implementing risk management measures and ensuring all our operations and procedures are safe. + +3. **Continuous Improvement**: We will continuously improve our EHS performance by setting measurable objectives, monitoring our performance, auditing our operations, and revising our policies and procedures as needed. + +4. **Communication**: We will communicate openly about our EHS performance and will engage with stakeholders to understand and address their concerns and expectations. + +5. **Education and Training**: We will educate and train our employees and contractors in appropriate EHS procedures and practices. + +## Implementation Measures + +1. **Responsibility and Accountability**: Every employee and contractor working at or with Ultralytics is responsible for adhering to this policy. Managers and supervisors are accountable for ensuring this policy is implemented within their areas of control. + +2. **Risk Management**: We will identify, assess, and manage EHS risks associated with our operations and activities to prevent accidents, injuries, and environmental harm. + +3. **Resource Allocation**: We will allocate the necessary resources to ensure the effective implementation of our EHS policy, including the necessary equipment, personnel, and training. + +4. **Emergency Preparedness and Response**: We will develop, maintain, and test emergency preparedness and response plans to ensure we can respond effectively to EHS incidents. + +5. **Monitoring and Review**: We will monitor and review our EHS performance regularly to identify opportunities for improvement and ensure we are meeting our objectives. + +This policy reflects our commitment to minimizing our environmental footprint, ensuring the safety and well-being of our employees, and continuously improving our performance. + +Please remember that the implementation of an effective EHS policy requires the involvement and commitment of everyone working at or with Ultralytics. We encourage you to take personal responsibility for your safety and the safety of others, and to take care of the environment in which we live and work. diff --git a/ultralytics/docs/help/index.md b/ultralytics/docs/help/index.md new file mode 100644 index 0000000000000000000000000000000000000000..a64b60cccc333bf0236bddc77897e258b41ed42b --- /dev/null +++ b/ultralytics/docs/help/index.md @@ -0,0 +1,19 @@ +--- +comments: true +description: Find comprehensive guides and documents on Ultralytics YOLO tasks. Includes FAQs, contributing guides, CI guide, CLA, MRE guide, code of conduct & more. +keywords: Ultralytics, YOLO, guides, documents, FAQ, contributing, CI guide, CLA, MRE guide, code of conduct, EHS policy, security policy, privacy policy +--- + +Welcome to the Ultralytics Help page! We are dedicated to providing you with detailed resources to enhance your experience with the Ultralytics YOLO models and repositories. This page serves as your portal to guides and documentation designed to assist you with various tasks and answer questions you may encounter while engaging with our repositories. + +- [Frequently Asked Questions (FAQ)](FAQ.md): Find answers to common questions and issues encountered by the community of Ultralytics YOLO users and contributors. +- [Contributing Guide](contributing.md): Discover the protocols for making contributions, including how to submit pull requests, report bugs, and more. +- [Continuous Integration (CI) Guide](CI.md): Gain insights into the CI processes we employ, complete with status reports for each Ultralytics repository. +- [Contributor License Agreement (CLA)](CLA.md): Review the CLA to understand the rights and responsibilities associated with contributing to Ultralytics projects. +- [Minimum Reproducible Example (MRE) Guide](minimum_reproducible_example.md): Learn the process for creating an MRE, which is crucial for the timely and effective resolution of bug reports. +- [Code of Conduct](code_of_conduct.md): Our community guidelines support a respectful and open atmosphere for all collaborators. +- [Environmental, Health and Safety (EHS) Policy](environmental-health-safety.md): Delve into our commitment to sustainability and the well-being of all our stakeholders. +- [Security Policy](../SECURITY.md): Familiarize yourself with our security protocols and the procedure for reporting vulnerabilities. +- [Privacy Policy](privacy.md): Read our privacy policy to understand how we protect your data and respect your privacy in all our services and operations. + +We encourage you to review these resources for a seamless and productive experience. Our aim is to foster a helpful and friendly environment for everyone in the Ultralytics community. Should you require additional support, please feel free to reach out via GitHub Issues or our official discussion forums. Happy coding! diff --git a/ultralytics/docs/help/minimum_reproducible_example.md b/ultralytics/docs/help/minimum_reproducible_example.md new file mode 100644 index 0000000000000000000000000000000000000000..47a0cdf0e736070a274fdc7b9899d5f3ea8c4cdd --- /dev/null +++ b/ultralytics/docs/help/minimum_reproducible_example.md @@ -0,0 +1,78 @@ +--- +comments: true +description: Learn how to create minimum reproducible examples (MRE) for efficient bug reporting in Ultralytics YOLO repositories with this step-by-step guide. +keywords: Ultralytics, YOLO, minimum reproducible example, MRE, bug reports, guide, dependencies, code, troubleshooting +--- + +# Creating a Minimum Reproducible Example for Bug Reports in Ultralytics YOLO Repositories + +When submitting a bug report for Ultralytics YOLO repositories, it's essential to provide a [minimum reproducible example](https://docs.ultralytics.com/help/minimum_reproducible_example/) (MRE). An MRE is a small, self-contained piece of code that demonstrates the problem you're experiencing. Providing an MRE helps maintainers and contributors understand the issue and work on a fix more efficiently. This guide explains how to create an MRE when submitting bug reports to Ultralytics YOLO repositories. + +## 1. Isolate the Problem + +The first step in creating an MRE is to isolate the problem. This means removing any unnecessary code or dependencies that are not directly related to the issue. Focus on the specific part of the code that is causing the problem and remove any irrelevant code. + +## 2. Use Public Models and Datasets + +When creating an MRE, use publicly available models and datasets to reproduce the issue. For example, use the 'yolov8n.pt' model and the 'coco8.yaml' dataset. This ensures that the maintainers and contributors can easily run your example and investigate the problem without needing access to proprietary data or custom models. + +## 3. Include All Necessary Dependencies + +Make sure to include all the necessary dependencies in your MRE. If your code relies on external libraries, specify the required packages and their versions. Ideally, provide a `requirements.txt` file or list the dependencies in your bug report. + +## 4. Write a Clear Description of the Issue + +Provide a clear and concise description of the issue you're experiencing. Explain the expected behavior and the actual behavior you're encountering. If applicable, include any relevant error messages or logs. + +## 5. Format Your Code Properly + +When submitting an MRE, format your code properly using code blocks in the issue description. This makes it easier for others to read and understand your code. In GitHub, you can create a code block by wrapping your code with triple backticks (\```) and specifying the language: + ++```python +# Your Python code goes here +``` ++ +## 6. Test Your MRE + +Before submitting your MRE, test it to ensure that it accurately reproduces the issue. Make sure that others can run your example without any issues or modifications. + +## Example of an MRE + +Here's an example of an MRE for a hypothetical bug report: + +**Bug description:** + +When running the `detect.py` script on the sample image from the 'coco8.yaml' dataset, I get an error related to the dimensions of the input tensor. + +**MRE:** + +```python +import torch +from ultralytics import YOLO + +# Load the model +model = YOLO("yolov8n.pt") + +# Load a 0-channel image +image = torch.rand(1, 0, 640, 640) + +# Run the model +results = model(image) +``` + +**Error message:** + +``` +RuntimeError: Expected input[1, 0, 640, 640] to have 3 channels, but got 0 channels instead +``` + +**Dependencies:** + +- torch==2.0.0 +- ultralytics==8.0.90 + +In this example, the MRE demonstrates the issue with a minimal amount of code, uses a public model ('yolov8n.pt'), includes all necessary dependencies, and provides a clear description of the problem along with the error message. + +By following these guidelines, you'll help the maintainers and contributors of Ultralytics YOLO repositories to understand and resolve your issue more efficiently. diff --git a/ultralytics/docs/help/privacy.md b/ultralytics/docs/help/privacy.md new file mode 100644 index 0000000000000000000000000000000000000000..dfd8137ef562ca0a6f5422854b77950dfde425b2 --- /dev/null +++ b/ultralytics/docs/help/privacy.md @@ -0,0 +1,137 @@ +--- +description: Learn about how Ultralytics collects and uses data to improve user experience, ensure software stability, and address privacy concerns, with options to opt-out. +keywords: Ultralytics, Data Collection, User Privacy, Google Analytics, Sentry, Crash Reporting, Anonymized Data, Privacy Settings, Opt-Out +--- + +# Data Collection for Ultralytics Python Package + +## Overview + +[Ultralytics](https://ultralytics.com) is dedicated to the continuous enhancement of the user experience and the capabilities of our Python package, including the advanced YOLO models we develop. Our approach involves the gathering of anonymized usage statistics and crash reports, helping us identify opportunities for improvement and ensuring the reliability of our software. This transparency document outlines what data we collect, its purpose, and the choice you have regarding this data collection. + +## Anonymized Google Analytics + +[Google Analytics](https://developers.google.com/analytics) is a web analytics service offered by Google that tracks and reports website traffic. It allows us to collect data about how our Python package is used, which is crucial for making informed decisions about design and functionality. + +### What We Collect + +- **Usage Metrics**: These metrics help us understand how frequently and in what ways the package is utilized, what features are favored, and the typical command-line arguments that are used. +- **System Information**: We collect general non-identifiable information about your computing environment to ensure our package performs well across various systems. +- **Performance Data**: Understanding the performance of our models during training, validation, and inference helps us in identifying optimization opportunities. + +For more information about Google Analytics and data privacy, visit [Google Analytics Privacy](https://support.google.com/analytics/answer/6004245). + +### How We Use This Data + +- **Feature Improvement**: Insights from usage metrics guide us in enhancing user satisfaction and interface design. +- **Optimization**: Performance data assist us in fine-tuning our models for better efficiency and speed across diverse hardware and software configurations. +- **Trend Analysis**: By studying usage trends, we can predict and respond to the evolving needs of our community. + +### Privacy Considerations + +We take several measures to ensure the privacy and security of the data you entrust to us: + +- **Anonymization**: We configure Google Analytics to anonymize the data collected, which means no personally identifiable information (PII) is gathered. You can use our services with the assurance that your personal details remain private. +- **Aggregation**: Data is analyzed only in aggregate form. This practice ensures that patterns can be observed without revealing any individual user's activity. +- **No Image Data Collection**: Ultralytics does not collect, process, or view any training or inference images. + +## Sentry Crash Reporting + +[Sentry](https://sentry.io/) is a developer-centric error tracking software that aids in identifying, diagnosing, and resolving issues in real-time, ensuring the robustness and reliability of applications. Within our package, it plays a crucial role by providing insights through crash reporting, significantly contributing to the stability and ongoing refinement of our software. + +!!! note + + Crash reporting via Sentry is activated only if the `sentry-sdk` Python package is pre-installed on your system. This package isn't included in the `ultralytics` prerequisites and won't be installed automatically by Ultralytics. + +### What We Collect + +If the `sentry-sdk` Python package is pre-installed on your system a crash event may send the following information: + +- **Crash Logs**: Detailed reports on the application's condition at the time of a crash, which are vital for our debugging efforts. +- **Error Messages**: We record error messages generated during the operation of our package to understand and resolve potential issues quickly. + +To learn more about how Sentry handles data, please visit [Sentry's Privacy Policy](https://sentry.io/privacy/). + +### How We Use This Data + +- **Debugging**: Analyzing crash logs and error messages enables us to swiftly identify and correct software bugs. +- **Stability Metrics**: By constantly monitoring for crashes, we aim to improve the stability and reliability of our package. + +### Privacy Considerations + +- **Sensitive Information**: We ensure that crash logs are scrubbed of any personally identifiable or sensitive user data, safeguarding the confidentiality of your information. +- **Controlled Collection**: Our crash reporting mechanism is meticulously calibrated to gather only what is essential for troubleshooting while respecting user privacy. + +By detailing the tools used for data collection and offering additional background information with URLs to their respective privacy pages, users are provided with a comprehensive view of our practices, emphasizing transparency and respect for user privacy. + +## Disabling Data Collection + +We believe in providing our users with full control over their data. By default, our package is configured to collect analytics and crash reports to help improve the experience for all users. However, we respect that some users may prefer to opt out of this data collection. + +To opt out of sending analytics and crash reports, you can simply set `sync=False` in your YOLO settings. This ensures that no data is transmitted from your machine to our analytics tools. + +### Inspecting Settings + +To gain insight into the current configuration of your settings, you can view them directly: + +!!! example "View settings" + + === "Python" + You can use Python to view your settings. Start by importing the `settings` object from the `ultralytics` module. Print and return settings using the following commands: + ```python + from ultralytics import settings + + # View all settings + print(settings) + + # Return analytics and crash reporting setting + value = settings['sync'] + ``` + + === "CLI" + Alternatively, the command-line interface allows you to check your settings with a simple command: + ```bash + yolo settings + ``` + +### Modifying Settings + +Ultralytics allows users to easily modify their settings. Changes can be performed in the following ways: + +!!! example "Update settings" + + === "Python" + Within the Python environment, call the `update` method on the `settings` object to change your settings: + ```python + from ultralytics import settings + + # Disable analytics and crash reporting + settings.update({'sync': False}) + + # Reset settings to default values + settings.reset() + ``` + + === "CLI" + If you prefer using the command-line interface, the following commands will allow you to modify your settings: + ```bash + # Disable analytics and crash reporting + yolo settings sync=False + + # Reset settings to default values + yolo settings reset + ``` + +The `sync=False` setting will prevent any data from being sent to Google Analytics or Sentry. Your settings will be respected across all sessions using the Ultralytics package and saved to disk for future sessions. + +## Commitment to Privacy + +Ultralytics takes user privacy seriously. We design our data collection practices with the following principles: + +- **Transparency**: We are open about the data we collect and how it is used. +- **Control**: We give users full control over their data. +- **Security**: We employ industry-standard security measures to protect the data we collect. + +## Questions or Concerns + +If you have any questions or concerns about our data collection practices, please reach out to us via our [contact form](https://ultralytics.com/contact) or via [support@ultralytics.com](mailto:support@ultralytics.com). We are dedicated to ensuring our users feel informed and confident in their privacy when using our package. diff --git a/ultralytics/docs/hub/app/android.md b/ultralytics/docs/hub/app/android.md new file mode 100644 index 0000000000000000000000000000000000000000..e6acfaf5beb11cd77ca69ed80e61ac97eb2e6ef0 --- /dev/null +++ b/ultralytics/docs/hub/app/android.md @@ -0,0 +1,89 @@ +--- +comments: true +description: Learn about the Ultralytics Android App, enabling real-time object detection using YOLO models. Discover in-app features, quantization methods, and delegate options for optimal performance. +keywords: Ultralytics, Android App, real-time object detection, YOLO models, TensorFlow Lite, FP16 quantization, INT8 quantization, CPU, GPU, Hexagon, NNAPI +--- + +# Ultralytics Android App: Real-time Object Detection with YOLO Models + + + +
+ +
+ +The dataset YAML is the same standard YOLOv5 and YOLOv8 YAML format. + +!!! example "coco8.yaml" + + ```yaml + --8<-- "ultralytics/cfg/datasets/coco8.yaml" + ``` + +After zipping your dataset, you should validate it before uploading it to Ultralytics HUB. Ultralytics HUB conducts the dataset validation check post-upload, so by ensuring your dataset is correctly formatted and error-free ahead of time, you can forestall any setbacks due to dataset rejection. + +```py +from ultralytics.hub import check_dataset + +check_dataset('path/to/coco8.zip') +``` + +Once your dataset ZIP is ready, navigate to the [Datasets](https://hub.ultralytics.com/datasets) page by clicking on the **Datasets** button in the sidebar. + +![Ultralytics HUB screenshot of the Home page with an arrow pointing to the Datasets button in the sidebar](https://raw.githubusercontent.com/ultralytics/assets/main/docs/hub/datasets/hub_upload_dataset_2.jpg) + +??? tip "Tip" + + You can also upload a dataset directly from the [Home](https://hub.ultralytics.com/home) page. + + ![Ultralytics HUB screenshot of the Home page with an arrow pointing to the Upload Dataset card](https://raw.githubusercontent.com/ultralytics/assets/main/docs/hub/datasets/hub_upload_dataset_3.jpg) + +Click on the **Upload Dataset** button on the top right of the page. This action will trigger the **Upload Dataset** dialog. + +![Ultralytics HUB screenshot of the Dataset page with an arrow pointing to the Upload Dataset button](https://raw.githubusercontent.com/ultralytics/assets/main/docs/hub/datasets/hub_upload_dataset_4.jpg) + +Upload your dataset in the _Dataset .zip file_ field. + +You have the additional option to set a custom name and description for your Ultralytics HUB dataset. + +When you're happy with your dataset configuration, click **Upload**. + +![Ultralytics HUB screenshot of the Upload Dataset dialog with an arrow pointing to the Upload button](https://raw.githubusercontent.com/ultralytics/assets/main/docs/hub/datasets/hub_upload_dataset_5.jpg) + +After your dataset is uploaded and processed, you will be able to access it from the Datasets page. + +![Ultralytics HUB screenshot of the Datasets page with an arrow pointing to one of the datasets](https://raw.githubusercontent.com/ultralytics/assets/main/docs/hub/datasets/hub_upload_dataset_6.jpg) + +You can view the images in your dataset grouped by splits (Train, Validation, Test). + +![Ultralytics HUB screenshot of the Dataset page with an arrow pointing to the Images tab](https://raw.githubusercontent.com/ultralytics/assets/main/docs/hub/datasets/hub_upload_dataset_7.jpg) + +??? tip "Tip" + + Each image can be enlarged for better visualization. + + ![Ultralytics HUB screenshot of the Images tab inside the Dataset page with an arrow pointing to the expand icon](https://raw.githubusercontent.com/ultralytics/assets/main/docs/hub/datasets/hub_upload_dataset_8.jpg) + + ![Ultralytics HUB screenshot of the Images tab inside the Dataset page with one of the images expanded](https://raw.githubusercontent.com/ultralytics/assets/main/docs/hub/datasets/hub_upload_dataset_9.jpg) + +Also, you can analyze your dataset by click on the **Overview** tab. + +![Ultralytics HUB screenshot of the Dataset page with an arrow pointing to the Overview tab](https://raw.githubusercontent.com/ultralytics/assets/main/docs/hub/datasets/hub_upload_dataset_10.jpg) + +Next, [train a model](https://docs.ultralytics.com/hub/models/#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_11.jpg) + +## Share Dataset + +!!! info "Info" + + Ultralytics HUB's sharing functionality provides a convenient way to share datasets with others. This feature is designed to accommodate both existing Ultralytics HUB users and those who have yet to create an account. + +??? note "Note" + + You have control over the general access of your datasets. + + You can choose to set the general access to "Private", in which case, only you will have access to it. Alternatively, you can set the general access to "Unlisted" which grants viewing access to anyone who has the direct link to the dataset, regardless of whether they have an Ultralytics HUB account or not. + +Navigate to the Dataset page of the dataset you want to share, open the dataset actions dropdown and click on the **Share** option. This action will trigger the **Share Dataset** dialog. + +![Ultralytics HUB screenshot of the Dataset page with an arrow pointing to the Share option](https://raw.githubusercontent.com/ultralytics/assets/main/docs/hub/datasets/hub_share_dataset_1.jpg) + +??? tip "Tip" + + You can also share 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 Share option of one of the datasets](https://raw.githubusercontent.com/ultralytics/assets/main/docs/hub/datasets/hub_share_dataset_2.jpg) + +Set the general access to "Unlisted" and click **Save**. + +![Ultralytics HUB screenshot of the Share Dataset dialog with an arrow pointing to the dropdown and one to the Save button](https://raw.githubusercontent.com/ultralytics/assets/main/docs/hub/datasets/hub_share_dataset_3.jpg) + +Now, anyone who has the direct link to your dataset can view it. + +??? tip "Tip" + + You can easily click on the dataset's link shown in the **Share Dataset** dialog to copy it. + + ![Ultralytics HUB screenshot of the Share Dataset dialog with an arrow pointing to the dataset's link](https://raw.githubusercontent.com/ultralytics/assets/main/docs/hub/datasets/hub_share_dataset_4.jpg) + +## Edit Dataset + +Navigate to the Dataset page of the dataset you want to edit, open the dataset actions dropdown and click on the **Edit** option. This action will trigger the **Update Dataset** dialog. + +![Ultralytics HUB screenshot of the Dataset page with an arrow pointing to the Edit option](https://raw.githubusercontent.com/ultralytics/assets/main/docs/hub/datasets/hub_edit_dataset_1.jpg) + +??? tip "Tip" + + You can also edit 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 Edit option of one of the datasets](https://raw.githubusercontent.com/ultralytics/assets/main/docs/hub/datasets/hub_edit_dataset_2.jpg) + +Apply the desired modifications to your dataset and then confirm the changes by clicking **Save**. + +![Ultralytics HUB screenshot of the Update Dataset dialog with an arrow pointing to the Save button](https://raw.githubusercontent.com/ultralytics/assets/main/docs/hub/datasets/hub_edit_dataset_3.jpg) + +## Delete Dataset + +Navigate to the Dataset page of the dataset you want to delete, open the dataset actions dropdown and click on the **Delete** option. This action will delete the dataset. + +![Ultralytics HUB screenshot of the Dataset page with an arrow pointing to the Delete option](https://raw.githubusercontent.com/ultralytics/assets/main/docs/hub/datasets/hub_delete_dataset_1.jpg) + +??? tip "Tip" + + You can also delete 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 Delete option of one of the datasets](https://raw.githubusercontent.com/ultralytics/assets/main/docs/hub/datasets/hub_delete_dataset_2.jpg) + +??? note "Note" + + If you change your mind, you can restore the dataset from the [Trash](https://hub.ultralytics.com/trash) page. + + ![Ultralytics HUB screenshot of the Trash page with an arrow pointing to the Restore option of one of the datasets](https://raw.githubusercontent.com/ultralytics/assets/main/docs/hub/datasets/hub_delete_dataset_3.jpg) diff --git a/ultralytics/docs/hub/index.md b/ultralytics/docs/hub/index.md new file mode 100644 index 0000000000000000000000000000000000000000..01ab107552e80c5ec861c205b44c0183d53fbc9c --- /dev/null +++ b/ultralytics/docs/hub/index.md @@ -0,0 +1,61 @@ +--- +comments: true +description: Gain insights into training and deploying your YOLOv5 and YOLOv8 models with Ultralytics HUB. Explore pre-trained models, templates and various integrations. +keywords: Ultralytics HUB, YOLOv5, YOLOv8, model training, model deployment, pretrained models, model integrations +--- + +# Ultralytics HUB + + + +
+
+
+
+ Watch: Train Your Custom YOLO Models In A Few Clicks with Ultralytics HUB.
+
+
+
+
+ Watch: Train Your Custom YOLO Models In A Few Clicks with Ultralytics HUB.
+
+
+
+
+ Watch: Train Your Custom YOLO Models In A Few Clicks with Ultralytics HUB.
+
+
+
+
+ Watch: How to Train a YOLOv8 model on Your Custom Dataset in Google Colab.
+
+
+
+
+ Watch: How To Export and Optimize an Ultralytics YOLOv8 Model for Inference with OpenVINO.
+
+ +
+ +[Ray Tune](https://docs.ray.io/en/latest/tune/index.html) is a hyperparameter tuning library designed for efficiency and flexibility. It supports various search strategies, parallelism, and early stopping strategies, and seamlessly integrates with popular machine learning frameworks, including Ultralytics YOLOv8. + +### Integration with Weights & Biases + +YOLOv8 also allows optional integration with [Weights & Biases](https://wandb.ai/site) for monitoring the tuning process. + +## Installation + +To install the required packages, run: + +!!! tip "Installation" + + === "CLI" + + ```bash + # Install and update Ultralytics and Ray Tune packages + pip install -U ultralytics "ray[tune]" + + # Optionally install W&B for logging + pip install wandb + ``` + +## Usage + +!!! example "Usage" + + === "Python" + + ```python + from ultralytics import YOLO + + # Load a YOLOv8n model + model = YOLO('yolov8n.pt') + + # Start tuning hyperparameters for YOLOv8n training on the COCO8 dataset + result_grid = model.tune(data='coco8.yaml', use_ray=True) + ``` + +## `tune()` Method Parameters + +The `tune()` method in YOLOv8 provides an easy-to-use interface for hyperparameter tuning with Ray Tune. It accepts several arguments that allow you to customize the tuning process. Below is a detailed explanation of each parameter: + +| Parameter | Type | Description | Default Value | +|-----------------|------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------| +| `data` | `str` | The dataset configuration file (in YAML format) to run the tuner on. This file should specify the training and validation data paths, as well as other dataset-specific settings. | | +| `space` | `dict, optional` | A dictionary defining the hyperparameter search space for Ray Tune. Each key corresponds to a hyperparameter name, and the value specifies the range of values to explore during tuning. If not provided, YOLOv8 uses a default search space with various hyperparameters. | | +| `grace_period` | `int, optional` | The grace period in epochs for the [ASHA scheduler](https://docs.ray.io/en/latest/tune/api/schedulers.html) in Ray Tune. The scheduler will not terminate any trial before this number of epochs, allowing the model to have some minimum training before making a decision on early stopping. | 10 | +| `gpu_per_trial` | `int, optional` | The number of GPUs to allocate per trial during tuning. This helps manage GPU usage, particularly in multi-GPU environments. If not provided, the tuner will use all available GPUs. | None | +| `iterations` | `int, optional` | The maximum number of trials to run during tuning. This parameter helps control the total number of hyperparameter combinations tested, ensuring the tuning process does not run indefinitely. | 10 | +| `**train_args` | `dict, optional` | Additional arguments to pass to the `train()` method during tuning. These arguments can include settings like the number of training epochs, batch size, and other training-specific configurations. | {} | + +By customizing these parameters, you can fine-tune the hyperparameter optimization process to suit your specific needs and available computational resources. + +## Default Search Space Description + +The following table lists the default search space parameters for hyperparameter tuning in YOLOv8 with Ray Tune. Each parameter has a specific value range defined by `tune.uniform()`. + +| Parameter | Value Range | Description | +|-------------------|----------------------------|------------------------------------------| +| `lr0` | `tune.uniform(1e-5, 1e-1)` | Initial learning rate | +| `lrf` | `tune.uniform(0.01, 1.0)` | Final learning rate factor | +| `momentum` | `tune.uniform(0.6, 0.98)` | Momentum | +| `weight_decay` | `tune.uniform(0.0, 0.001)` | Weight decay | +| `warmup_epochs` | `tune.uniform(0.0, 5.0)` | Warmup epochs | +| `warmup_momentum` | `tune.uniform(0.0, 0.95)` | Warmup momentum | +| `box` | `tune.uniform(0.02, 0.2)` | Box loss weight | +| `cls` | `tune.uniform(0.2, 4.0)` | Class loss weight | +| `hsv_h` | `tune.uniform(0.0, 0.1)` | Hue augmentation range | +| `hsv_s` | `tune.uniform(0.0, 0.9)` | Saturation augmentation range | +| `hsv_v` | `tune.uniform(0.0, 0.9)` | Value (brightness) augmentation range | +| `degrees` | `tune.uniform(0.0, 45.0)` | Rotation augmentation range (degrees) | +| `translate` | `tune.uniform(0.0, 0.9)` | Translation augmentation range | +| `scale` | `tune.uniform(0.0, 0.9)` | Scaling augmentation range | +| `shear` | `tune.uniform(0.0, 10.0)` | Shear augmentation range (degrees) | +| `perspective` | `tune.uniform(0.0, 0.001)` | Perspective augmentation range | +| `flipud` | `tune.uniform(0.0, 1.0)` | Vertical flip augmentation probability | +| `fliplr` | `tune.uniform(0.0, 1.0)` | Horizontal flip augmentation probability | +| `mosaic` | `tune.uniform(0.0, 1.0)` | Mosaic augmentation probability | +| `mixup` | `tune.uniform(0.0, 1.0)` | Mixup augmentation probability | +| `copy_paste` | `tune.uniform(0.0, 1.0)` | Copy-paste augmentation probability | + +## Custom Search Space Example + +In this example, we demonstrate how to use a custom search space for hyperparameter tuning with Ray Tune and YOLOv8. By providing a custom search space, you can focus the tuning process on specific hyperparameters of interest. + +!!! example "Usage" + + ```python + from ultralytics import YOLO + + # Define a YOLO model + model = YOLO("yolov8n.pt") + + # Run Ray Tune on the model + result_grid = model.tune(data="coco128.yaml", + space={"lr0": tune.uniform(1e-5, 1e-1)}, + epochs=50, + use_ray=True) + ``` + +In the code snippet above, we create a YOLO model with the "yolov8n.pt" pretrained weights. Then, we call the `tune()` method, specifying the dataset configuration with "coco128.yaml". We provide a custom search space for the initial learning rate `lr0` using a dictionary with the key "lr0" and the value `tune.uniform(1e-5, 1e-1)`. Finally, we pass additional training arguments, such as the number of epochs directly to the tune method as `epochs=50`. + +## Processing Ray Tune Results + +After running a hyperparameter tuning experiment with Ray Tune, you might want to perform various analyses on the obtained results. This guide will take you through common workflows for processing and analyzing these results. + +### Loading Tune Experiment Results from a Directory + +After running the tuning experiment with `tuner.fit()`, you can load the results from a directory. This is useful, especially if you're performing the analysis after the initial training script has exited. + +```python +experiment_path = f"{storage_path}/{exp_name}" +print(f"Loading results from {experiment_path}...") + +restored_tuner = tune.Tuner.restore(experiment_path, trainable=train_mnist) +result_grid = restored_tuner.get_results() +``` + +### Basic Experiment-Level Analysis + +Get an overview of how trials performed. You can quickly check if there were any errors during the trials. + +```python +if result_grid.errors: + print("One or more trials failed!") +else: + print("No errors!") +``` + +### Basic Trial-Level Analysis + +Access individual trial hyperparameter configurations and the last reported metrics. + +```python +for i, result in enumerate(result_grid): + print(f"Trial #{i}: Configuration: {result.config}, Last Reported Metrics: {result.metrics}") +``` + +### Plotting the Entire History of Reported Metrics for a Trial + +You can plot the history of reported metrics for each trial to see how the metrics evolved over time. + +```python +import matplotlib.pyplot as plt + +for result in result_grid: + plt.plot(result.metrics_dataframe["training_iteration"], result.metrics_dataframe["mean_accuracy"], label=f"Trial {i}") + +plt.xlabel('Training Iterations') +plt.ylabel('Mean Accuracy') +plt.legend() +plt.show() +``` + +## Summary + +In this documentation, we covered common workflows to analyze the results of experiments run with Ray Tune using Ultralytics. The key steps include loading the experiment results from a directory, performing basic experiment-level and trial-level analysis and plotting metrics. + +Explore further by looking into Ray Tune’s [Analyze Results](https://docs.ray.io/en/latest/tune/examples/tune_analyze_results.html) docs page to get the most out of your hyperparameter tuning experiments. diff --git a/ultralytics/docs/integrations/roboflow.md b/ultralytics/docs/integrations/roboflow.md new file mode 100644 index 0000000000000000000000000000000000000000..ed6b8cd3b65701fd307f44392dfb931bbef62ffe --- /dev/null +++ b/ultralytics/docs/integrations/roboflow.md @@ -0,0 +1,239 @@ +--- +comments: true +description: Learn how to use Roboflow with Ultralytics for labeling and managing images for use in training, and for evaluating model performance. +keywords: Ultralytics, YOLOv8, Roboflow, vector analysis, confusion matrix, data management, image labeling +--- + +# Roboflow + +[Roboflow](https://roboflow.com/?ref=ultralytics) has everything you need to build and deploy computer vision models. Connect Roboflow at any step in your pipeline with APIs and SDKs, or use the end-to-end interface to automate the entire process from image to inference. Whether you’re in need of [data labeling](https://roboflow.com/annotate?ref=ultralytics), [model training](https://roboflow.com/train?ref=ultralytics), or [model deployment](https://roboflow.com/deploy?ref=ultralytics), Roboflow gives you building blocks to bring custom computer vision solutions to your project. + +!!! warning + + Roboflow users can use Ultralytics under the [AGPL license](https://github.com/ultralytics/ultralytics/blob/main/LICENSE) or procure an [Enterprise license](https://ultralytics.com/license) directly from Ultralytics. Be aware that Roboflow does **not** provide Ultralytics licenses, and it is the responsibility of the user to ensure appropriate licensing. + +In this guide, we are going to showcase how to find, label, and organize data for use in training a custom Ultralytics YOLOv8 model. Use the table of contents below to jump directly to a specific section: + +- Gather data for training a custom YOLOv8 model +- Upload, convert and label data for YOLOv8 format +- Pre-process and augment data for model robustness +- Dataset management for [YOLOv8](https://docs.ultralytics.com/models/yolov8/) +- Export data in 40+ formats for model training +- Upload custom YOLOv8 model weights for testing and deployment +- Gather Data for Training a Custom YOLOv8 Model + +Roboflow provides two services that can help you collect data for YOLOv8 models: [Universe](https://universe.roboflow.com/?ref=ultralytics) and [Collect](https://roboflow.com/collect?ref=ultralytics). + +Universe is an online repository with over 250,000 vision datasets totalling over 100 million images. + ++ +
+ +With a [free Roboflow account](https://app.roboflow.com/?ref=ultralytics), you can export any dataset available on Universe. To export a dataset, click the "Download this Dataset" button on any dataset. + + ++ +
+ +For YOLOv8, select "YOLOv8" as the export format: + ++ +
+ +Universe also has a page that aggregates all [public fine-tuned YOLOv8 models uploaded to Roboflow](https://universe.roboflow.com/search?q=model:yolov8). You can use this page to explore pre-trained models you can use for testing or [for automated data labeling](https://docs.roboflow.com/annotate/use-roboflow-annotate/model-assisted-labeling) or to prototype with [Roboflow inference](https://roboflow.com/inference?ref=ultralytics). + +If you want to gather images yourself, try [Collect](https://github.com/roboflow/roboflow-collect), an open source project that allows you to automatically gather images using a webcam on the edge. You can use text or image prompts with Collect to instruct what data should be collected, allowing you to capture only the useful data you need to build your vision model. + +## Upload, Convert and Label Data for YOLOv8 Format + +[Roboflow Annotate](https://docs.roboflow.com/annotate/use-roboflow-annotate) is an online annotation tool for use in labeling images for object detection, classification, and segmentation. + +To label data for a YOLOv8 object detection, instance segmentation, or classification model, first create a project in Roboflow. + ++ +
+ +Next, upload your images, and any pre-existing annotations you have from other tools ([using one of the 40+ supported import formats](https://roboflow.com/formats?ref=ultralytics)), into Roboflow. + ++ +
+ +Select the batch of images you have uploaded on the Annotate page to which you are taken after uploading images. Then, click "Start Annotating" to label images. + +To label with bounding boxes, press the `B` key on your keyboard or click the box icon in the sidebar. Click on a point where you want to start your bounding box, then drag to create the box: + ++ +
+ +A pop-up will appear asking you to select a class for your annotation once you have created an annotation. + +To label with polygons, press the `P` key on your keyboard, or the polygon icon in the sidebar. With the polygon annotation tool enabled, click on individual points in the image to draw a polygon. + +Roboflow offers a SAM-based label assistant with which you can label images faster than ever. SAM (Segment Anything Model) is a state-of-the-art computer vision model that can precisely label images. With SAM, you can significantly speed up the image labeling process. Annotating images with polygons becomes as simple as a few clicks, rather than the tedious process of precisely clicking points around an object. + +To use the label assistant, click the cursor icon in the sidebar, SAM will be loaded for use in your project. + ++ +
+ +Hover over any object in the image and SAM will recommend an annotation. You can hover to find the right place to annotate, then click to create your annotation. To amend your annotation to be more or less specific, you can click inside or outside of the annotation SAM has created on the document. + +You can also add tags to images from the Tags panel in the sidebar. You can apply tags to data from a particular area, taken from a specific camera, and more. You can then use these tags to search through data for images matching a tag and generate versions of a dataset with images that contain a particular tag or set of tags. + ++ +
+ +Models hosted on Roboflow can be used with Label Assist, an automated annotation tool that uses your YOLOv8 model to recommend annotations. To use Label Assist, first upload a YOLOv8 model to Roboflow (see instructions later in the guide). Then, click the magic wand icon in the left sidebar and select your model for use in Label Assist. + +Choose a model, then click "Continue" to enable Label Assist: + ++ +
+ +When you open new images for annotation, Label Assist will trigger and recommend annotations. + ++ +
+ +## Dataset Management for YOLOv8 + +Roboflow provides a suite of tools for understanding computer vision datasets. + +First, you can use dataset search to find images that meet a semantic text description (i.e. find all images that contain people), or that meet a specified label (i.e. the image is associated with a specific tag). To use dataset search, click "Dataset" in the sidebar. Then, input a search query using the search bar and associated filters at the top of the page. + +For example, the following text query finds images that contain people in a dataset: + ++ +
+ +You can narrow your search to images with a particular tag using the "Tags" selector: + ++ +
+ +Before you start training a model with your dataset, we recommend using Roboflow [Health Check](https://docs.roboflow.com/datasets/dataset-health-check), a web tool that provides an insight into your dataset and how you can improve the dataset prior to training a vision model. + +To use Health Check, click the "Health Check" sidebar link. A list of statistics will appear that show the average size of images in your dataset, class balance, a heatmap of where annotations are in your images, and more. + ++ +
+ +Health Check may recommend changes to help enhance dataset performance. For example, the class balance feature may show that there is an imbalance in labels that, if solved, may boost performance or your model. + +## Export Data in 40+ Formats for Model Training + +To export your data, you will need a dataset version. A version is a state of your dataset frozen-in-time. To create a version, first click "Versions" in the sidebar. Then, click the "Create New Version" button. On this page, you will be able to choose augmentations and preprocessing steps to apply to your dataset: + ++ +
+ +For each augmentation you select, a pop-up will appear allowing you to tune the augmentation to your needs. Here is an example of tuning a brightness augmentation within specified parameters: + ++ +
+ +When your dataset version has been generated, you can export your data into a range of formats. Click the "Export Dataset" button on your dataset version page to export your data: + ++ +
+ +You are now ready to train YOLOv8 on a custom dataset. Follow this [written guide](https://blog.roboflow.com/how-to-train-yolov8-on-a-custom-dataset/) and [YouTube video](https://www.youtube.com/watch?v=wuZtUMEiKWY) for step-by-step instructions or refer to the [Ultralytics documentation](https://docs.ultralytics.com/modes/train/). + +## Upload Custom YOLOv8 Model Weights for Testing and Deployment + +Roboflow offers an infinitely scalable API for deployed models and SDKs for use with NVIDIA Jetsons, Luxonis OAKs, Raspberry Pis, GPU-based devices, and more. + +You can deploy YOLOv8 models by uploading YOLOv8 weights to Roboflow. You can do this in a few lines of Python code. Create a new Python file and add the following code: + +```python +import roboflow # install with 'pip install roboflow' + +roboflow.login() + +rf = roboflow.Roboflow() + +project = rf.workspace(WORKSPACE_ID).project("football-players-detection-3zvbc") +dataset = project.version(VERSION).download("yolov8") + +project.version(dataset.version).deploy(model_type="yolov8", model_path=f"{HOME}/runs/detect/train/") +``` + +In this code, replace the project ID and version ID with the values for your account and project. [Learn how to retrieve your Roboflow API key](https://docs.roboflow.com/api-reference/authentication#retrieve-an-api-key). + +When you run the code above, you will be asked to authenticate. Then, your model will be uploaded and an API will be created for your project. This process can take up to 30 minutes to complete. + +To test your model and find deployment instructions for supported SDKs, go to the "Deploy" tab in the Roboflow sidebar. At the top of this page, a widget will appear with which you can test your model. You can use your webcam for live testing or upload images or videos. + ++ +
+ +You can also use your uploaded model as a [labeling assistant](https://docs.roboflow.com/annotate/use-roboflow-annotate/model-assisted-labeling). This feature uses your trained model to recommend annotations on images uploaded to Roboflow. + +## How to Evaluate YOLOv8 Models + +Roboflow provides a range of features for use in evaluating models. + +Once you have uploaded a model to Roboflow, you can access our model evaluation tool, which provides a confusion matrix showing the performance of your model as well as an interactive vector analysis plot. These features can help you find opportunities to improve your model. + +To access a confusion matrix, go to your model page on the Roboflow dashboard, then click "View Detailed Evaluation": + ++ +
+ +A pop-up will appear showing a confusion matrix: + ++ +
+ +Hover over a box on the confusion matrix to see the value associated with the box. Click on a box to see images in the respective category. Click on an image to view the model predictions and ground truth data associated with that image. + +For more insights, click Vector Analysis. This will show a scatter plot of the images in your dataset, calculated using CLIP. The closer images are in the plot, the more similar they are, semantically. Each image is represented as a dot with a color between white and red. The more red the dot, the worse the model performed. + ++ +
+ +You can use Vector Analysis to: + +- Find clusters of images; +- Identify clusters where the model performs poorly, and; +- Visualize commonalities between images on which the model performs poorly. + +## Learning Resources + +Want to learn more about using Roboflow for creating YOLOv8 models? The following resources may be helpful in your work. + +- [Train YOLOv8 on a Custom Dataset](https://github.com/roboflow/notebooks/blob/main/notebooks/train-yolov8-object-detection-on-custom-dataset.ipynb): Follow our interactive notebook that shows you how to train a YOLOv8 model on a custom dataset. +- [Autodistill](https://autodistill.github.io/autodistill/): Use large foundation vision models to label data for specific models. You can label images for use in training YOLOv8 classification, detection, and segmentation models with Autodistill. +- [Supervision](https://roboflow.github.io/supervision/): A Python package with helpful utilities for use in working with computer vision models. You can use supervision to filter detections, compute confusion matrices, and more, all in a few lines of Python code. +- [Roboflow Blog](https://blog.roboflow.com/): The Roboflow Blog features over 500 articles on computer vision, covering topics from how to train a YOLOv8 model to annotation best practices. +- [Roboflow YouTube channel](https://www.youtube.com/@Roboflow): Browse dozens of in-depth computer vision guides on our YouTube channel, covering topics from training YOLOv8 models to automated image labeling. + +## Project Showcase + +Below are a few of the many pieces of feedback we have received for using YOLOv8 and Roboflow together to create computer vision models. + ++ + + +
diff --git a/ultralytics/docs/models/fast-sam.md b/ultralytics/docs/models/fast-sam.md new file mode 100644 index 0000000000000000000000000000000000000000..2e839a5a73934ac05adc28b33368553c025f9663 --- /dev/null +++ b/ultralytics/docs/models/fast-sam.md @@ -0,0 +1,186 @@ +--- +comments: true +description: Explore FastSAM, a CNN-based solution for real-time object segmentation in images. Enhanced user interaction, computational efficiency and adaptable across vision tasks. +keywords: FastSAM, machine learning, CNN-based solution, object segmentation, real-time solution, Ultralytics, vision tasks, image processing, industrial applications, user interaction +--- + +# Fast Segment Anything Model (FastSAM) + +The Fast Segment Anything Model (FastSAM) is a novel, real-time CNN-based solution for the Segment Anything task. This task is designed to segment any object within an image based on various possible user interaction prompts. FastSAM significantly reduces computational demands while maintaining competitive performance, making it a practical choice for a variety of vision tasks. + +![Fast Segment Anything Model (FastSAM) architecture overview](https://user-images.githubusercontent.com/26833433/248551984-d98f0f6d-7535-45d0-b380-2e1440b52ad7.jpg) + +## Overview + +FastSAM is designed to address the limitations of the [Segment Anything Model (SAM)](sam.md), a heavy Transformer model with substantial computational resource requirements. The FastSAM decouples the segment anything task into two sequential stages: all-instance segmentation and prompt-guided selection. The first stage uses [YOLOv8-seg](../tasks/segment.md) to produce the segmentation masks of all instances in the image. In the second stage, it outputs the region-of-interest corresponding to the prompt. + +## Key Features + +1. **Real-time Solution:** By leveraging the computational efficiency of CNNs, FastSAM provides a real-time solution for the segment anything task, making it valuable for industrial applications that require quick results. + +2. **Efficiency and Performance:** FastSAM offers a significant reduction in computational and resource demands without compromising on performance quality. It achieves comparable performance to SAM but with drastically reduced computational resources, enabling real-time application. + +3. **Prompt-guided Segmentation:** FastSAM can segment any object within an image guided by various possible user interaction prompts, providing flexibility and adaptability in different scenarios. + +4. **Based on YOLOv8-seg:** FastSAM is based on [YOLOv8-seg](../tasks/segment.md), an object detector equipped with an instance segmentation branch. This allows it to effectively produce the segmentation masks of all instances in an image. + +5. **Competitive Results on Benchmarks:** On the object proposal task on MS COCO, FastSAM achieves high scores at a significantly faster speed than [SAM](sam.md) on a single NVIDIA RTX 3090, demonstrating its efficiency and capability. + +6. **Practical Applications:** The proposed approach provides a new, practical solution for a large number of vision tasks at a really high speed, tens or hundreds of times faster than current methods. + +7. **Model Compression Feasibility:** FastSAM demonstrates the feasibility of a path that can significantly reduce the computational effort by introducing an artificial prior to the structure, thus opening new possibilities for large model architecture for general vision tasks. + +## Usage + +### Python API + +The FastSAM models are easy to integrate into your Python applications. Ultralytics provides a user-friendly Python API to streamline the process. + +#### Predict Usage + +To perform object detection on an image, use the `predict` method as shown below: + +!!! example "" + + === "Python" + ```python + from ultralytics import FastSAM + from ultralytics.models.fastsam import FastSAMPrompt + + # Define an inference source + source = 'path/to/bus.jpg' + + # Create a FastSAM model + model = FastSAM('FastSAM-s.pt') # or FastSAM-x.pt + + # Run inference on an image + everything_results = model(source, device='cpu', retina_masks=True, imgsz=1024, conf=0.4, iou=0.9) + + # Prepare a Prompt Process object + prompt_process = FastSAMPrompt(source, everything_results, device='cpu') + + # Everything prompt + ann = prompt_process.everything_prompt() + + # Bbox default shape [0,0,0,0] -> [x1,y1,x2,y2] + ann = prompt_process.box_prompt(bbox=[200, 200, 300, 300]) + + # Text prompt + ann = prompt_process.text_prompt(text='a photo of a dog') + + # Point prompt + # points default [[0,0]] [[x1,y1],[x2,y2]] + # point_label default [0] [1,0] 0:background, 1:foreground + ann = prompt_process.point_prompt(points=[[200, 200]], pointlabel=[1]) + prompt_process.plot(annotations=ann, output='./') + ``` + + === "CLI" + ```bash + # Load a FastSAM model and segment everything with it + yolo segment predict model=FastSAM-s.pt source=path/to/bus.jpg imgsz=640 + ``` + +This snippet demonstrates the simplicity of loading a pre-trained model and running a prediction on an image. + +#### Val Usage + +Validation of the model on a dataset can be done as follows: + +!!! example "" + + === "Python" + ```python + from ultralytics import FastSAM + + # Create a FastSAM model + model = FastSAM('FastSAM-s.pt') # or FastSAM-x.pt + + # Validate the model + results = model.val(data='coco8-seg.yaml') + ``` + + === "CLI" + ```bash + # Load a FastSAM model and validate it on the COCO8 example dataset at image size 640 + yolo segment val model=FastSAM-s.pt data=coco8.yaml imgsz=640 + ``` + +Please note that FastSAM only supports detection and segmentation of a single class of object. This means it will recognize and segment all objects as the same class. Therefore, when preparing the dataset, you need to convert all object category IDs to 0. + +### FastSAM official Usage + +FastSAM is also available directly from the [https://github.com/CASIA-IVA-Lab/FastSAM](https://github.com/CASIA-IVA-Lab/FastSAM) repository. Here is a brief overview of the typical steps you might take to use FastSAM: + +#### Installation + +1. Clone the FastSAM repository: + ```shell + git clone https://github.com/CASIA-IVA-Lab/FastSAM.git + ``` + +2. Create and activate a Conda environment with Python 3.9: + ```shell + conda create -n FastSAM python=3.9 + conda activate FastSAM + ``` + +3. Navigate to the cloned repository and install the required packages: + ```shell + cd FastSAM + pip install -r requirements.txt + ``` + +4. Install the CLIP model: + ```shell + pip install git+https://github.com/openai/CLIP.git + ``` + +#### Example Usage + +1. Download a [model checkpoint](https://drive.google.com/file/d/1m1sjY4ihXBU1fZXdQ-Xdj-mDltW-2Rqv/view?usp=sharing). + +2. Use FastSAM for inference. Example commands: + + - Segment everything in an image: + ```shell + python Inference.py --model_path ./weights/FastSAM.pt --img_path ./images/dogs.jpg + ``` + + - Segment specific objects using text prompt: + ```shell + python Inference.py --model_path ./weights/FastSAM.pt --img_path ./images/dogs.jpg --text_prompt "the yellow dog" + ``` + + - Segment objects within a bounding box (provide box coordinates in xywh format): + ```shell + python Inference.py --model_path ./weights/FastSAM.pt --img_path ./images/dogs.jpg --box_prompt "[570,200,230,400]" + ``` + + - Segment objects near specific points: + ```shell + python Inference.py --model_path ./weights/FastSAM.pt --img_path ./images/dogs.jpg --point_prompt "[[520,360],[620,300]]" --point_label "[1,0]" + ``` + +Additionally, you can try FastSAM through a [Colab demo](https://colab.research.google.com/drive/1oX14f6IneGGw612WgVlAiy91UHwFAvr9?usp=sharing) or on the [HuggingFace web demo](https://huggingface.co/spaces/An-619/FastSAM) for a visual experience. + +## Citations and Acknowledgements + +We would like to acknowledge the FastSAM authors for their significant contributions in the field of real-time instance segmentation: + +!!! note "" + + === "BibTeX" + + ```bibtex + @misc{zhao2023fast, + title={Fast Segment Anything}, + author={Xu Zhao and Wenchao Ding and Yongqi An and Yinglong Du and Tao Yu and Min Li and Ming Tang and Jinqiao Wang}, + year={2023}, + eprint={2306.12156}, + archivePrefix={arXiv}, + primaryClass={cs.CV} + } + ``` + +The original FastSAM paper can be found on [arXiv](https://arxiv.org/abs/2306.12156). The authors have made their work publicly available, and the codebase can be accessed on [GitHub](https://github.com/CASIA-IVA-Lab/FastSAM). We appreciate their efforts in advancing the field and making their work accessible to the broader community. diff --git a/ultralytics/docs/models/index.md b/ultralytics/docs/models/index.md new file mode 100644 index 0000000000000000000000000000000000000000..e67f5d6106d35a559a5d855b5da8294349fe0851 --- /dev/null +++ b/ultralytics/docs/models/index.md @@ -0,0 +1,90 @@ +--- +comments: true +description: Explore the diverse range of YOLO family, SAM, MobileSAM, FastSAM, YOLO-NAS, and RT-DETR models supported by Ultralytics. Get started with examples for both CLI and Python usage. +keywords: Ultralytics, documentation, YOLO, SAM, MobileSAM, FastSAM, YOLO-NAS, RT-DETR, models, architectures, Python, CLI +--- + +# Models Supported by Ultralytics + +Welcome to Ultralytics' model documentation! We offer support for a wide range of models, each tailored to specific tasks like [object detection](../tasks/detect.md), [instance segmentation](../tasks/segment.md), [image classification](../tasks/classify.md), [pose estimation](../tasks/pose.md), and [multi-object tracking](../modes/track.md). If you're interested in contributing your model architecture to Ultralytics, check out our [Contributing Guide](../help/contributing.md). + +## Featured Models + +Here are some of the key models supported: + +1. **[YOLOv3](./yolov3.md)**: The third iteration of the YOLO model family, originally by Joseph Redmon, known for its efficient real-time object detection capabilities. +2. **[YOLOv4](./yolov4.md)**: A darknet-native update to YOLOv3, released by Alexey Bochkovskiy in 2020. +3. **[YOLOv5](./yolov5.md)**: An improved version of the YOLO architecture by Ultralytics, offering better performance and speed trade-offs compared to previous versions. +4. **[YOLOv6](./yolov6.md)**: Released by [Meituan](https://about.meituan.com/) in 2022, and in use in many of the company's autonomous delivery robots. +5. **[YOLOv7](./yolov7.md)**: Updated YOLO models released in 2022 by the authors of YOLOv4. +6. **[YOLOv8](./yolov8.md)**: The latest version of the YOLO family, featuring enhanced capabilities such as instance segmentation, pose/keypoints estimation, and classification. +7. **[Segment Anything Model (SAM)](./sam.md)**: Meta's Segment Anything Model (SAM). +8. **[Mobile Segment Anything Model (MobileSAM)](./mobile-sam.md)**: MobileSAM for mobile applications, by Kyung Hee University. +9. **[Fast Segment Anything Model (FastSAM)](./fast-sam.md)**: FastSAM by Image & Video Analysis Group, Institute of Automation, Chinese Academy of Sciences. +10. **[YOLO-NAS](./yolo-nas.md)**: YOLO Neural Architecture Search (NAS) Models. +11. **[Realtime Detection Transformers (RT-DETR)](./rtdetr.md)**: Baidu's PaddlePaddle Realtime Detection Transformer (RT-DETR) models. + +
+
+
+
+ Watch: Run Ultralytics YOLO models in just a few lines of code.
+
+
+
+
+ Watch: How To Export Custom Trained Ultralytics YOLOv8 Model and Run Live Inference on Webcam.
+
+
+
+
+ Watch: Ultralytics Modes Tutorial: Train, Validate, Predict, Export & Benchmark.
+
+
+
+
+ Watch: How to Extract the Outputs from Ultralytics YOLOv8 Model for Custom Projects.
+
+
+
+
+ Watch: Object Detection and Tracking with Ultralytics YOLOv8.
+
+
+
+
+ Watch: How to Train a YOLOv8 model on Your Custom Dataset in Google Colab.
+
+
+
+
+ Watch: Object Detection with Pre-trained Ultralytics YOLOv8 Model.
+
+
+
+
+ Watch: Explore Ultralytics YOLO Tasks: Object Detection, Segmentation, Tracking, and Pose Estimation.
+
+
+
+
+ Watch: Pose Estimation with Ultralytics YOLOv8.
+
+
+
+
+ Watch: Run Segmentation with Pre-Trained Ultralytics YOLOv8 Model in Python.
+
+
+
+
+ Watch: Mastering Ultralytics YOLOv8: CLI & Python Usage and Live Inference
+
+ + +
+ + + + ++ +
+ +For the first time, your deep learning workloads can meet the performance demands of production without the complexity and costs of hardware accelerators. Put simply, DeepSparse gives you the performance of GPUs and the simplicity of software: + +- **Flexible Deployments**: Run consistently across cloud, data center, and edge with any hardware provider from Intel to AMD to ARM +- **Infinite Scalability**: Scale vertically to 100s of cores, out with standard Kubernetes, or fully-abstracted with Serverless +- **Easy Integration**: Clean APIs for integrating your model into an application and monitoring it in production + +### How Does DeepSparse Achieve GPU-Class Performance? + +DeepSparse takes advantage of model sparsity to gain its performance speedup. + +Sparsification through pruning and quantization is a broadly studied technique, allowing order-of-magnitude reductions in the size and compute needed to execute a network, while maintaining high accuracy. DeepSparse is sparsity-aware, meaning it skips the zeroed out parameters, shrinking amount of compute in a forward pass. Since the sparse computation is now memory bound, DeepSparse executes the network depth-wise, breaking the problem into Tensor Columns, vertical stripes of computation that fit in cache. + ++ +
+ +Sparse networks with compressed computation, executed depth-wise in cache, allows DeepSparse to deliver GPU-class performance on CPUs! + +### How Do I Create A Sparse Version of YOLOv5 Trained on My Data? + +Neural Magic's open-source model repository, SparseZoo, contains pre-sparsified checkpoints of each YOLOv5 model. Using SparseML, which is integrated with Ultralytics, you can fine-tune a sparse checkpoint onto your data with a single CLI command. + +[Checkout Neural Magic's YOLOv5 documentation for more details](https://docs.neuralmagic.com/use-cases/object-detection/sparsifying). + +## DeepSparse Usage + +We will walk through an example benchmarking and deploying a sparse version of YOLOv5s with DeepSparse. + +### Install DeepSparse + +Run the following to install DeepSparse. We recommend you use a virtual environment with Python. + +```bash +pip install "deepsparse[server,yolo,onnxruntime]" +``` + +### Collect an ONNX File + +DeepSparse accepts a model in the ONNX format, passed either as: + +- A SparseZoo stub which identifies an ONNX file in the SparseZoo +- A local path to an ONNX model in a filesystem + +The examples below use the standard dense and pruned-quantized YOLOv5s checkpoints, identified by the following SparseZoo stubs: + +```bash +zoo:cv/detection/yolov5-s/pytorch/ultralytics/coco/base-none +zoo:cv/detection/yolov5-s/pytorch/ultralytics/coco/pruned65_quant-none +``` + +### Deploy a Model + +DeepSparse offers convenient APIs for integrating your model into an application. + +To try the deployment examples below, pull down a sample image and save it as `basilica.jpg` with the following: + +```bash +wget -O basilica.jpg https://raw.githubusercontent.com/neuralmagic/deepsparse/main/src/deepsparse/yolo/sample_images/basilica.jpg +``` + +#### Python API + +`Pipelines` wrap pre-processing and output post-processing around the runtime, providing a clean interface for adding DeepSparse to an application. The DeepSparse-Ultralytics integration includes an out-of-the-box `Pipeline` that accepts raw images and outputs the bounding boxes. + +Create a `Pipeline` and run inference: + +```python +from deepsparse import Pipeline + +# list of images in local filesystem +images = ["basilica.jpg"] + +# create Pipeline +model_stub = "zoo:cv/detection/yolov5-s/pytorch/ultralytics/coco/pruned65_quant-none" +yolo_pipeline = Pipeline.create( + task="yolo", + model_path=model_stub, +) + +# run inference on images, receive bounding boxes + classes +pipeline_outputs = yolo_pipeline(images=images, iou_thres=0.6, conf_thres=0.001) +print(pipeline_outputs) +``` + +If you are running in the cloud, you may get an error that open-cv cannot find `libGL.so.1`. Running the following on Ubuntu installs it: + +``` +apt-get install libgl1 +``` + +#### HTTP Server + +DeepSparse Server runs on top of the popular FastAPI web framework and Uvicorn web server. With just a single CLI command, you can easily setup a model service endpoint with DeepSparse. The Server supports any Pipeline from DeepSparse, including object detection with YOLOv5, enabling you to send raw images to the endpoint and receive the bounding boxes. + +Spin up the Server with the pruned-quantized YOLOv5s: + +```bash +deepsparse.server \ + --task yolo \ + --model_path zoo:cv/detection/yolov5-s/pytorch/ultralytics/coco/pruned65_quant-none +``` + +An example request, using Python's `requests` package: + +```python +import requests, json + +# list of images for inference (local files on client side) +path = ['basilica.jpg'] +files = [('request', open(img, 'rb')) for img in path] + +# send request over HTTP to /predict/from_files endpoint +url = 'http://0.0.0.0:5543/predict/from_files' +resp = requests.post(url=url, files=files) + +# response is returned in JSON +annotations = json.loads(resp.text) # dictionary of annotation results +bounding_boxes = annotations["boxes"] +labels = annotations["labels"] +``` + +#### Annotate CLI + +You can also use the annotate command to have the engine save an annotated photo on disk. Try --source 0 to annotate your live webcam feed! + +```bash +deepsparse.object_detection.annotate --model_filepath zoo:cv/detection/yolov5-s/pytorch/ultralytics/coco/pruned65_quant-none --source basilica.jpg +``` + +Running the above command will create an `annotation-results` folder and save the annotated image inside. + ++ +
+ +## Benchmarking Performance + +We will compare DeepSparse's throughput to ONNX Runtime's throughput on YOLOv5s, using DeepSparse's benchmarking script. + +The benchmarks were run on an AWS `c6i.8xlarge` instance (16 cores). + +### Batch 32 Performance Comparison + +#### ONNX Runtime Baseline + +At batch 32, ONNX Runtime achieves 42 images/sec with the standard dense YOLOv5s: + +```bash +deepsparse.benchmark zoo:cv/detection/yolov5-s/pytorch/ultralytics/coco/base-none -s sync -b 32 -nstreams 1 -e onnxruntime + +> Original Model Path: zoo:cv/detection/yolov5-s/pytorch/ultralytics/coco/base-none +> Batch Size: 32 +> Scenario: sync +> Throughput (items/sec): 41.9025 +``` + +#### DeepSparse Dense Performance + +While DeepSparse offers its best performance with optimized sparse models, it also performs well with the standard dense YOLOv5s. + +At batch 32, DeepSparse achieves 70 images/sec with the standard dense YOLOv5s, a **1.7x performance improvement over ORT**! + +```bash +deepsparse.benchmark zoo:cv/detection/yolov5-s/pytorch/ultralytics/coco/base-none -s sync -b 32 -nstreams 1 + +> Original Model Path: zoo:cv/detection/yolov5-s/pytorch/ultralytics/coco/base-none +> Batch Size: 32 +> Scenario: sync +> Throughput (items/sec): 69.5546 +``` + +#### DeepSparse Sparse Performance + +When sparsity is applied to the model, DeepSparse's performance gains over ONNX Runtime is even stronger. + +At batch 32, DeepSparse achieves 241 images/sec with the pruned-quantized YOLOv5s, a **5.8x performance improvement over ORT**! + +```bash +deepsparse.benchmark zoo:cv/detection/yolov5-s/pytorch/ultralytics/coco/pruned65_quant-none -s sync -b 32 -nstreams 1 + +> Original Model Path: zoo:cv/detection/yolov5-s/pytorch/ultralytics/coco/pruned65_quant-none +> Batch Size: 32 +> Scenario: sync +> Throughput (items/sec): 241.2452 +``` + +### Batch 1 Performance Comparison + +DeepSparse is also able to gain a speed-up over ONNX Runtime for the latency-sensitive, batch 1 scenario. + +#### ONNX Runtime Baseline + +At batch 1, ONNX Runtime achieves 48 images/sec with the standard, dense YOLOv5s. + +```bash +deepsparse.benchmark zoo:cv/detection/yolov5-s/pytorch/ultralytics/coco/base-none -s sync -b 1 -nstreams 1 -e onnxruntime + +> Original Model Path: zoo:cv/detection/yolov5-s/pytorch/ultralytics/coco/base-none +> Batch Size: 1 +> Scenario: sync +> Throughput (items/sec): 48.0921 +``` + +#### DeepSparse Sparse Performance + +At batch 1, DeepSparse achieves 135 items/sec with a pruned-quantized YOLOv5s, **a 2.8x performance gain over ONNX Runtime!** + +```bash +deepsparse.benchmark zoo:cv/detection/yolov5-s/pytorch/ultralytics/coco/pruned65_quant-none -s sync -b 1 -nstreams 1 + +> Original Model Path: zoo:cv/detection/yolov5-s/pytorch/ultralytics/coco/pruned65_quant-none +> Batch Size: 1 +> Scenario: sync +> Throughput (items/sec): 134.9468 +``` + +Since `c6i.8xlarge` instances have VNNI instructions, DeepSparse's throughput can be pushed further if weights are pruned in blocks of 4. + +At batch 1, DeepSparse achieves 180 items/sec with a 4-block pruned-quantized YOLOv5s, a **3.7x performance gain over ONNX Runtime!** + +```bash +deepsparse.benchmark zoo:cv/detection/yolov5-s/pytorch/ultralytics/coco/pruned35_quant-none-vnni -s sync -b 1 -nstreams 1 + +> Original Model Path: zoo:cv/detection/yolov5-s/pytorch/ultralytics/coco/pruned35_quant-none-vnni +> Batch Size: 1 +> Scenario: sync +> Throughput (items/sec): 179.7375 +``` + +## Get Started With DeepSparse + +**Research or Testing?** DeepSparse Community is free for research and testing. Get started with our [Documentation](https://docs.neuralmagic.com/). diff --git a/ultralytics/docs/yolov5/tutorials/pytorch_hub_model_loading.md b/ultralytics/docs/yolov5/tutorials/pytorch_hub_model_loading.md new file mode 100644 index 0000000000000000000000000000000000000000..5d9a10adf3019458d657af679c4c47f4e6d7bfcd --- /dev/null +++ b/ultralytics/docs/yolov5/tutorials/pytorch_hub_model_loading.md @@ -0,0 +1,330 @@ +--- +comments: true +description: Detailed guide on loading YOLOv5 from PyTorch Hub. Includes examples & tips on inference settings, multi-GPU inference, training and more. +keywords: Ultralytics, YOLOv5, PyTorch, loading YOLOv5, PyTorch Hub, inference, multi-GPU inference, training +--- + +📚 This guide explains how to load YOLOv5 🚀 from PyTorch Hub at [https://pytorch.org/hub/ultralytics_yolov5](https://pytorch.org/hub/ultralytics_yolov5). UPDATED 26 March 2023. + +## Before You Start + +Install [requirements.txt](https://github.com/ultralytics/yolov5/blob/master/requirements.txt) in a [**Python>=3.8.0**](https://www.python.org/) environment, including [**PyTorch>=1.8**](https://pytorch.org/get-started/locally/). [Models](https://github.com/ultralytics/yolov5/tree/master/models) and [datasets](https://github.com/ultralytics/yolov5/tree/master/data) download automatically from the latest YOLOv5 [release](https://github.com/ultralytics/yolov5/releases). + +```bash +pip install -r https://raw.githubusercontent.com/ultralytics/yolov5/master/requirements.txt +``` + +💡 ProTip: Cloning [https://github.com/ultralytics/yolov5](https://github.com/ultralytics/yolov5) is **not** required 😃 + +## Load YOLOv5 with PyTorch Hub + +### Simple Example + +This example loads a pretrained YOLOv5s model from PyTorch Hub as `model` and passes an image for inference. `'yolov5s'` is the lightest and fastest YOLOv5 model. For details on all available models please see the [README](https://github.com/ultralytics/yolov5#pretrained-checkpoints). + +```python +import torch + +# Model +model = torch.hub.load('ultralytics/yolov5', 'yolov5s') + +# Image +im = 'https://ultralytics.com/images/zidane.jpg' + +# Inference +results = model(im) + +results.pandas().xyxy[0] +# xmin ymin xmax ymax confidence class name +# 0 749.50 43.50 1148.0 704.5 0.874023 0 person +# 1 433.50 433.50 517.5 714.5 0.687988 27 tie +# 2 114.75 195.75 1095.0 708.0 0.624512 0 person +# 3 986.00 304.00 1028.0 420.0 0.286865 27 tie +``` + +### Detailed Example + +This example shows **batched inference** with **PIL** and **OpenCV** image sources. `results` can be **printed** to console, **saved** to `runs/hub`, **showed** to screen on supported environments, and returned as **tensors** or **pandas** dataframes. + +```python +import cv2 +import torch +from PIL import Image + +# Model +model = torch.hub.load('ultralytics/yolov5', 'yolov5s') + +# Images +for f in 'zidane.jpg', 'bus.jpg': + torch.hub.download_url_to_file('https://ultralytics.com/images/' + f, f) # download 2 images +im1 = Image.open('zidane.jpg') # PIL image +im2 = cv2.imread('bus.jpg')[..., ::-1] # OpenCV image (BGR to RGB) + +# Inference +results = model([im1, im2], size=640) # batch of images + +# Results +results.print() +results.save() # or .show() + +results.xyxy[0] # im1 predictions (tensor) +results.pandas().xyxy[0] # im1 predictions (pandas) +# xmin ymin xmax ymax confidence class name +# 0 749.50 43.50 1148.0 704.5 0.874023 0 person +# 1 433.50 433.50 517.5 714.5 0.687988 27 tie +# 2 114.75 195.75 1095.0 708.0 0.624512 0 person +# 3 986.00 304.00 1028.0 420.0 0.286865 27 tie +``` + + + +For all inference options see YOLOv5 `AutoShape()` forward [method](https://github.com/ultralytics/yolov5/blob/30e4c4f09297b67afedf8b2bcd851833ddc9dead/models/common.py#L243-L252). + +### Inference Settings + +YOLOv5 models contain various inference attributes such as **confidence threshold**, **IoU threshold**, etc. which can be set by: + +```python +model.conf = 0.25 # NMS confidence threshold + iou = 0.45 # NMS IoU threshold + agnostic = False # NMS class-agnostic + multi_label = False # NMS multiple labels per box + classes = None # (optional list) filter by class, i.e. = [0, 15, 16] for COCO persons, cats and dogs + max_det = 1000 # maximum number of detections per image + amp = False # Automatic Mixed Precision (AMP) inference + +results = model(im, size=320) # custom inference size +``` + +### Device + +Models can be transferred to any device after creation: + +```python +model.cpu() # CPU +model.cuda() # GPU +model.to(device) # i.e. device=torch.device(0) +``` + +Models can also be created directly on any `device`: + +```python +model = torch.hub.load('ultralytics/yolov5', 'yolov5s', device='cpu') # load on CPU +``` + +💡 ProTip: Input images are automatically transferred to the correct model device before inference. + +### Silence Outputs + +Models can be loaded silently with `_verbose=False`: + +```python +model = torch.hub.load('ultralytics/yolov5', 'yolov5s', _verbose=False) # load silently +``` + +### Input Channels + +To load a pretrained YOLOv5s model with 4 input channels rather than the default 3: + +```python +model = torch.hub.load('ultralytics/yolov5', 'yolov5s', channels=4) +``` + +In this case the model will be composed of pretrained weights **except for** the very first input layer, which is no longer the same shape as the pretrained input layer. The input layer will remain initialized by random weights. + +### Number of Classes + +To load a pretrained YOLOv5s model with 10 output classes rather than the default 80: + +```python +model = torch.hub.load('ultralytics/yolov5', 'yolov5s', classes=10) +``` + +In this case the model will be composed of pretrained weights **except for** the output layers, which are no longer the same shape as the pretrained output layers. The output layers will remain initialized by random weights. + +### Force Reload + +If you run into problems with the above steps, setting `force_reload=True` may help by discarding the existing cache and force a fresh download of the latest YOLOv5 version from PyTorch Hub. + +```python +model = torch.hub.load('ultralytics/yolov5', 'yolov5s', force_reload=True) # force reload +``` + +### Screenshot Inference + +To run inference on your desktop screen: + +```python +import torch +from PIL import ImageGrab + +# Model +model = torch.hub.load('ultralytics/yolov5', 'yolov5s') + +# Image +im = ImageGrab.grab() # take a screenshot + +# Inference +results = model(im) +``` + +### Multi-GPU Inference + +YOLOv5 models can be loaded to multiple GPUs in parallel with threaded inference: + +```python +import torch +import threading + +def run(model, im): + results = model(im) + results.save() + +# Models +model0 = torch.hub.load('ultralytics/yolov5', 'yolov5s', device=0) +model1 = torch.hub.load('ultralytics/yolov5', 'yolov5s', device=1) + +# Inference +threading.Thread(target=run, args=[model0, 'https://ultralytics.com/images/zidane.jpg'], daemon=True).start() +threading.Thread(target=run, args=[model1, 'https://ultralytics.com/images/bus.jpg'], daemon=True).start() +``` + +### Training + +To load a YOLOv5 model for training rather than inference, set `autoshape=False`. To load a model with randomly initialized weights (to train from scratch) use `pretrained=False`. You must provide your own training script in this case. Alternatively see our YOLOv5 [Train Custom Data Tutorial](https://docs.ultralytics.com/yolov5/tutorials/train_custom_data) for model training. + +```python +model = torch.hub.load('ultralytics/yolov5', 'yolov5s', autoshape=False) # load pretrained +model = torch.hub.load('ultralytics/yolov5', 'yolov5s', autoshape=False, pretrained=False) # load scratch +``` + +### Base64 Results + +For use with API services. See https://github.com/ultralytics/yolov5/pull/2291 and [Flask REST API](https://github.com/ultralytics/yolov5/tree/master/utils/flask_rest_api) example for details. + +```python +results = model(im) # inference + +results.ims # array of original images (as np array) passed to model for inference +results.render() # updates results.ims with boxes and labels +for im in results.ims: + buffered = BytesIO() + im_base64 = Image.fromarray(im) + im_base64.save(buffered, format="JPEG") + print(base64.b64encode(buffered.getvalue()).decode('utf-8')) # base64 encoded image with results +``` + +### Cropped Results + +Results can be returned and saved as detection crops: + +```python +results = model(im) # inference +crops = results.crop(save=True) # cropped detections dictionary +``` + +### Pandas Results + +Results can be returned as [Pandas DataFrames](https://pandas.pydata.org/): + +```python +results = model(im) # inference +results.pandas().xyxy[0] # Pandas DataFrame +``` + +
+
+
+
+ 观看: 在Google Colab中如何训练您的自定义数据集上的YOLOv8模型。
+
+ + +
+ +This example demonstrates how to perform inference using YOLOv8 in C++ with ONNX Runtime and OpenCV's API. + +## Benefits ✨ + +- Friendly for deployment in the industrial sector. +- Faster than OpenCV's DNN inference on both CPU and GPU. +- Supports FP32 and FP16 CUDA acceleration. + +## Exporting YOLOv8 Models 📦 + +To export YOLOv8 models, use the following Python script: + +```python +from ultralytics import YOLO + +# Load a YOLOv8 model +model = YOLO("yolov8n.pt") + +# Export the model +model.export(format="onnx", opset=12, simplify=True, dynamic=False, imgsz=640) +``` + +Alternatively, you can use the following command for exporting the model in the terminal + +```bash +yolo export model=yolov8n.pt opset=12 simplify=True dynamic=False format=onnx imgsz=640,640 +``` + +## Download COCO.yaml file 📂 + +In order to run example, you also need to download coco.yaml. You can download the file manually from [here](https://raw.githubusercontent.com/ultralytics/ultralytics/main/ultralytics/cfg/datasets/coco.yaml) + +## Dependencies ⚙️ + +| Dependency | Version | +| -------------------------------- | -------------- | +| Onnxruntime(linux,windows,macos) | >=1.14.1 | +| OpenCV | >=4.0.0 | +| C++ Standard | >=17 | +| Cmake | >=3.5 | +| Cuda (Optional) | >=11.4 \<12.0 | +| cuDNN (Cuda required) | =8 | + +Note: The dependency on C++17 is due to the usage of the C++17 filesystem feature. + +Note (2): Due to ONNX Runtime, we need to use CUDA 11 and cuDNN 8. Keep in mind that this requirement might change in the future. + +## Build 🛠️ + +1. Clone the repository to your local machine. +1. Navigate to the root directory of the repository. +1. Create a build directory and navigate to it: + +```console +mkdir build && cd build +``` + +4. Run CMake to generate the build files: + +```console +cmake .. +``` + +5. Build the project: + +```console +make +``` + +6. The built executable should now be located in the `build` directory. + +## Usage 🚀 + +```c++ +// CPU inference +DCSP_INIT_PARAM params{ model_path, YOLO_ORIGIN_V8, {imgsz_w, imgsz_h}, 0.1, 0.5, false}; +// GPU inference +DCSP_INIT_PARAM params{ model_path, YOLO_ORIGIN_V8, {imgsz_w, imgsz_h}, 0.1, 0.5, true}; +// Load your image +cv::Mat img = cv::imread(img_path); +// Init Inference Session +char* ret = yoloDetector->CreateSession(params); + +ret = yoloDetector->RunSession(img, res); +``` + +This repository should also work for YOLOv5, which needs a permute operator for the output of the YOLOv5 model, but this has not been implemented yet. diff --git a/ultralytics/examples/YOLOv8-ONNXRuntime-CPP/inference.cpp b/ultralytics/examples/YOLOv8-ONNXRuntime-CPP/inference.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7e9d0aa5169e3b843776d801b0af99f514d9f164 --- /dev/null +++ b/ultralytics/examples/YOLOv8-ONNXRuntime-CPP/inference.cpp @@ -0,0 +1,290 @@ +#include "inference.h" +#include+ + + +
+