yolov5 Documentation

Ultralytics YOLOv5 in PyTorch for object detection, instance segmentation, classification, training, and export.

RAW Doc

Docker & Self-Hosted Deployment Verified OCI

Deploy yolov5 on any server, homelab, or cloud container platform.

1-Click Terminal Command
bash (docker run)
docker run -d --name yolov5 --restart always wang-xinyu/yolov5:latest

1. Project Overview & Quickstart (ultralytics/yolov5)

File: README.md

Ultralytics YOLOv5 ๐Ÿš€ is a fast, accurate, and easy-to-use computer vision model developed by Ultralytics. Based on the PyTorch framework, YOLOv5 is renowned for its speed, accuracy, and simplicity. It incorporates insights and best practices from extensive research and development, making it a popular and reliable choice for a wide range of vision AI tasks, including object detection, image segmentation, and image classification.

We hope the resources here help you get the most out of YOLOv5. Please browse the YOLOv5 Docs for detailed information, raise an issue on GitHub for support, and join our Discord community for questions and discussions!

To request an Enterprise License, please complete the form at Ultralytics Licensing.

๐Ÿš€ Explore the Ultralytics YOLO Ecosystem

YOLOv5 is a mature, production-proven model that remains an excellent choice for fast and reliable object detection, instance segmentation, and image classification. If your project calls for the newest architectures, additional tasks such as pose estimation and oriented object detection (OBB), or a unified Python and CLI interface, the actively maintained ultralytics package brings the latest Ultralytics YOLO models together in one place. Explore the Ultralytics Docs to find the best fit for your use case.

bash
# Install the ultralytics package for the latest Ultralytics YOLO models
pip install ultralytics

๐Ÿ“š Documentation

See the YOLOv5 Docs for full documentation on training, testing, and deployment. See below for quickstart examples.

Install

Clone the repository and install dependencies in a Python>=3.8.0 environment. Ensure you have PyTorch>=1.8 installed.

bash
# Clone the YOLOv5 repository
git clone https://github.com/ultralytics/yolov5

# Navigate to the cloned directory
cd yolov5

# Install required packages
pip install -r requirements.txt

Inference with PyTorch Hub

Use YOLOv5 via PyTorch Hub for inference. Models are automatically downloaded from the latest YOLOv5 release.

python
import torch

# Load a YOLOv5 model (options: yolov5n, yolov5s, yolov5m, yolov5l, yolov5x)
model = torch.hub.load("ultralytics/yolov5", "yolov5s")  # Default: yolov5s

# Define the input image source (URL, local file, PIL image, OpenCV frame, numpy array, or list)
img = "https://ultralytics.com/images/zidane.jpg"  # Example image

# Perform inference (handles batching, resizing, normalization automatically)
results = model(img)

# Process the results (options: .print(), .show(), .save(), .crop(), .pandas())
results.print()  # Print results to console
results.show()  # Display results in a window
results.save()  # Save results to runs/detect/exp

Inference with detect.py

The detect.py script runs inference on various sources. It automatically downloads models from the latest YOLOv5 release and saves the results to the runs/detect directory.

bash
# Run inference using a webcam
python detect.py --weights yolov5s.pt --source 0

# Run inference on a local image file
python detect.py --weights yolov5s.pt --source img.jpg

# Run inference on a local video file
python detect.py --weights yolov5s.pt --source vid.mp4

# Run inference on a screen capture
python detect.py --weights yolov5s.pt --source screen

# Run inference on a directory of images
python detect.py --weights yolov5s.pt --source path/to/images/

# Run inference on a text file listing image paths
python detect.py --weights yolov5s.pt --source list.txt

# Run inference on a text file listing stream URLs
python detect.py --weights yolov5s.pt --source list.streams

# Run inference using a glob pattern for images
python detect.py --weights yolov5s.pt --source 'path/to/*.jpg'

# Run inference on a YouTube video URL
python detect.py --weights yolov5s.pt --source 'https://youtu.be/LNwODJXcvt4'

# Run inference on an RTSP, RTMP, or HTTP stream
python detect.py --weights yolov5s.pt --source 'rtsp://example.com/media.mp4'

Training

The commands below demonstrate how to reproduce YOLOv5 COCO dataset results. Both models and datasets are downloaded automatically from the latest YOLOv5 release. Training times for YOLOv5n/s/m/l/x are approximately 1/2/4/6/8 days on a single NVIDIA V100 GPU. Using Multi-GPU training can significantly reduce training time. Use the largest --batch-size your hardware allows, or use --batch-size -1 for YOLOv5 AutoBatch. The batch sizes shown below are for V100-16GB GPUs.

bash
# Train YOLOv5n on COCO for 300 epochs
python train.py --data coco.yaml --epochs 300 --weights '' --cfg yolov5n.yaml --batch-size 128

# Train YOLOv5s on COCO for 300 epochs
python train.py --data coco.yaml --epochs 300 --weights '' --cfg yolov5s.yaml --batch-size 64

# Train YOLOv5m on COCO for 300 epochs
python train.py --data coco.yaml --epochs 300 --weights '' --cfg yolov5m.yaml --batch-size 40

# Train YOLOv5l on COCO for 300 epochs
python train.py --data coco.yaml --epochs 300 --weights '' --cfg yolov5l.yaml --batch-size 24

# Train YOLOv5x on COCO for 300 epochs
python train.py --data coco.yaml --epochs 300 --weights '' --cfg yolov5x.yaml --batch-size 16

Tutorials

๐Ÿงฉ Integrations

Our key integrations with leading AI platforms extend the functionality of Ultralytics' offerings, enhancing tasks like dataset labeling, training, visualization, and model management. Discover how Ultralytics, in collaboration with partners like Weights & Biases, Comet ML, Roboflow, and Intel OpenVINO, can optimize your AI workflow. Explore more at Ultralytics Integrations.

๐Ÿค” Why YOLOv5?

YOLOv5 is designed for simplicity and ease of use. We prioritize real-world performance and accessibility.

YOLOv5-P5 640 Figure

Figure Notes

Pretrained Checkpoints

This table shows the performance metrics for various YOLOv5 models trained on the COCO dataset.

Model Size(pixels) mAPval50-95 mAPval50 SpeedCPU b1(ms) SpeedV100 b1(ms) SpeedV100 b32(ms) Params(M) FLOPs@640 (B)
YOLOv5n 640 28.0 45.7 45 6.3 0.6 1.9 4.5
YOLOv5s 640 37.4 56.8 98 6.4 0.9 7.2 16.5
YOLOv5m 640 45.4 64.1 224 8.2 1.7 21.2 49.0
YOLOv5l 640 49.0 67.3 430 10.1 2.7 46.5 109.1
YOLOv5x 640 50.7 68.9 766 12.1 4.8 86.7 205.7
YOLOv5n6 1280 36.0 54.4 153 8.1 2.1 3.2 4.6
YOLOv5s6 1280 44.8 63.7 385 8.2 3.6 12.6 16.8
YOLOv5m6 1280 51.3 69.3 887 11.1 6.8 35.7 50.0
YOLOv5l6 1280 53.7 71.3 1784 15.8 10.5 76.8 111.4
YOLOv5x6+ [TTA] 12801536 55.055.8 72.772.7 3136- 26.2- 19.4- 140.7- 209.8-

Table Notes

  • The 640-pixel rows report the legacy anchor-based YOLOv5 checkpoints, while their links open the corresponding anchor-free YOLOv5u successor models on Ultralytics Platform. P6 links continue to download the legacy 1280-pixel checkpoints directly.
  • All checkpoints were trained for 300 epochs using default settings. Nano (n) and Small (s) models use hyp.scratch-low.yaml hyperparameters, while Medium (m), Large (l), and Extra-Large (x) models use hyp.scratch-high.yaml.
  • mAPval values represent single-model, single-scale performance on the COCO val2017 dataset.Reproduce using: python val.py --data coco.yaml --img 640 --conf 0.001 --iou 0.65
  • Speed metrics are averaged over COCO val images using an AWS p3.2xlarge V100 instance. Non-Maximum Suppression (NMS) time (~1 ms/image) is not included.Reproduce using: python val.py --data coco.yaml --img 640 --task speed --batch 1
  • TTA (Test Time Augmentation) includes reflection and scale augmentations for improved accuracy.Reproduce using: python val.py --data coco.yaml --img 1536 --iou 0.7 --augment

๐Ÿ–ผ๏ธ Segmentation

The YOLOv5 release v7.0 introduced instance segmentation models designed for easy training, validation, and deployment. For full details, see the Release Notes and explore the YOLOv5 Segmentation Colab Notebook for quickstart examples.

Segmentation Checkpoints

YOLOv5 segmentation models were trained on the COCO dataset for 300 epochs at an image size of 640 pixels using A100 GPUs. Models were exported to ONNX FP32 for CPU speed tests and TensorRT FP16 for GPU speed tests. All speed tests were conducted on Google Colab Pro notebooks for reproducibility.

Model Size(pixels) mAPbox50-95 mAPmask50-95 Train Time300 epochsA100 (hours) SpeedONNX CPU(ms) SpeedTRT A100(ms) Params(M) FLOPs@640 (B)
YOLOv5n-seg 640 27.6 23.4 80:17 62.7 1.2 2.0 7.1
YOLOv5s-seg 640 37.6 31.7 88:16 173.3 1.4 7.6 26.4
YOLOv5m-seg 640 45.0 37.1 108:36 427.0 2.2 22.0 70.8
YOLOv5l-seg 640 49.0 39.9 66:43 (2x) 857.4 2.9 47.9 147.7
YOLOv5x-seg 640 50.7 41.4 62:56 (3x) 1579.2 4.5 88.8 265.7
  • All checkpoints were trained for 300 epochs using the SGD optimizer with lr0=0.01 and weight_decay=5e-5 at an image size of 640 pixels, using default settings.Training runs are logged at https://wandb.ai/glenn-jocher/YOLOv5_v70_official.

  • Accuracy values represent single-model, single-scale performance on the COCO dataset.Reproduce using: python segment/val.py --data coco.yaml --weights yolov5s-seg.pt

  • Speed metrics are averaged over 100 inference images using a Colab Pro A100 High-RAM instance. Values indicate inference speed only (NMS adds approximately 1ms per image).Reproduce using: python segment/val.py --data coco.yaml --weights yolov5s-seg.pt --batch 1

  • Export to ONNX (FP32) and TensorRT (FP16) was performed using export.py.Reproduce using: python export.py --weights yolov5s-seg.pt --include engine --device 0 --half

    Segmentation Usage Examples  

Train

YOLOv5 segmentation training supports automatic download of the COCO128-seg dataset via the --data coco128-seg.yaml argument. For the full COCO-segments dataset, download it manually using bash data/scripts/get_coco.sh --train --val --segments and then train with python segment/train.py --data coco.yaml.

bash
# Train on a single GPU
python segment/train.py --data coco128-seg.yaml --weights yolov5s-seg.pt --img 640

# Train using Multi-GPU Distributed Data Parallel (DDP)
python -m torch.distributed.run --nproc_per_node 4 --master_port 1 segment/train.py --data coco128-seg.yaml --weights yolov5s-seg.pt --img 640 --device 0,1,2,3

Val

Validate the mask mean Average Precision (mAP) of YOLOv5s-seg on the COCO dataset:

bash
# Download COCO validation segments split (780MB, 5000 images)
bash data/scripts/get_coco.sh --val --segments

# Validate the model
python segment/val.py --weights yolov5s-seg.pt --data coco.yaml --img 640

Predict

Use the pretrained YOLOv5m-seg.pt model to perform segmentation on bus.jpg:

bash
# Run prediction
python segment/predict.py --weights yolov5m-seg.pt --source data/images/bus.jpg
python
# Load model from PyTorch Hub (Note: Inference support might vary)
model = torch.hub.load("ultralytics/yolov5", "custom", "yolov5m-seg.pt")

Export

Export the YOLOv5s-seg model to ONNX and TensorRT formats:

bash
# Export model
python export.py --weights yolov5s-seg.pt --include onnx engine --img 640 --device 0

๐Ÿท๏ธ Classification

YOLOv5 release v6.2 introduced support for image classification model training, validation, and deployment. Check the Release Notes for details and the YOLOv5 Classification Colab Notebook for quickstart guides.

Classification Checkpoints

YOLOv5-cls classification models were trained on ImageNet for 90 epochs using a 4xA100 instance. ResNet and EfficientNet models were trained alongside under identical settings for comparison. Models were exported to ONNX FP32 (CPU speed tests) and TensorRT FP16 (GPU speed tests). All speed tests were run on Google Colab Pro for reproducibility.

Model Size(pixels) Acctop1 Acctop5 Training90 epochs4xA100 (hours) SpeedONNX CPU(ms) SpeedTensorRT V100(ms) Params(M) FLOPs@224 (B)
YOLOv5n-cls 224 64.6 85.4 7:59 3.3 0.5 2.5 0.5
YOLOv5s-cls 224 71.5 90.2 8:09 6.6 0.6 5.4 1.4
YOLOv5m-cls 224 75.9 92.9 10:06 15.5 0.9 12.9 3.9
YOLOv5l-cls 224 78.0 94.0 11:56 26.9 1.4 26.5 8.5
YOLOv5x-cls 224 79.0 94.4 15:04 54.3 1.8 48.1 15.9
ResNet18 224 70.3 89.5 6:47 11.2 0.5 11.7 3.7
ResNet34 224 73.9 91.8 8:33 20.6 0.9 21.8 7.4
ResNet50 224 76.8 93.4 11:10 23.4 1.0 25.6 8.5
ResNet101 224 78.5 94.3 17:10 42.1 1.9 44.5 15.9
EfficientNet_b0 224 75.1 92.4 13:03 12.5 1.3 5.3 1.0
EfficientNet_b1 224 76.4 93.2 17:04 14.9 1.6 7.8 1.5
EfficientNet_b2 224 76.6 93.4 17:10 15.9 1.6 9.1 1.7
EfficientNet_b3 224 77.7 94.0 19:19 18.9 1.9 12.2 2.4

Table Notes (click to expand)

  • All checkpoints were trained for 90 epochs using the SGD optimizer with lr0=0.001 and weight_decay=5e-5 at an image size of 224 pixels, using default settings.Training runs are logged at https://wandb.ai/glenn-jocher/YOLOv5-Classifier-v6-2.

  • Accuracy values (top-1 and top-5) represent single-model, single-scale performance on the ImageNet-1k dataset.Reproduce using: python classify/val.py --data ../datasets/imagenet --img 224

  • Speed metrics are averaged over 100 inference images using a Google Colab Pro V100 High-RAM instance.Reproduce using: python classify/val.py --data ../datasets/imagenet --img 224 --batch 1

  • Export to ONNX (FP32) and TensorRT (FP16) was performed using export.py.Reproduce using: python export.py --weights yolov5s-cls.pt --include engine onnx --imgsz 224

    Classification Usage Examples  

Train

YOLOv5 classification training supports automatic download for datasets like MNIST, Fashion-MNIST, CIFAR10, CIFAR100, Imagenette, Imagewoof, and ImageNet using the --data argument. For example, start training on MNIST with --data mnist.

bash
# Train on a single GPU using CIFAR-100 dataset
python classify/train.py --model yolov5s-cls.pt --data cifar100 --epochs 5 --img 224 --batch 128

# Train using Multi-GPU DDP on ImageNet dataset
python -m torch.distributed.run --nproc_per_node 4 --master_port 1 classify/train.py --model yolov5s-cls.pt --data imagenet --epochs 5 --img 224 --device 0,1,2,3

Val

Validate the accuracy of the YOLOv5m-cls model on the ImageNet-1k validation dataset:

bash
# Download ImageNet validation split (6.3GB, 50,000 images)
bash data/scripts/get_imagenet.sh --val

# Validate the model
python classify/val.py --weights yolov5m-cls.pt --data ../datasets/imagenet --img 224

Predict

Use the pretrained YOLOv5s-cls.pt model to classify the image bus.jpg:

bash
# Run prediction
python classify/predict.py --weights yolov5s-cls.pt --source data/images/bus.jpg
python
# Load model from PyTorch Hub
model = torch.hub.load("ultralytics/yolov5", "custom", "yolov5s-cls.pt")

Export

Export trained YOLOv5s-cls, ResNet50, and EfficientNet_b0 models to ONNX and TensorRT formats:

bash
# Export models
python export.py --weights yolov5s-cls.pt resnet50.pt efficientnet_b0.pt --include onnx engine --img 224

โ˜๏ธ Environments

Get started quickly with our pre-configured environments. Click the icons below for setup details.

๐Ÿค Contribute

We welcome your contributions! Making YOLOv5 accessible and effective is a community effort. Please see our Contributing Guide to get started. Share your feedback through the YOLOv5 Survey. Thank you to all our contributors for making YOLOv5 better!

๐Ÿ“œ License

Ultralytics provides two licensing options to meet different needs:

  • AGPL-3.0 License: An OSI-approved open-source license ideal for academic research, personal projects, and testing. It promotes open collaboration and knowledge sharing. See the LICENSE file for details.
  • Enterprise License: Tailored for commercial applications, this license allows seamless integration of Ultralytics software and AI models into commercial products and services, bypassing the open-source requirements of AGPL-3.0. For commercial use cases, please contact us via Ultralytics Licensing.

๐Ÿ“ง Contact

For bug reports and feature requests related to YOLOv5, please visit GitHub Issues. For general questions, discussions, and community support, join our Discord server!


File: utils/flask_rest_api/README.md

Flask REST API for YOLOv5

Representational State Transfer (REST) Application Programming Interfaces (APIs) provide a standardized way to expose Machine Learning (ML) models for use by other services or applications. This directory contains an example REST API built with the Flask web framework to serve the Ultralytics YOLOv5s model, loaded directly from PyTorch Hub. This setup allows you to easily integrate YOLOv5 object detection capabilities into your web applications or microservices, aligning with common model deployment options.

๐Ÿ’ป Requirements

The primary requirement is the Flask web framework. You can install it using pip:

shell
pip install Flask

You will also need torch and yolov5. These are implicitly handled by the script when it loads the model from PyTorch Hub. Ensure you have a functioning Python environment set up.

โ–ถ๏ธ Run the API

Once Flask is installed, you can start the API server using the following command:

shell
python restapi.py --port 5000

The server will begin listening on the specified port (defaulting to 5000). You can then send inference requests to the API endpoint using tools like curl or any other HTTP client.

To test the API with a local image file (e.g., zidane.jpg located in the yolov5/data/images directory, which is ../../data/images/zidane.jpg relative to the script):

shell
curl -X POST -F image=@../../data/images/zidane.jpg 'http://localhost:5000/v1/object-detection/yolov5s'

The API processes the submitted image using the YOLOv5s model and returns the detection results in JSON format. Each object within the JSON array represents a detected item, including its pixel bounding box coordinates (xmin, ymin, xmax, ymax), confidence score, class ID, and class name.

json
[
  {
    "xmin": 749.5,
    "ymin": 43.5,
    "xmax": 1148.0,
    "ymax": 704.5,
    "confidence": 0.8900438547,
    "class": 0,
    "name": "person"
  },
  {
    "xmin": 113.5,
    "ymin": 196.0,
    "xmax": 1093.0,
    "ymax": 711.0,
    "confidence": 0.8440024257,
    "class": 0,
    "name": "person"
  },
  {
    "xmin": 437.5,
    "ymin": 433.5,
    "xmax": 529.5,
    "ymax": 717.5,
    "confidence": 0.3771208823,
    "class": 27,
    "name": "tie"
  },
  {
    "xmin": 1090.0,
    "ymin": 312.0,
    "xmax": 1135.0,
    "ymax": 410.0,
    "confidence": 0.3527112305,
    "class": 27,
    "name": "tie"
  }
]

An example Python script, example_request.py, is included to demonstrate how to perform inference using the popular requests library. This script offers a straightforward method for interacting with the running API programmatically.

To require authentication, set API_KEY when starting the server and include it in each request:

shell
API_KEY=mysecretkey python restapi.py --port 5000
curl -H 'X-API-Key: mysecretkey' -F image=@../../data/images/zidane.jpg 'http://localhost:5000/v1/object-detection/yolov5s'

๐Ÿค Contribute

Contributions to enhance this Flask API example are highly encouraged! Whether you're interested in adding support for different YOLO models, improving error handling, or implementing new features, please feel free to fork the repository, apply your changes, and submit a pull request. For more comprehensive contribution guidelines, please refer to the main Ultralytics YOLOv5 repository and the general Ultralytics documentation.


File: utils/loggers/clearml/README.md

ClearML Integration with Ultralytics YOLO

โ„น๏ธ About ClearML

ClearML is an open-source MLOps platform. Integrating it with Ultralytics YOLO provides experiment tracking, data management, and remote execution:

You can use ClearML's experiment manager alone or combine these features into a comprehensive MLOps pipeline.

๐Ÿฆพ Setting Up ClearML

ClearML requires a server to track experiments and data. You have two main options:

  1. ClearML Hosted Service: Sign up for a free account at app.clear.ml.
  2. Self-Hosted Server: Deploy your own ClearML server using the official setup guide. The server is open-source, ensuring data privacy and control.

To get started:

  1. Install the ClearML Python package:

    bash
    pip install clearml

    Note: The clearml package is listed (commented out) in requirements.txt and is not installed by default โ€” install it with the command above.

  2. Connect the ClearML SDK to your server:
    Create credentials (Settings โ†’ Workspace โ†’ Create new credentials), then run:

    bash
    clearml-init

    Follow the prompts to complete setup.

For a general Ultralytics setup, see the Quickstart Guide.

๐Ÿš€ Training YOLO with ClearML

When the clearml package is installed, experiment tracking is automatically enabled for every YOLO training run. All experiment details are captured and stored in the ClearML experiment manager.

To customize your project or task name in ClearML, use the --project and --name arguments. By default, the project is YOLOv5 and the task is Training. ClearML uses / as a delimiter for subprojects.

Example Training Command:

bash
# Train YOLO on COCO128 dataset for 3 epochs
python train.py --img 640 --batch 16 --epochs 3 --data coco128.yaml --weights yolov5s.pt --cache

Example with Custom Project and Task Names:

bash
# Train with custom project and experiment names
python train.py --project my_yolo_project --name experiment_001 --img 640 --batch 16 --epochs 3 --data coco128.yaml --weights yolov5s.pt --cache

ClearML automatically logs:

  • Source code and uncommitted changes
  • Installed Python packages
  • Hyperparameters and configuration settings
  • Model checkpoints (use --save-period n to save every n epochs)
  • Console output logs
  • Performance metrics (precision, recall, losses, learning rates, mAP0.5, mAP0.5:0.95)
  • System details (hardware specs, runtime, creation date)
  • Generated plots (label correlogram, confusion matrix)
  • Images with bounding boxes per epoch
  • Mosaic augmentation previews per epoch
  • Validation images per epoch

All this information can be visualized in the ClearML UI. You can customize table views, sort experiments by metrics, and compare multiple runs. This enables advanced features like hyperparameter optimization and remote execution.

๐Ÿ”— Dataset Version Management

Versioning your datasets independently from code is essential for reproducibility and collaboration. ClearML's Data Versioning Tool streamlines this process. YOLO supports ClearML dataset version IDs, automatically downloading data as needed. The dataset ID is saved as a task parameter, ensuring traceability for every experiment.

Prepare Your Dataset

YOLO uses YAML files to define dataset configurations. By default, datasets are expected in the ../datasets directory relative to the repository root. For example, the COCO128 dataset structure:

text
../
โ”œโ”€โ”€ yolov5/          # Your YOLO repository clone
โ””โ”€โ”€ datasets/
    โ””โ”€โ”€ coco128/
        โ”œโ”€โ”€ images/
        โ”œโ”€โ”€ labels/
        โ”œโ”€โ”€ LICENSE
        โ””โ”€โ”€ README.txt

Ensure your custom dataset follows a similar structure.

Next, โš ๏ธ copy the corresponding dataset .yaml file into the root of your dataset folder. This file contains essential information (path, train, test, val, nc, names) required by ClearML.

text
../
โ””โ”€โ”€ datasets/
    โ””โ”€โ”€ coco128/
        โ”œโ”€โ”€ images/
        โ”œโ”€โ”€ labels/
        โ”œโ”€โ”€ coco128.yaml  # <---- Place the YAML file here!
        โ”œโ”€โ”€ LICENSE
        โ””โ”€โ”€ README.txt

Upload Your Dataset

Navigate to your dataset's root directory and use the clearml-data CLI tool:

bash
cd ../datasets/coco128
clearml-data sync --project YOLO_Datasets --name coco128 --folder .

Alternatively, use the following commands:

bash
# Create a new dataset entry in ClearML
clearml-data create --project YOLO_Datasets --name coco128

# Add the dataset files (use '.' for the current directory)
clearml-data add --files .

# Finalize and upload the dataset version
clearml-data close

Tip: Use --parent with clearml-data create to link versions and avoid re-uploading unchanged files.

Run Training Using a ClearML Dataset

Once your dataset is versioned in ClearML, you can use it for training by providing the dataset ID via the --data argument with the clearml:// prefix:

bash
# Replace YOUR_DATASET_ID with the actual ID from ClearML
python train.py --img 640 --batch 16 --epochs 3 --data clearml://YOUR_DATASET_ID --weights yolov5s.pt --cache

๐Ÿ‘€ Hyperparameter Optimization

With experiments and data versioned, you can leverage ClearML for hyperparameter optimization. ClearML captures all necessary information (code, packages, environment), making experiments fully reproducible. Its HPO tools clone an existing experiment, modify hyperparameters, and rerun it automatically.

To run HPO locally, use the provided script utils/loggers/clearml/hpo.py. You'll need the ID of a previously run training task (the "template task") to clone. Update the script with this ID and run:

bash
# Install Optuna, required by the optimizer used in the script
pip install optuna

# Run the HPO script
python utils/loggers/clearml/hpo.py

The script uses Optuna (via OptimizerOptuna) to search the hyperparameter space, so the optuna package must be installed. To enqueue HPO tasks for a remote ClearML agent instead of running locally, replace optimizer.start_locally() with optimizer.start() in the script and provide an execution queue.

๐Ÿคฏ Remote Execution (Advanced)

ClearML Agent enables you to execute experiments on remote machines, including on-premise servers or cloud GPUs such as AWS, Google Cloud, or Azure. The agent listens to task queues, reproduces the experiment environment, runs the task, and reports results back to the ClearML server.

Learn more about ClearML Agent:

Turn any machine into a ClearML agent by running:

bash
# Replace QUEUES_TO_LISTEN_TO with your queue name(s)
clearml-agent daemon --queue QUEUES_TO_LISTEN_TO [--docker] # Use --docker to run in a Docker container

Cloning, Editing, and Enqueuing Tasks

You can manage remote execution directly from the ClearML web UI:

  1. Clone: Right-click an existing experiment to clone it.
  2. Edit: Modify hyperparameters or other settings in the cloned task.
  3. Enqueue: Right-click the modified task and select "Enqueue" to assign it to a specific queue for an agent to pick up.

Executing a Task Remotely via Code

You can also modify your training script to automatically enqueue tasks for remote execution. Add task.execute_remotely() after the ClearML logger is initialized in train.py:

python
# Inside train.py, after logger initialization...
if RANK in {-1, 0}:
    # Initialize loggers
    loggers = Loggers(save_dir, weights, opt, hyp, LOGGER)

    # Check if ClearML logger is active and enqueue the task
    if loggers.clearml:
        # Specify the queue name for the remote agent
        loggers.clearml.task.execute_remotely(queue_name="my_remote_queue")  # <------ ADD THIS LINE
        # data_dict might be populated by ClearML if using a ClearML dataset
        data_dict = loggers.clearml.data_dict

Running the script with this modification will package the code and its environment and send it to the specified queue, rather than executing locally.

Autoscaling Workers

ClearML provides Autoscalers that automatically manage cloud resources (AWS, GCP, Azure). They spin up new virtual machines as ClearML agents when tasks appear in a queue, and shut them down when the queue is empty, optimizing cost.

Watch the Autoscalers getting started video:

๐Ÿค Contributing

Contributions to enhance the ClearML integration are welcome! Please see the Ultralytics Contributing Guide for details on how to get involved.



File: utils/loggers/comet/README.md

Using Ultralytics YOLO With Comet

This guide explains how to integrate Ultralytics YOLO with Comet for monitoring training, logging results, managing datasets, and optimizing hyperparameters.




๐Ÿงช About Comet

Comet provides tools for data scientists, engineers, and teams to accelerate and optimize deep learning and machine learning models.

With Comet, you can track and visualize model metrics in real time, save hyperparameters, datasets, and model checkpoints, and visualize predictions using Custom Panels. For more details, see the Comet Documentation.

๐Ÿš€ Getting Started

Follow these steps to set up Comet for your YOLO projects.

Install Comet

Install the comet_ml Python package using pip:

shell
pip install comet_ml

Configure Comet Credentials

You can configure Comet in two ways:

  1. Environment Variables:
    Set your credentials directly in your environment.

    shell
    export COMET_API_KEY=YOUR_COMET_API_KEY
    export COMET_PROJECT_NAME=YOUR_COMET_PROJECT_NAME # Defaults to 'yolov5' if not set

    Find your API key in your Comet Account Settings.

  2. Configuration File:
    Create a .comet.config file in your working directory:

    ini
    [comet]
    api_key=YOUR_COMET_API_KEY
    project_name=YOUR_COMET_PROJECT_NAME # Defaults to 'yolov5' if not set

Run the Training Script

Run the YOLO training script. Comet will automatically log your run.

shell
# Train YOLO on COCO128 for 5 epochs
python train.py --img 640 --batch 16 --epochs 5 --data coco128.yaml --weights yolov5s.pt

Comet automatically logs hyperparameters, command-line arguments, and training/validation metrics. Visualize and analyze your runs in the Comet UI. For more details, see the Ultralytics training documentation.

โœจ Try an Example!

Explore a completed YOLO training run tracked with Comet:

Run the example yourself using this Google Colab notebook:

๐Ÿ“Š Automatic Logging

Comet automatically logs the following information by default:

Metrics

Parameters

  • Model Hyperparameters: Configuration used for the model
  • Command Line Arguments: All arguments passed via the CLI

Visualizations

  • Confusion Matrix: Model predictions on validation data (Wikipedia)
  • Curves: PR and F1 curves across all classes
  • Label Correlogram: Correlation visualization of class labels

โš™๏ธ Advanced Configuration

Customize Comet's logging behavior using command-line flags or environment variables.

shell
# Environment Variables for Comet Configuration
export COMET_MODE=online                                    # 'online' or 'offline'. Default: online
export COMET_MODEL_NAME=YOUR_MODEL_NAME                     # Name for the saved model. Default: yolov5
export COMET_LOG_CONFUSION_MATRIX=false                     # Disable confusion matrix logging. Default: true
export COMET_MAX_IMAGE_UPLOADS=NUMBER                       # Max prediction images to log. Default: 100
export COMET_LOG_PER_CLASS_METRICS=true                     # Log metrics per class. Default: false
export COMET_DEFAULT_CHECKPOINT_FILENAME=checkpoint_file.pt # Checkpoint for resuming. Default: 'last.pt'
export COMET_LOG_BATCH_METRICS=true                         # Log training metrics per batch. Default: false
export COMET_LOG_PREDICTIONS=true                           # Disable prediction logging if set to false. Default: true

For more configuration options, see the Comet documentation.

Logging Checkpoints With Comet

Model checkpoint logging to Comet is disabled by default. Enable it using the --save-period argument during training to save checkpoints at the specified epoch interval.

shell
python train.py \
  --img 640 \
  --batch 16 \
  --epochs 5 \
  --data coco128.yaml \
  --weights yolov5s.pt \
  --save-period 1 # Save checkpoint every epoch

Checkpoints will appear in the "Assets & Artifacts" tab of your Comet experiment. Learn more about model management in the Comet Model Registry documentation.

Logging Model Predictions

By default, model predictions (images, ground truth labels, bounding boxes) for the validation set are logged. Control the logging frequency using the --bbox_interval argument, which specifies logging every Nth batch per epoch.

Note: The YOLO validation dataloader defaults to a batch size of 32. Adjust --bbox_interval as needed.

Visualize predictions using Comet's Object Detection Custom Panel. See an example project using the Panel.

shell
python train.py \
  --img 640 \
  --batch 16 \
  --epochs 5 \
  --data coco128.yaml \
  --weights yolov5s.pt \
  --bbox_interval 2 # Log predictions every 2nd validation batch per epoch

Controlling the Number of Prediction Images

Adjust the maximum number of validation images logged using the COMET_MAX_IMAGE_UPLOADS environment variable.

shell
env COMET_MAX_IMAGE_UPLOADS=200 python train.py \
  --img 640 \
  --batch 16 \
  --epochs 5 \
  --data coco128.yaml \
  --weights yolov5s.pt \
  --bbox_interval 1 # Log every batch

Logging Class Level Metrics

Enable logging of mAP, precision, recall, and F1-score for each class using the COMET_LOG_PER_CLASS_METRICS environment variable.

shell
env COMET_LOG_PER_CLASS_METRICS=true python train.py \
  --img 640 \
  --batch 16 \
  --epochs 5 \
  --data coco128.yaml \
  --weights yolov5s.pt

๐Ÿ’พ Dataset Management With Comet Artifacts

Use Comet Artifacts to version, store, and manage your datasets.

Uploading a Dataset

Upload your dataset using the --upload_dataset flag. Ensure your dataset follows the structure described in the Ultralytics Datasets documentation and that your dataset config YAML file matches the format of coco128.yaml (see the COCO128 dataset docs).

shell
python train.py \
  --img 640 \
  --batch 16 \
  --epochs 5 \
  --data coco128.yaml \
  --weights yolov5s.pt \
  --upload_dataset # Upload the dataset specified in coco128.yaml

View the uploaded dataset in the Artifacts tab of your Comet Workspace.

Preview data directly in the Comet UI.

Artifacts are versioned and support metadata. Comet automatically logs metadata from your dataset YAML file.

Using a Saved Artifact

To use a dataset stored in Comet Artifacts, update the path in your dataset YAML file to the Artifact resource URL:

yaml
# contents of artifact.yaml
path: "comet://WORKSPACE_NAME/ARTIFACT_NAME:ARTIFACT_VERSION_OR_ALIAS"
train: images/train # Adjust subdirectory if needed
val: images/val # Adjust subdirectory if needed


# Other dataset configurations...

Then, pass this configuration file to your training script:

shell
python train.py \
  --img 640 \
  --batch 16 \
  --epochs 5 \
  --data artifact.yaml \
  --weights yolov5s.pt

Artifacts track data lineage, showing which experiments used specific dataset versions.

๐Ÿ”„ Resuming Training Runs

If a training run is interrupted (for example, due to connection issues), you can resume it using the --resume flag with the Comet Run Path (comet://YOUR_WORKSPACE/YOUR_PROJECT/EXPERIMENT_ID).

This restores the model state, hyperparameters, arguments, and downloads necessary Artifacts, continuing logging to the existing Comet Experiment. Learn more about resuming runs in the Comet documentation.

shell
python train.py \
  --resume "comet://YOUR_WORKSPACE/YOUR_PROJECT/EXPERIMENT_ID"

๐Ÿ” Hyperparameter Optimization (HPO)

YOLO integrates with the Comet Optimizer for easy hyperparameter sweeps and visualization. This helps you find the best set of parameters for your model, a process often referred to as Hyperparameter Tuning.

Configuring an Optimizer Sweep

Create a JSON configuration file defining the sweep parameters, search strategy, and objective metric. An example is provided at utils/loggers/comet/optimizer_config.json.

Run the sweep using the hpo.py script:

shell
python utils/loggers/comet/hpo.py \
  --comet_optimizer_config "utils/loggers/comet/optimizer_config.json"

The hpo.py script accepts the same arguments as train.py. Pass additional fixed arguments for the sweep:

shell
python utils/loggers/comet/hpo.py \
  --comet_optimizer_config "utils/loggers/comet/optimizer_config.json" \
  --save-period 1 \
  --bbox_interval 1

Running a Sweep in Parallel

Execute multiple sweep trials concurrently using the comet optimize command:

shell
comet optimize -j NUM_WORKERS \
  utils/loggers/comet/hpo.py utils/loggers/comet/optimizer_config.json

Replace NUM_WORKERS with the desired number of parallel processes.

Visualizing HPO Results

Comet offers various visualizations for analyzing sweep results, such as parallel coordinate plots and parameter importance plots. Explore a project with a completed sweep.

๐Ÿค Contributing

Contributions to enhance the YOLO-Comet integration are welcome! Please see the Ultralytics Contributing Guide for more information on how to get involved. Thank you for helping improve this integration!


File: README.zh-CN.md

Ultralytics YOLOv5 ๐Ÿš€ ๆ˜ฏ็”ฑ Ultralytics ๅผ€ๅ‘็š„ไธ€ๆฌพๅฟซ้€Ÿใ€ๅ‡†็กฎไธ”ๆ˜“ไบŽไฝฟ็”จ็š„่ฎก็ฎ—ๆœบ่ง†่ง‰ๆจกๅž‹ใ€‚ๅŸบไบŽ PyTorch ๆก†ๆžถ๏ผŒYOLOv5 ไปฅๅ…ถ้€Ÿๅบฆใ€ๅ‡†็กฎๆ€งๅ’Œ็ฎ€ๆดๆ€ง่€Œ้—ปๅใ€‚ๅฎƒ่žๅˆไบ†ๅนฟๆณ›็ ”็ฉถๅ’Œๅผ€ๅ‘็š„่ง่งฃไธŽๆœ€ไฝณๅฎž่ทต๏ผŒไฝฟๅ…ถๆˆไธบๅ„็ง่ง†่ง‰ AI ไปปๅŠกไธญ็ƒญ้—จ่€Œๅฏ้ ็š„้€‰ๆ‹ฉ๏ผŒๅŒ…ๆ‹ฌ็›ฎๆ ‡ๆฃ€ๆต‹ใ€ๅ›พๅƒๅˆ†ๅ‰ฒๅ’Œๅ›พๅƒๅˆ†็ฑปใ€‚

ๆˆ‘ไปฌๅธŒๆœ›่ฟ™้‡Œ็š„่ต„ๆบ่ƒฝๅธฎๅŠฉๆ‚จๅ……ๅˆ†ๅˆฉ็”จ YOLOv5ใ€‚่ฏทๆต่งˆ YOLOv5 ๆ–‡ๆกฃ่Žทๅ–่ฏฆ็ป†ไฟกๆฏ๏ผŒๅœจ GitHub ไธŠๆๅ‡บ issue ไปฅ่Žทๅพ—ๆ”ฏๆŒ๏ผŒๅนถๅŠ ๅ…ฅๆˆ‘ไปฌ็š„ Discord ็คพๅŒบ่ฟ›่กŒๆ้—ฎๅ’Œ่ฎจ่ฎบ๏ผ

ๅฆ‚้œ€็”ณ่ฏทไผไธš่ฎธๅฏ่ฏ๏ผŒ่ฏทๅกซๅ†™ Ultralytics ๆŽˆๆƒ่ฎธๅฏ ่กจๆ ผใ€‚

๐Ÿš€ ๆŽข็ดข Ultralytics YOLO ็”Ÿๆ€็ณป็ปŸ

YOLOv5 ๆ˜ฏไธ€ไธชๆˆ็†Ÿใ€็ป่ฟ‡็”Ÿไบง้ชŒ่ฏ็š„ๆจกๅž‹๏ผŒไป็„ถๆ˜ฏๅฟซ้€Ÿๅฏ้ ็š„็›ฎๆ ‡ๆฃ€ๆต‹ใ€ๅฎžไพ‹ๅˆ†ๅ‰ฒๅ’Œๅ›พๅƒๅˆ†็ฑป็š„็ปไฝณ้€‰ๆ‹ฉใ€‚ๅฆ‚ๆžœๆ‚จ็š„้กน็›ฎ้œ€่ฆๆœ€ๆ–ฐ็š„ๆžถๆž„ใ€ๅงฟๆ€ไผฐ่ฎกๅ’Œๆ—‹่ฝฌ็›ฎๆ ‡ๆฃ€ๆต‹ (OBB)็ญ‰้ขๅค–ไปปๅŠก๏ผŒๆˆ–็ปŸไธ€็š„ Python ไธŽ CLI ๆŽฅๅฃ๏ผŒ้‚ฃไนˆๆŒ็ปญ็ปดๆŠค็š„ ultralytics ๅŒ…ๅฐ†ๆœ€ๆ–ฐ็š„ Ultralytics YOLO ๆจกๅž‹ๆฑ‡้›†ไบŽไธ€ๅค„ใ€‚ๆต่งˆ Ultralytics ๆ–‡ๆกฃไปฅๆ‰พๅˆฐๆœ€้€‚ๅˆๆ‚จ็”จไพ‹็š„ๆ–นๆกˆใ€‚

bash
# ๅฎ‰่ฃ… ultralytics ๅŒ…ไปฅ่Žทๅ–ๆœ€ๆ–ฐ็š„ Ultralytics YOLO ๆจกๅž‹
pip install ultralytics

๐Ÿ“š ๆ–‡ๆกฃ

่ฏทๅ‚้˜… YOLOv5 ๆ–‡ๆกฃ๏ผŒไบ†่งฃๆœ‰ๅ…ณ่ฎญ็ปƒใ€ๆต‹่ฏ•ๅ’Œ้ƒจ็ฝฒ็š„ๅฎŒๆ•ดๆ–‡ๆกฃใ€‚่ฏทๅ‚้˜…ไธ‹ๆ–น็š„ๅฟซ้€Ÿๅ…ฅ้—จ็คบไพ‹ใ€‚

ๅฎ‰่ฃ…

ๅ…‹้š†ไป“ๅบ“ๅนถๅœจ Python>=3.8.0 ็Žฏๅขƒไธญๅฎ‰่ฃ…ไพ่ต–้กนใ€‚็กฎไฟๆ‚จๅทฒๅฎ‰่ฃ… PyTorch>=1.8ใ€‚

bash
# ๅ…‹้š† YOLOv5 ไป“ๅบ“
git clone https://github.com/ultralytics/yolov5

# ๅฏผ่ˆชๅˆฐๅ…‹้š†็š„็›ฎๅฝ•
cd yolov5

# ๅฎ‰่ฃ…ๆ‰€้œ€็š„ๅŒ…
pip install -r requirements.txt

ไฝฟ็”จ PyTorch Hub ่ฟ›่กŒๆŽจ็†

้€š่ฟ‡ PyTorch Hub ไฝฟ็”จ YOLOv5 ่ฟ›่กŒๆŽจ็†ใ€‚ๆจกๅž‹ ไผš่‡ชๅŠจไปŽๆœ€ๆ–ฐ็š„ YOLOv5 ๅ‘ๅธƒ็‰ˆๆœฌไธ‹่ฝฝใ€‚

python
import torch

# ๅŠ ่ฝฝ YOLOv5 ๆจกๅž‹ (้€‰้กน: yolov5n, yolov5s, yolov5m, yolov5l, yolov5x)
model = torch.hub.load("ultralytics/yolov5", "yolov5s")  # ้ป˜่ฎค: yolov5s

# ๅฎšไน‰่พ“ๅ…ฅๅ›พๅƒๆบ (URLใ€ๆœฌๅœฐๆ–‡ไปถใ€PIL ๅ›พๅƒใ€OpenCV ๅธงใ€numpy ๆ•ฐ็ป„ๆˆ–ๅˆ—่กจ)
img = "https://ultralytics.com/images/zidane.jpg"  # ็คบไพ‹ๅ›พๅƒ

# ๆ‰ง่กŒๆŽจ็† (่‡ชๅŠจๅค„็†ๆ‰นๅค„็†ใ€่ฐƒๆ•ดๅคงๅฐใ€ๅฝ’ไธ€ๅŒ–)
results = model(img)

# ๅค„็†็ป“ๆžœ (้€‰้กน: .print(), .show(), .save(), .crop(), .pandas())
results.print()  # ๅฐ†็ป“ๆžœๆ‰“ๅฐๅˆฐๆŽงๅˆถๅฐ
results.show()  # ๅœจ็ช—ๅฃไธญๆ˜พ็คบ็ป“ๆžœ
results.save()  # ๅฐ†็ป“ๆžœไฟๅญ˜ๅˆฐ runs/detect/exp

ไฝฟ็”จ detect.py ่ฟ›่กŒๆŽจ็†

detect.py ่„šๆœฌๅœจๅ„็งๆฅๆบไธŠ่ฟ่กŒๆŽจ็†ใ€‚ๅฎƒไผš่‡ชๅŠจไปŽๆœ€ๆ–ฐ็š„ YOLOv5 ๅ‘ๅธƒ็‰ˆๆœฌไธ‹่ฝฝๆจกๅž‹๏ผŒๅนถๅฐ†็ป“ๆžœไฟๅญ˜ๅˆฐ runs/detect ็›ฎๅฝ•ใ€‚

bash
# ไฝฟ็”จ็ฝ‘็ปœๆ‘„ๅƒๅคด่ฟ่กŒๆŽจ็†
python detect.py --weights yolov5s.pt --source 0

# ๅฏนๆœฌๅœฐๅ›พๅƒๆ–‡ไปถ่ฟ่กŒๆŽจ็†
python detect.py --weights yolov5s.pt --source img.jpg

# ๅฏนๆœฌๅœฐ่ง†้ข‘ๆ–‡ไปถ่ฟ่กŒๆŽจ็†
python detect.py --weights yolov5s.pt --source vid.mp4

# ๅฏนๅฑๅน•ๆˆชๅ›พ่ฟ่กŒๆŽจ็†
python detect.py --weights yolov5s.pt --source screen

# ๅฏนๅ›พๅƒ็›ฎๅฝ•่ฟ่กŒๆŽจ็†
python detect.py --weights yolov5s.pt --source path/to/images/

# ๅฏนๅˆ—ๅ‡บๅ›พๅƒ่ทฏๅพ„็š„ๆ–‡ๆœฌๆ–‡ไปถ่ฟ่กŒๆŽจ็†
python detect.py --weights yolov5s.pt --source list.txt

# ๅฏนๅˆ—ๅ‡บๆต URL ็š„ๆ–‡ๆœฌๆ–‡ไปถ่ฟ่กŒๆŽจ็†
python detect.py --weights yolov5s.pt --source list.streams

# ไฝฟ็”จ glob ๆจกๅผๅฏนๅ›พๅƒ่ฟ่กŒๆŽจ็†
python detect.py --weights yolov5s.pt --source 'path/to/*.jpg'

# ๅฏน YouTube ่ง†้ข‘ URL ่ฟ่กŒๆŽจ็†
python detect.py --weights yolov5s.pt --source 'https://youtu.be/LNwODJXcvt4'

# ๅฏน RTSPใ€RTMP ๆˆ– HTTP ๆต่ฟ่กŒๆŽจ็†
python detect.py --weights yolov5s.pt --source 'rtsp://example.com/media.mp4'

่ฎญ็ปƒ

ไปฅไธ‹ๅ‘ฝไปคๆผ”็คบไบ†ๅฆ‚ไฝ•ๅค็Žฐ YOLOv5 ๅœจ COCO ๆ•ฐๆฎ้›†ไธŠ็š„็ป“ๆžœใ€‚ๆจกๅž‹ๅ’Œๆ•ฐๆฎ้›†้ƒฝไผš่‡ชๅŠจไปŽๆœ€ๆ–ฐ็š„ YOLOv5 ๅ‘ๅธƒ็‰ˆๆœฌไธ‹่ฝฝใ€‚YOLOv5n/s/m/l/x ็š„่ฎญ็ปƒๆ—ถ้—ดๅœจๅ•ไธช NVIDIA V100 GPU ไธŠๅคง็บฆ้œ€่ฆ 1/2/4/6/8 ๅคฉใ€‚ไฝฟ็”จๅคš GPU ่ฎญ็ปƒๅฏไปฅๆ˜พ่‘—ๅ‡ๅฐ‘่ฎญ็ปƒๆ—ถ้—ดใ€‚่ฏทไฝฟ็”จ็กฌไปถๅ…่ฎธ็š„ๆœ€ๅคง --batch-size๏ผŒๆˆ–ไฝฟ็”จ --batch-size -1 ไปฅๅฏ็”จ YOLOv5 AutoBatchใ€‚ไธ‹้ขๆ˜พ็คบ็š„ๆ‰นๅค„็†ๅคงๅฐ้€‚็”จไบŽ V100-16GB GPUใ€‚

bash
# ๅœจ COCO ไธŠ่ฎญ็ปƒ YOLOv5n 300 ไธชๅ‘จๆœŸ
python train.py --data coco.yaml --epochs 300 --weights '' --cfg yolov5n.yaml --batch-size 128

# ๅœจ COCO ไธŠ่ฎญ็ปƒ YOLOv5s 300 ไธชๅ‘จๆœŸ
python train.py --data coco.yaml --epochs 300 --weights '' --cfg yolov5s.yaml --batch-size 64

# ๅœจ COCO ไธŠ่ฎญ็ปƒ YOLOv5m 300 ไธชๅ‘จๆœŸ
python train.py --data coco.yaml --epochs 300 --weights '' --cfg yolov5m.yaml --batch-size 40

# ๅœจ COCO ไธŠ่ฎญ็ปƒ YOLOv5l 300 ไธชๅ‘จๆœŸ
python train.py --data coco.yaml --epochs 300 --weights '' --cfg yolov5l.yaml --batch-size 24

# ๅœจ COCO ไธŠ่ฎญ็ปƒ YOLOv5x 300 ไธชๅ‘จๆœŸ
python train.py --data coco.yaml --epochs 300 --weights '' --cfg yolov5x.yaml --batch-size 16

ๆ•™็จ‹

๐Ÿงฉ ้›†ๆˆ

ๆˆ‘ไปฌไธŽ้ข†ๅ…ˆ AI ๅนณๅฐ็š„ๅ…ณ้”ฎ้›†ๆˆๆ‰ฉๅฑ•ไบ† Ultralytics ไบงๅ“็š„ๅŠŸ่ƒฝ๏ผŒๅขžๅผบไบ†่ฏธๅฆ‚ๆ•ฐๆฎ้›†ๆ ‡ๆณจใ€่ฎญ็ปƒใ€ๅฏ่ง†ๅŒ–ๅ’Œๆจกๅž‹็ฎก็†็ญ‰ไปปๅŠกใ€‚ไบ†่งฃ Ultralytics ๅฆ‚ไฝ•ไธŽ Weights & Biasesใ€Comet MLใ€Roboflow ๅ’Œ Intel OpenVINO ็ญ‰ๅˆไฝœไผ™ไผดๅไฝœ๏ผŒไผ˜ๅŒ–ๆ‚จ็š„ AI ๅทฅไฝœๆต็จ‹ใ€‚ๅœจ Ultralytics ้›†ๆˆ ๆŽข็ดขๆ›ดๅคšไฟกๆฏใ€‚

๐Ÿค” ไธบไฝ•้€‰ๆ‹ฉ YOLOv5๏ผŸ

YOLOv5 ็š„่ฎพ่ฎกๆ—จๅœจ็ฎ€ๅ•ๆ˜“็”จใ€‚ๆˆ‘ไปฌไผ˜ๅ…ˆ่€ƒ่™‘ๅฎž้™…ๆ€ง่ƒฝๅ’Œๅฏ่ฎฟ้—ฎๆ€งใ€‚

YOLOv5-P5 640 ๅ›พ่กจ

ๅ›พ่กจ่ฏดๆ˜Ž

  • COCO AP val ่กจ็คบๅœจ ไบคๅนถๆฏ” (IoU) ้˜ˆๅ€ผไปŽ 0.5 ๅˆฐ 0.95 ่Œƒๅ›ดๅ†…็š„ๅนณๅ‡็ฒพๅบฆๅ‡ๅ€ผ (mAP)๏ผŒๅœจๅŒ…ๅซ 5000 ๅผ ๅ›พๅƒ็š„ COCO val2017 ๆ•ฐๆฎ้›†ไธŠ๏ผŒไฝฟ็”จๅ„็งๆŽจ็†ๅฐบๅฏธ๏ผˆ256 ๅˆฐ 1536 ๅƒ็ด ๏ผ‰ๆต‹้‡ๅพ—ๅ‡บใ€‚
  • GPU Speed ไฝฟ็”จๆ‰นๅค„็†ๅคงๅฐไธบ 32 ็š„ AWS p3.2xlarge V100 ๅฎžไพ‹๏ผŒๆต‹้‡ๅœจ COCO val2017 ๆ•ฐๆฎ้›†ไธŠๆฏๅผ ๅ›พๅƒ็š„ๅนณๅ‡ๆŽจ็†ๆ—ถ้—ดใ€‚
  • EfficientDet ๆ•ฐๆฎๆฅๆบไบŽ google/automl ไป“ๅบ“๏ผŒๆ‰นๅค„็†ๅคงๅฐไธบ 8ใ€‚
  • ๅค็Žฐ่ฟ™ไบ›็ป“ๆžœ่ฏทไฝฟ็”จๅ‘ฝไปค๏ผšpython val.py --task study --data coco.yaml --iou 0.7 --weights yolov5n6.pt yolov5s6.pt yolov5m6.pt yolov5l6.pt yolov5x6.pt

้ข„่ฎญ็ปƒๆƒ้‡

ๆญค่กจๆ˜พ็คบไบ†ๅœจ COCO ๆ•ฐๆฎ้›†ไธŠ่ฎญ็ปƒ็š„ๅ„็ง YOLOv5 ๆจกๅž‹็š„ๆ€ง่ƒฝๆŒ‡ๆ ‡ใ€‚

ๆจกๅž‹ ๅฐบๅฏธ(ๅƒ็ด ) mAPval50-95 mAPval50 ้€ŸๅบฆCPU b1(ๆฏซ็ง’) ้€ŸๅบฆV100 b1(ๆฏซ็ง’) ้€ŸๅบฆV100 b32(ๆฏซ็ง’) ๅ‚ๆ•ฐ(M) FLOPs@640 (B)
YOLOv5n 640 28.0 45.7 45 6.3 0.6 1.9 4.5
YOLOv5s 640 37.4 56.8 98 6.4 0.9 7.2 16.5
YOLOv5m 640 45.4 64.1 224 8.2 1.7 21.2 49.0
YOLOv5l 640 49.0 67.3 430 10.1 2.7 46.5 109.1
YOLOv5x 640 50.7 68.9 766 12.1 4.8 86.7 205.7
YOLOv5n6 1280 36.0 54.4 153 8.1 2.1 3.2 4.6
YOLOv5s6 1280 44.8 63.7 385 8.2 3.6 12.6 16.8
YOLOv5m6 1280 51.3 69.3 887 11.1 6.8 35.7 50.0
YOLOv5l6 1280 53.7 71.3 1784 15.8 10.5 76.8 111.4
YOLOv5x6+ [TTA] 12801536 55.055.8 72.772.7 3136- 26.2- 19.4- 140.7- 209.8-

่กจๆ ผ่ฏดๆ˜Ž

  • 640 ๅƒ็ด ่กŒๅฑ•็คบ็š„ๆ˜ฏๆ—ง็‰ˆๅŸบไบŽ้”šๆก†็š„ YOLOv5 ๆƒ้‡ๅŠๅ…ถๆŒ‡ๆ ‡๏ผŒไฝ†้“พๆŽฅไผšๆ‰“ๅผ€ Ultralytics Platform ไธŠๅฏนๅบ”็š„ๆ— ้”š YOLOv5u ๅŽ็ปงๆจกๅž‹ใ€‚P6 ้“พๆŽฅไป็›ดๆŽฅไธ‹่ฝฝๆ—ง็‰ˆ 1280 ๅƒ็ด ๆƒ้‡ใ€‚
  • ๆ‰€ๆœ‰้ข„่ฎญ็ปƒๆƒ้‡ๅ‡ไฝฟ็”จ้ป˜่ฎค่ฎพ็ฝฎ่ฎญ็ปƒไบ† 300 ไธชๅ‘จๆœŸใ€‚Nano (n) ๅ’Œ Small (s) ๆจกๅž‹ไฝฟ็”จ hyp.scratch-low.yaml ่ถ…ๅ‚ๆ•ฐ๏ผŒ่€Œ Medium (m)ใ€Large (l) ๅ’Œ Extra-Large (x) ๆจกๅž‹ไฝฟ็”จ hyp.scratch-high.yamlใ€‚
  • mAPval ๅ€ผ่กจ็คบๅœจ COCO val2017 ๆ•ฐๆฎ้›†ไธŠ็š„ๅ•ๆจกๅž‹ใ€ๅ•ๅฐบๅบฆๆ€ง่ƒฝใ€‚ๅค็Žฐ่ฏทไฝฟ็”จ๏ผšpython val.py --data coco.yaml --img 640 --conf 0.001 --iou 0.65
  • ้€ŸๅบฆๆŒ‡ๆ ‡ๆ˜ฏๅœจ AWS p3.2xlarge V100 ๅฎžไพ‹ไธŠๅฏน COCO val ๅ›พๅƒ่ฟ›่กŒๅนณๅ‡ๆต‹้‡็š„ใ€‚ไธๅŒ…ๆ‹ฌ้žๆžๅคงๅ€ผๆŠ‘ๅˆถ (NMS) ๆ—ถ้—ด๏ผˆ็บฆ 1 ๆฏซ็ง’/ๅ›พๅƒ๏ผ‰ใ€‚ๅค็Žฐ่ฏทไฝฟ็”จ๏ผšpython val.py --data coco.yaml --img 640 --task speed --batch 1
  • TTA (ๆต‹่ฏ•ๆ—ถๅขžๅผบ) ๅŒ…ๆ‹ฌๅๅฐ„ๅ’Œๅฐบๅบฆๅขžๅผบไปฅๆ้ซ˜ๅ‡†็กฎๆ€งใ€‚ๅค็Žฐ่ฏทไฝฟ็”จ๏ผšpython val.py --data coco.yaml --img 1536 --iou 0.7 --augment

๐Ÿ–ผ๏ธ ๅˆ†ๅ‰ฒ

YOLOv5 v7.0 ็‰ˆๆœฌ ๅผ•ๅ…ฅไบ†ๅฎžไพ‹ๅˆ†ๅ‰ฒๆจกๅž‹๏ผŒ่ฎพ่ฎก็”จไบŽ่ฝปๆพ่ฎญ็ปƒใ€้ชŒ่ฏๅ’Œ้ƒจ็ฝฒใ€‚ๆœ‰ๅ…ณๅฎŒๆ•ด่ฏฆ็ป†ไฟกๆฏ๏ผŒ่ฏทๅ‚้˜…ๅ‘ๅธƒ่ฏดๆ˜Ž๏ผŒๅนถๆŽข็ดข YOLOv5 ๅˆ†ๅ‰ฒ Colab ็ฌ”่ฎฐๆœฌไปฅ่Žทๅ–ๅฟซ้€Ÿๅ…ฅ้—จ็คบไพ‹ใ€‚

ๅˆ†ๅ‰ฒ้ข„่ฎญ็ปƒๆƒ้‡

YOLOv5 ๅˆ†ๅ‰ฒๆจกๅž‹ๅœจ COCO ๆ•ฐๆฎ้›†ไธŠไฝฟ็”จ A100 GPU ไปฅ 640 ๅƒ็ด ็š„ๅ›พๅƒๅคงๅฐ่ฎญ็ปƒไบ† 300 ไธชๅ‘จๆœŸใ€‚ๆจกๅž‹ๅฏผๅ‡บไธบ ONNX FP32 ็”จไบŽ CPU ้€Ÿๅบฆๆต‹่ฏ•๏ผŒๅฏผๅ‡บไธบ TensorRT FP16 ็”จไบŽ GPU ้€Ÿๅบฆๆต‹่ฏ•ใ€‚ๆ‰€ๆœ‰้€Ÿๅบฆๆต‹่ฏ•ๅ‡ๅœจ Google Colab Pro ็ฌ”่ฎฐๆœฌไธŠ่ฟ›่กŒ๏ผŒไปฅ็กฎไฟๅฏๅค็Žฐๆ€งใ€‚

ๆจกๅž‹ ๅฐบๅฏธ(ๅƒ็ด ) mAPbox50-95 mAPmask50-95 ่ฎญ็ปƒๆ—ถ้—ด300 ๅ‘จๆœŸA100 (ๅฐๆ—ถ) ้€ŸๅบฆONNX CPU(ๆฏซ็ง’) ้€ŸๅบฆTRT A100(ๆฏซ็ง’) ๅ‚ๆ•ฐ(M) FLOPs@640 (B)
YOLOv5n-seg 640 27.6 23.4 80:17 62.7 1.2 2.0 7.1
YOLOv5s-seg 640 37.6 31.7 88:16 173.3 1.4 7.6 26.4
YOLOv5m-seg 640 45.0 37.1 108:36 427.0 2.2 22.0 70.8
YOLOv5l-seg 640 49.0 39.9 66:43 (2x) 857.4 2.9 47.9 147.7
YOLOv5x-seg 640 50.7 41.4 62:56 (3x) 1579.2 4.5 88.8 265.7
  • ๆ‰€ๆœ‰้ข„่ฎญ็ปƒๆƒ้‡ๅ‡ไฝฟ็”จ SGD ไผ˜ๅŒ–ๅ™จ๏ผŒlr0=0.01 ๅ’Œ weight_decay=5e-5๏ผŒๅœจ 640 ๅƒ็ด ็š„ๅ›พๅƒๅคงๅฐไธ‹๏ผŒไฝฟ็”จ้ป˜่ฎค่ฎพ็ฝฎ่ฎญ็ปƒไบ† 300 ไธชๅ‘จๆœŸใ€‚่ฎญ็ปƒ่ฟ่กŒ่ฎฐๅฝ•ๅœจ https://wandb.ai/glenn-jocher/YOLOv5_v70_officialใ€‚

  • ๅ‡†็กฎๅบฆๅ€ผ่กจ็คบๅœจ COCO ๆ•ฐๆฎ้›†ไธŠ็š„ๅ•ๆจกๅž‹ใ€ๅ•ๅฐบๅบฆๆ€ง่ƒฝใ€‚ๅค็Žฐ่ฏทไฝฟ็”จ๏ผšpython segment/val.py --data coco.yaml --weights yolov5s-seg.pt

  • ้€ŸๅบฆๆŒ‡ๆ ‡ๆ˜ฏๅœจ Colab Pro A100 High-RAM ๅฎžไพ‹ไธŠๅฏน 100 ๅผ ๆŽจ็†ๅ›พๅƒ่ฟ›่กŒๅนณๅ‡ๆต‹้‡็š„ใ€‚ๅ€ผไป…่กจ็คบๆŽจ็†้€Ÿๅบฆ๏ผˆNMS ็บฆๅขžๅŠ  1 ๆฏซ็ง’/ๅ›พๅƒ๏ผ‰ใ€‚ๅค็Žฐ่ฏทไฝฟ็”จ๏ผšpython segment/val.py --data coco.yaml --weights yolov5s-seg.pt --batch 1

  • ๅฏผๅ‡บๅˆฐ ONNX (FP32) ๅ’Œ TensorRT (FP16) ๆ˜ฏไฝฟ็”จ export.py ๅฎŒๆˆ็š„ใ€‚ๅค็Žฐ่ฏทไฝฟ็”จ๏ผšpython export.py --weights yolov5s-seg.pt --include engine --device 0 --half

    ๅˆ†ๅ‰ฒไฝฟ็”จ็คบไพ‹  

่ฎญ็ปƒ

YOLOv5 ๅˆ†ๅ‰ฒ่ฎญ็ปƒๆ”ฏๆŒ้€š่ฟ‡ --data coco128-seg.yaml ๅ‚ๆ•ฐ่‡ชๅŠจไธ‹่ฝฝ COCO128-seg ๆ•ฐๆฎ้›†ใ€‚ๅฏนไบŽๅฎŒๆ•ด็š„ COCO-segments ๆ•ฐๆฎ้›†๏ผŒ่ฏทไฝฟ็”จ bash data/scripts/get_coco.sh --train --val --segments ๆ‰‹ๅŠจไธ‹่ฝฝ๏ผŒ็„ถๅŽไฝฟ็”จ python segment/train.py --data coco.yaml ่ฟ›่กŒ่ฎญ็ปƒใ€‚

bash
# ๅœจๅ•ไธช GPU ไธŠ่ฎญ็ปƒ
python segment/train.py --data coco128-seg.yaml --weights yolov5s-seg.pt --img 640

# ไฝฟ็”จๅคš GPU ๅˆ†ๅธƒๅผๆ•ฐๆฎๅนถ่กŒ (DDP) ่ฟ›่กŒ่ฎญ็ปƒ
python -m torch.distributed.run --nproc_per_node 4 --master_port 1 segment/train.py --data coco128-seg.yaml --weights yolov5s-seg.pt --img 640 --device 0,1,2,3

้ชŒ่ฏ

ๅœจ COCO ๆ•ฐๆฎ้›†ไธŠ้ชŒ่ฏ YOLOv5s-seg ็š„ๆŽฉ็ ๅนณๅ‡็ฒพๅบฆๅ‡ๅ€ผ (mAP)๏ผš

bash
# ไธ‹่ฝฝ COCO ้ชŒ่ฏๅˆ†ๅ‰ฒ้›† (780MB, 5000 ๅผ ๅ›พๅƒ)
bash data/scripts/get_coco.sh --val --segments

# ้ชŒ่ฏๆจกๅž‹
python segment/val.py --weights yolov5s-seg.pt --data coco.yaml --img 640

้ข„ๆต‹

ไฝฟ็”จ้ข„่ฎญ็ปƒ็š„ YOLOv5m-seg.pt ๆจกๅž‹ๅฏน bus.jpg ๆ‰ง่กŒๅˆ†ๅ‰ฒ๏ผš

bash
# ่ฟ่กŒ้ข„ๆต‹
python segment/predict.py --weights yolov5m-seg.pt --source data/images/bus.jpg
python
# ไปŽ PyTorch Hub ๅŠ ่ฝฝๆจกๅž‹ (ๆณจๆ„: ๆŽจ็†ๆ”ฏๆŒๅฏ่ƒฝๆœ‰ๆ‰€ไธๅŒ)
model = torch.hub.load("ultralytics/yolov5", "custom", "yolov5m-seg.pt")

ๅฏผๅ‡บ

ๅฐ† YOLOv5s-seg ๆจกๅž‹ๅฏผๅ‡บไธบ ONNX ๅ’Œ TensorRT ๆ ผๅผ๏ผš

bash
# ๅฏผๅ‡บๆจกๅž‹
python export.py --weights yolov5s-seg.pt --include onnx engine --img 640 --device 0

๐Ÿท๏ธ ๅˆ†็ฑป

YOLOv5 v6.2 ็‰ˆๆœฌ ๅผ•ๅ…ฅไบ†ๅฏนๅ›พๅƒๅˆ†็ฑปๆจกๅž‹่ฎญ็ปƒใ€้ชŒ่ฏๅ’Œ้ƒจ็ฝฒ็š„ๆ”ฏๆŒใ€‚่ฏทๆŸฅ็œ‹ๅ‘ๅธƒ่ฏดๆ˜Žไบ†่งฃ่ฏฆ็ป†ไฟกๆฏ๏ผŒๅนถๅ‚้˜… YOLOv5 ๅˆ†็ฑป Colab ็ฌ”่ฎฐๆœฌ่Žทๅ–ๅฟซ้€Ÿๅ…ฅ้—จๆŒ‡ๅ—ใ€‚

ๅˆ†็ฑป้ข„่ฎญ็ปƒๆƒ้‡

YOLOv5-cls ๅˆ†็ฑปๆจกๅž‹ๅœจ ImageNet ไธŠไฝฟ็”จ 4xA100 ๅฎžไพ‹่ฎญ็ปƒไบ† 90 ไธชๅ‘จๆœŸใ€‚ResNet ๅ’Œ EfficientNet ๆจกๅž‹ๅœจ็›ธๅŒ่ฎพ็ฝฎไธ‹ไธ€่ตท่ฎญ็ปƒไปฅ่ฟ›่กŒๆฏ”่พƒใ€‚ๆจกๅž‹ๅฏผๅ‡บไธบ ONNX FP32๏ผˆ็”จไบŽ CPU ้€Ÿๅบฆๆต‹่ฏ•๏ผ‰ๅ’Œ TensorRT FP16๏ผˆ็”จไบŽ GPU ้€Ÿๅบฆๆต‹่ฏ•๏ผ‰ใ€‚ๆ‰€ๆœ‰้€Ÿๅบฆๆต‹่ฏ•ๅ‡ๅœจ Google Colab Pro ไธŠ่ฟ่กŒ๏ผŒไปฅ็กฎไฟๅฏๅค็Žฐๆ€งใ€‚

ๆจกๅž‹ ๅฐบๅฏธ(ๅƒ็ด ) ๅ‡†็กฎ็އtop1 ๅ‡†็กฎ็އtop5 ่ฎญ็ปƒ90 ๅ‘จๆœŸ4xA100 (ๅฐๆ—ถ) ้€ŸๅบฆONNX CPU(ๆฏซ็ง’) ้€ŸๅบฆTensorRT V100(ๆฏซ็ง’) ๅ‚ๆ•ฐ(M) FLOPs@224 (B)
YOLOv5n-cls 224 64.6 85.4 7:59 3.3 0.5 2.5 0.5
YOLOv5s-cls 224 71.5 90.2 8:09 6.6 0.6 5.4 1.4
YOLOv5m-cls 224 75.9 92.9 10:06 15.5 0.9 12.9 3.9
YOLOv5l-cls 224 78.0 94.0 11:56 26.9 1.4 26.5 8.5
YOLOv5x-cls 224 79.0 94.4 15:04 54.3 1.8 48.1 15.9
ResNet18 224 70.3 89.5 6:47 11.2 0.5 11.7 3.7
ResNet34 224 73.9 91.8 8:33 20.6 0.9 21.8 7.4
ResNet50 224 76.8 93.4 11:10 23.4 1.0 25.6 8.5
ResNet101 224 78.5 94.3 17:10 42.1 1.9 44.5 15.9
EfficientNet_b0 224 75.1 92.4 13:03 12.5 1.3 5.3 1.0
EfficientNet_b1 224 76.4 93.2 17:04 14.9 1.6 7.8 1.5
EfficientNet_b2 224 76.6 93.4 17:10 15.9 1.6 9.1 1.7
EfficientNet_b3 224 77.7 94.0 19:19 18.9 1.9 12.2 2.4

่กจๆ ผ่ฏดๆ˜Ž๏ผˆ็‚นๅ‡ปๅฑ•ๅผ€๏ผ‰

  • ๆ‰€ๆœ‰้ข„่ฎญ็ปƒๆƒ้‡ๅ‡ไฝฟ็”จ SGD ไผ˜ๅŒ–ๅ™จ๏ผŒlr0=0.001 ๅ’Œ weight_decay=5e-5๏ผŒๅœจ 224 ๅƒ็ด ็š„ๅ›พๅƒๅคงๅฐไธ‹๏ผŒไฝฟ็”จ้ป˜่ฎค่ฎพ็ฝฎ่ฎญ็ปƒไบ† 90 ไธชๅ‘จๆœŸใ€‚่ฎญ็ปƒ่ฟ่กŒ่ฎฐๅฝ•ๅœจ https://wandb.ai/glenn-jocher/YOLOv5-Classifier-v6-2ใ€‚

  • ๅ‡†็กฎๅบฆๅ€ผ๏ผˆtop-1 ๅ’Œ top-5๏ผ‰่กจ็คบๅœจ ImageNet-1k ๆ•ฐๆฎ้›†ไธŠ็š„ๅ•ๆจกๅž‹ใ€ๅ•ๅฐบๅบฆๆ€ง่ƒฝใ€‚ๅค็Žฐ่ฏทไฝฟ็”จ๏ผšpython classify/val.py --data ../datasets/imagenet --img 224

  • ้€ŸๅบฆๆŒ‡ๆ ‡ๆ˜ฏๅœจ Google Colab Pro V100 High-RAM ๅฎžไพ‹ไธŠๅฏน 100 ๅผ ๆŽจ็†ๅ›พๅƒ่ฟ›่กŒๅนณๅ‡ๆต‹้‡็š„ใ€‚ๅค็Žฐ่ฏทไฝฟ็”จ๏ผšpython classify/val.py --data ../datasets/imagenet --img 224 --batch 1

  • ๅฏผๅ‡บๅˆฐ ONNX (FP32) ๅ’Œ TensorRT (FP16) ๆ˜ฏไฝฟ็”จ export.py ๅฎŒๆˆ็š„ใ€‚ๅค็Žฐ่ฏทไฝฟ็”จ๏ผšpython export.py --weights yolov5s-cls.pt --include engine onnx --imgsz 224

    ๅˆ†็ฑปไฝฟ็”จ็คบไพ‹  

่ฎญ็ปƒ

YOLOv5 ๅˆ†็ฑป่ฎญ็ปƒๆ”ฏๆŒไฝฟ็”จ --data ๅ‚ๆ•ฐ่‡ชๅŠจไธ‹่ฝฝ่ฏธๅฆ‚ MNISTใ€Fashion-MNISTใ€CIFAR10ใ€CIFAR100ใ€Imagenetteใ€Imagewoof ๅ’Œ ImageNet ็ญ‰ๆ•ฐๆฎ้›†ใ€‚ไพ‹ๅฆ‚๏ผŒไฝฟ็”จ --data mnist ๅผ€ๅง‹ๅœจ MNIST ไธŠ่ฎญ็ปƒใ€‚

bash
# ไฝฟ็”จ CIFAR-100 ๆ•ฐๆฎ้›†ๅœจๅ•ไธช GPU ไธŠ่ฎญ็ปƒ
python classify/train.py --model yolov5s-cls.pt --data cifar100 --epochs 5 --img 224 --batch 128

# ๅœจ ImageNet ๆ•ฐๆฎ้›†ไธŠไฝฟ็”จๅคš GPU DDP ่ฟ›่กŒ่ฎญ็ปƒ
python -m torch.distributed.run --nproc_per_node 4 --master_port 1 classify/train.py --model yolov5s-cls.pt --data imagenet --epochs 5 --img 224 --device 0,1,2,3

้ชŒ่ฏ

ๅœจ ImageNet-1k ้ชŒ่ฏๆ•ฐๆฎ้›†ไธŠ้ชŒ่ฏ YOLOv5m-cls ๆจกๅž‹็š„ๅ‡†็กฎๆ€ง๏ผš

bash
# ไธ‹่ฝฝ ImageNet ้ชŒ่ฏ้›† (6.3GB, 50,000 ๅผ ๅ›พๅƒ)
bash data/scripts/get_imagenet.sh --val

# ้ชŒ่ฏๆจกๅž‹
python classify/val.py --weights yolov5m-cls.pt --data ../datasets/imagenet --img 224

้ข„ๆต‹

ไฝฟ็”จ้ข„่ฎญ็ปƒ็š„ YOLOv5s-cls.pt ๆจกๅž‹ๅฏนๅ›พๅƒ bus.jpg ่ฟ›่กŒๅˆ†็ฑป๏ผš

bash
# ่ฟ่กŒ้ข„ๆต‹
python classify/predict.py --weights yolov5s-cls.pt --source data/images/bus.jpg
python
# ไปŽ PyTorch Hub ๅŠ ่ฝฝๆจกๅž‹
model = torch.hub.load("ultralytics/yolov5", "custom", "yolov5s-cls.pt")

ๅฏผๅ‡บ

ๅฐ†่ฎญ็ปƒๅฅฝ็š„ YOLOv5s-clsใ€ResNet50 ๅ’Œ EfficientNet_b0 ๆจกๅž‹ๅฏผๅ‡บไธบ ONNX ๅ’Œ TensorRT ๆ ผๅผ๏ผš

bash
# ๅฏผๅ‡บๆจกๅž‹
python export.py --weights yolov5s-cls.pt resnet50.pt efficientnet_b0.pt --include onnx engine --img 224

โ˜๏ธ ็Žฏๅขƒ

ไฝฟ็”จๆˆ‘ไปฌ้ข„้…็ฝฎ็š„็Žฏๅขƒๅฟซ้€Ÿๅผ€ๅง‹ใ€‚็‚นๅ‡ปไธ‹้ข็š„ๅ›พๆ ‡ๆŸฅ็œ‹่ฎพ็ฝฎ่ฏฆๆƒ…ใ€‚

๐Ÿค ่ดก็Œฎ

ๆˆ‘ไปฌๆฌข่ฟŽๆ‚จ็š„่ดก็Œฎ๏ผ่ฎฉ YOLOv5 ๅ˜ๅพ—ๆ˜“ไบŽ่ฎฟ้—ฎๅ’Œๆœ‰ๆ•ˆๆ˜ฏ็คพๅŒบ็š„ๅ…ฑๅŒๅŠชๅŠ›ใ€‚่ฏทๅ‚้˜…ๆˆ‘ไปฌ็š„่ดก็ŒฎๆŒ‡ๅ—ๅผ€ๅง‹ใ€‚้€š่ฟ‡ YOLOv5 ่ฐƒๆŸฅๅˆ†ไบซๆ‚จ็š„ๅ้ฆˆใ€‚ๆ„Ÿ่ฐขๆ‰€ๆœ‰ไธบไฝฟ YOLOv5 ๅ˜ๅพ—ๆ›ดๅฅฝ่€Œๅšๅ‡บ่ดก็Œฎ็š„ไบบ๏ผ

๐Ÿ“œ ่ฎธๅฏ่ฏ

Ultralytics ๆไพ›ไธค็ง่ฎธๅฏ้€‰้กนไปฅๆปก่ถณไธๅŒ้œ€ๆฑ‚๏ผš

  • AGPL-3.0 ่ฎธๅฏ่ฏ๏ผšไธ€็ง OSI ๆ‰นๅ‡†็š„ๅผ€ๆบ่ฎธๅฏ่ฏ๏ผŒ้žๅธธ้€‚ๅˆๅญฆๆœฏ็ ”็ฉถใ€ไธชไบบ้กน็›ฎๅ’Œๆต‹่ฏ•ใ€‚ๅฎƒไฟƒ่ฟ›ๅผ€ๆ”พๅไฝœๅ’Œ็Ÿฅ่ฏ†ๅ…ฑไบซใ€‚่ฏฆๆƒ…่ฏทๅ‚้˜… LICENSE ๆ–‡ไปถใ€‚
  • ไผไธš่ฎธๅฏ่ฏ๏ผšไธ“ไธบๅ•†ไธšๅบ”็”จ้‡่บซๅฎšๅˆถ๏ผŒๆญค่ฎธๅฏ่ฏๅ…่ฎธๅฐ† Ultralytics ่ฝฏไปถๅ’Œ AI ๆจกๅž‹ๆ— ็ผ้›†ๆˆๅˆฐๅ•†ไธšไบงๅ“ๅ’ŒๆœๅŠกไธญ๏ผŒ็ป•่ฟ‡ AGPL-3.0 ็š„ๅผ€ๆบ่ฆๆฑ‚ใ€‚ๅฏนไบŽๅ•†ไธš็”จไพ‹๏ผŒ่ฏท้€š่ฟ‡ Ultralytics ๆŽˆๆƒ่ฎธๅฏ่”็ณปๆˆ‘ไปฌใ€‚

๐Ÿ“ง ่”็ณป

ๅฏนไบŽไธŽ YOLOv5 ็›ธๅ…ณ็š„้”™่ฏฏๆŠฅๅ‘Šๅ’ŒๅŠŸ่ƒฝ่ฏทๆฑ‚๏ผŒ่ฏท่ฎฟ้—ฎ GitHub Issuesใ€‚ๅฏนไบŽไธ€่ˆฌ้—ฎ้ข˜ใ€่ฎจ่ฎบๅ’Œ็คพๅŒบๆ”ฏๆŒ๏ผŒ่ฏทๅŠ ๅ…ฅๆˆ‘ไปฌ็š„ Discord ๆœๅŠกๅ™จ๏ผ

2. Official Technical Reference & Guides (ultralytics/docs)

๐Ÿ“š Ultralytics Docs

Welcome to Ultralytics Docs, your comprehensive resource for understanding and utilizing our state-of-the-art machine learning tools and models, including Ultralytics YOLO. These documents are actively maintained and deployed to https://docs.ultralytics.com for easy access.




๐Ÿ› ๏ธ Ultralytics Package



The badges above track the core ultralytics Python package documented by this site. To install that package in developer mode, which allows you to modify the source code directly, ensure you have Git and Python 3.8 or later installed on your system. Then, follow these steps:

  1. Clone the ultralytics repository to your local machine using Git:

    bash
    git clone https://github.com/ultralytics/ultralytics.git
  2. Navigate to the cloned repository's root directory:

    bash
    cd ultralytics
  3. Install the package in editable mode (-e) along with its development dependencies ([dev]) using pip:

    bash
    pip install -e '.[dev]'

    This command installs the ultralytics package such that changes to the source code are immediately reflected in your environment, ideal for development and contributing.

๐Ÿงฐ Technology Stack

๐Ÿ”ง Repository Tooling

This repository contains documentation source plus maintenance workflows for published-site checks. Install the lightweight Python dependencies before running repository utilities locally:

bash
uv pip install -r requirements.txt

For example, utils/check_image_sizes.py is used by the website link-check workflow to flag oversized images in downloaded pages.

๐ŸŒ Website Checks

The live documentation at docs.ultralytics.com is maintained with scheduled and manual workflows in .github/workflows/:

  • links.yml downloads rendered pages for www.ultralytics.com, docs.ultralytics.com, academy.ultralytics.com, and handbook.ultralytics.com, then checks links, spelling, and large images.
  • links_local.yml checks repository Markdown and HTML links, with an optional broader link scan on manual runs.
  • download_websites.yml can download public website pages for inspection.

Production combines this repository's content with the other documentation sources, validates the complete tree with zensical build --strict, and renders it through Ultralytics' centralized publishing service. This repository therefore has no standalone site build; use the workflows above to check published pages.

๐Ÿ’ก Contribute

We deeply value contributions from the open-source community to enhance Ultralytics projects. Your input helps drive innovation in computer vision and AI! Please review our Contributing Guide for detailed information on how to get involved. You can also share your feedback and ideas through our quick Survey. A heartfelt thank you ๐Ÿ™ to all our contributors for their dedication and support!

We look forward to your contributions!

๐Ÿ“œ License

Ultralytics Docs are available under two licensing options to accommodate different usage scenarios:

  • AGPL-3.0 License: Ideal for students, researchers, and enthusiasts involved in academic pursuits and open collaboration. See the LICENSE file for full details. This license promotes sharing improvements back with the community, fostering an open and collaborative environment.
  • Enterprise License: Designed for commercial applications, this license allows seamless integration of Ultralytics software and AI models into commercial products and services without the open-source requirements of AGPL-3.0. Visit Ultralytics Licensing for more information on obtaining an Enterprise License.

โœ‰๏ธ Contact

For bug reports, feature requests, and other issues related to the documentation, please use GitHub Issues. For discussions, questions, and community support regarding Ultralytics software, the Ultralytics Platform, and more, join the conversation with peers and the Ultralytics team on our Discord server!