yolov5

ultralyticsAGPL-3.0活跃维护

基于 PyTorch 的目标检测全家桶,覆盖训练、推理、实例分割、图像分类和模型导出,开箱即用,适合快速落地视觉任务。

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

v7.0发布于 2022-11-22 15:29 UTC58,260star +7 / 7 天17,439fork同步于 2026-11-10 23:19 UTC

怎么上手

由 README 提炼,执行前请确认
git clone https://github.com/ultralytics/yolov5
cd yolov5
pip install -r requirements.txt
硬件要求按 README 说明

README 提到训练在单张 NVIDIA V100 GPU 上进行,并给出 V100-16GB 对应的批大小;未说明 CPU 推理或其他 GPU 型号要求。

多卡 / 张量并行
下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

由 README 自动翻译提炼

基于 PyTorch 的 YOLOv5 目标检测、实例分割与分类模型,开箱即用

基于 PyTorch 的目标检测全家桶,覆盖训练、推理、实例分割、图像分类和模型导出,开箱即用,适合快速落地视觉任务。

核心能力

  • 用 PyTorch Hub 一行代码加载 yolov5n/s/m/l/x 模型做推理
  • detect.py 支持图片、视频、摄像头、RTSP 流和 YouTube 链接
  • train.py 可复现 COCO 训练,支持多 GPU 与 AutoBatch 自动批大小
  • 提供目标检测、实例分割、图像分类三类视觉任务
  • 结果可 print/show/save/crop 或转 pandas 处理

容易踩的坑

需要 Python>=3.8.0 且预先安装 PyTorch>=1.8;模型权重会从最新 release 自动下载,首次运行需联网;训练耗时较长,YOLOv5n/s/m/l/x 在单张 V100 上约需 1/2/4/6/8 天。

内容由模型根据 README 生成,可能不完整或不准确,以官方文档为准。看原文 README

最近发版

5 个版本v7.0
  1. v7.0v7.0 - YOLOv5 SOTA Realtime Instance Segmentation最新正式版2022-11-22 · 2022-11-22 15:29 UTC

    Our new YOLOv5 v7.0 instance segmentation models are the fastest and most accurate in the world, beating all current SOTA benchmarks. We've made them super simple to train, validate and deploy. See full details in our Release Notes and visit our YOLOv5 Segmentation Colab Notebook for quickstart tutorials.

    Our primary goal with this release is to introduce super simple YOLOv5 segmentation workflows just like our existing object detection models. The new v7.0 YOLOv5-seg models below are just a start, we will continue to improve these going forward together with our existing detection and classification models. We'd love your feedback and contributions on this effort!

    This release incorporates 280 PRs from 41 contributors since our last release in August 2022.

    Important Updates

    New Segmentation Checkpoints

    We trained YOLOv5 segmentations models on COCO for 300 epochs at image size 640 using A100 GPUs. We exported all models to ONNX FP32 for CPU speed tests and to TensorRT FP16 for GPU speed tests. We ran all speed tests on Google Colab Pro notebooks for easy reproducibility.

    Modelsize(pixels)mAPbox50-95mAPmask50-95Train time300 epochsA100 (hours)SpeedONNX CPU(ms)SpeedTRT A100(ms)params(M)FLOPs@640 (B)
    [YOLOv5n-seg](https://github.com/ultralytics/yolov5/releases/download/v7.0/yolo
  2. v6.2v6.2 - YOLOv5 Classification Models, Apple M1, Reproducibility, ClearML and Deci.ai integrations2022-08-17 · 2022-08-17 10:26 UTC
    查看更新说明

    This release incorporates 401 PRs from 41 contributors since our last release in February 2022. It adds Classification training, validation, prediction and export (to all 11 formats), and also provides ImageNet-pretrained YOLOv5m-cls, ResNet (18, 34, 50, 101) and EfficientNet (b0-b3) models.

    My main goal with this release is to introduce super simple YOLOv5 classification workflows just like our existing object detection models. The new v6.2 YOLOv5-cls models below are just a start, we will continue to improve these going forward together with our existing detection models. We'd love your contributions on this effort!

    Our next release, v6.3 is scheduled for September and will bring official instance segmentation support to YOLOv5, with a major v7.0 release later this year updating architectures across all 3 tasks - classification, detection and segmentation.

    Important Updates

    New Classification Checkpoints

    We trained YOLOv5-cls classification models on ImageNet for 90 epochs using a 4xA100 instance, and we trained ResNet and EfficientNet models alongside with the same default training settings to compare. We exported all models to ONNX FP32 for CPU speed tests and to TensorRT FP16 for GPU speed tests. We ran all speed tests on Google Colab Pro for easy reproducibility.

    | Model

  3. v6.1v6.1 - TensorRT, TensorFlow Edge TPU and OpenVINO Export and Inference2022-02-22 · 2022-02-22 11:35 UTC
    查看更新说明

    This release incorporates many new features and bug fixes (271 PRs from 48 contributors) since our last release in October 2021. It adds TensorRT, Edge TPU and OpenVINO support, and provides retrained models at --batch-size 128 with new default one-cycle linear LR scheduler. YOLOv5 now officially supports 11 different formats, not just for export but for inference (both detect.py and PyTorch Hub), and validation to profile mAP and speed results after export.

    Formatexport.py --includeModel
    PyTorch-yolov5s.pt
    TorchScripttorchscriptyolov5s.torchscript
    ONNXonnxyolov5s.onnx
    OpenVINOopenvinoyolov5s_openvino_model/
    TensorRTengineyolov5s.engine
    CoreMLcoremlyolov5s.mlmodel
    TensorFlow SavedModelsaved_modelyolov5s_saved_model/
    TensorFlow GraphDefpbyolov5s.pb
    TensorFlow Litetfliteyolov5s.tflite
    TensorFlow Edge TPUedgetpuyolov5s_edgetpu.tflite
    TensorFlow.jstfjsyolov5s_web_model/

    Usage examples (ONNX shown):

    Export:          python export.py --weights yolov5s.pt --include onnx
    Detect:          python detect.py --weights yolov5s.onnx
    PyTorch Hub:     model = torch.hub.load('ultralytics/yolov5', 'custom', 'yolov5s.onnx')
    Validate:        python val.py --weights yolov5s.onnx
    Visualize:       https://netron.app
    

    Important Updates

  4. v6.0v6.0 - YOLOv5n 'Nano' models, Roboflow integration, TensorFlow export, OpenCV DNN support2021-10-12 · 2021-10-12 07:08 UTC
    查看更新说明

    This release incorporates many new features and bug fixes (465 PRs from 73 contributors) since our last release v5.0 in April, brings architecture tweaks, and also introduces new P5 and P6 'Nano' models: YOLOv5n and YOLOv5n6. Nano models maintain the YOLOv5s depth multiple of 0.33 but reduce the YOLOv5s width multiple from 0.50 to 0.25, resulting in ~75% fewer parameters, from 7.5M to 1.9M, ideal for mobile and CPU solutions.

    Example usage:

    python detect.py --weights yolov5n.pt --img 640    # Nano P5 model trained at --img 640 (28.4 [email protected]:0.95)
    python detect.py --weights yolov5n6.pt --img 1280  # Nano P6 model trained at --img 1280 (34.0 mAP0.5:0.95)
    

    Important Updates

    New Results

    • COCO AP val denotes [email protected]:0.95 metric measured on the 5000-image COCO val2017 dataset over various inference sizes from 256 to 1536.
    • GPU Speed measures average inference time per image on COCO val2017 dataset using a AWS p3.2xlarge V100 instance at batch-size 32.
    • EfficientDet data from google/automl at batch size 8.
    • Reproduce by python val.py --task study --data coco.yaml --iou 0.7 --weights yolov5n6.pt yolov5s6.pt yolov5m6.pt yolov5l6.pt yolov5x6.pt

    mAP improves from +0.3% to +1.1% across all models, and ~5% FLOPs reduction produces slight speed improvements and a reduced CUDA memory footprint. Example YOLOv5l before and after metrics:

    |YOLOv5lLarge|size(pixels) |mAPval0.5:0.95 |mAPval0.5 |SpeedCPU b1(ms) |SpeedV100 b1(ms) |Speed<su

  5. v5.0v5.0 - YOLOv5-P6 1280 models, AWS, Supervise.ly and YouTube integrations2021-04-11 · 2021-04-11 17:25 UTC
    查看更新说明

    This release implements YOLOv5-P6 models and retrained YOLOv5-P5 models. All model sizes YOLOv5s/m/l/x are now available in both P5 and P6 architectures:

    • YOLOv5-P5 models (same architecture as v4.0 release): 3 output layers P3, P4, P5 at strides 8, 16, 32, trained at --img 640
    python detect.py --weights yolov5s.pt  # P5 models
                               yolov5m.pt
                               yolov5l.pt
                               yolov5x.pt
    
    • YOLOv5-P6 models: 4 output layers P3, P4, P5, P6 at strides 8, 16, 32, 64 trained at --img 1280
    python detect.py --weights yolov5s6.pt  # P6 models
                               yolov5m6.pt
                               yolov5l6.pt
                               yolov5x6.pt
    

    Example usage:

    # Command Line
    python detect.py --weights yolov5m.pt --img 640  # P5 model at 640
    python detect.py --weights yolov5m6.pt --img 640  # P6 model at 640
    python detect.py --weights yolov5m6.pt --img 1280  # P6 model at 1280
    
    # PyTorch Hub
    model = torch.hub.load('ultralytics/yolov5', 'yolov5m6')  #  P6 model
    results = model(imgs, size=1280)  # inference at 1280
    

    Notable Updates

    Updated Results

    P6 models include an extra P6/64 output layer for detection of larger objects, and benefit the most from training at higher resolution. For this reason we trained all P5 models at 640, and all P6 models at 1280.

    • GPU Speed measures end-to-end time per image averaged over 5000 COCO val2017 images using a V100 GPU with batch size 32, and includes image preprocessing, PyTorch FP16 inference, postprocessing and NMS.
    • EfficientDet data from google/automl at batch size 8.
    • Reproduce by python test.py --task study --data coco.yaml --iou 0.7 --weights yolov5s6.pt yolov5m6.pt yolov5l6.pt yolov5x6.pt

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    中文 | 한국어 | 日本語 | Русский | Deutsch | Français | Español | Português | Türkçe | Tiếng Việt | العربية

    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.

    # 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.

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

    # 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
    

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

    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
    

    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.

    # 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'
    

    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.

    # 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
    

    🧩 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.

    Pretrained Checkpoints

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

    ModelSize(pixels)mAPval50-95mAPval50SpeedCPU b1(ms)SpeedV100 b1(ms)SpeedV100 b32(ms)Params(M)FLOPs@640 (B)
    YOLOv5n64028.045.7456.30.61.94.5
    YOLOv5s64037.456.8986.40.97.216.5
    YOLOv5m64045.464.12248.21.721.249.0
    YOLOv5l64049.067.343010.12.746.5109.1
    YOLOv5x64050.768.976612.14.886.7205.7
    YOLOv5n6128036.054.41538.12.13.24.6
    YOLOv5s6128044.863.73858.23.612.616.8
    YOLOv5m6128051.369.388711.16.835.750.0
    YOLOv5l6128053.771.3178415.810.576.8111.4
    YOLOv5x6+ [TTA]1280153655.055.872.772.73136-26.2-19.4-140.7-209.8-
    • 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.

    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.

    ModelSize(pixels)mAPbox50-95mAPmask50-95Train Time300 epochsA100 (hours)SpeedONNX CPU(ms)SpeedTRT A100(ms)Params(M)FLOPs@640 (B)
    YOLOv5n-seg64027.623.480:1762.71.22.07.1
    YOLOv5s-seg64037.631.788:16173.31.47.626.4
    YOLOv5m-seg64045.037.1108:36427.02.222.070.8
    YOLOv5l-seg64049.039.966:43 (2x)857.42.947.9147.7
    YOLOv5x-seg64050.741.462:56 (3x)1579.24.588.8265.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

    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.

    # 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:

    # 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:

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

    Export

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

    # 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.

    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.

    ModelSize(pixels)Acctop1Acctop5Training90 epochs4xA100 (hours)SpeedONNX CPU(ms)SpeedTensorRT V100(ms)Params(M)FLOPs@224 (B)
    YOLOv5n-cls22464.685.47:593.30.52.50.5
    YOLOv5s-cls22471.590.28:096.60.65.41.4
    YOLOv5m-cls22475.992.910:0615.50.912.93.9
    YOLOv5l-cls22478.094.011:5626.91.426.58.5
    YOLOv5x-cls22479.094.415:0454.31.848.115.9
    ResNet1822470.389.56:4711.20.511.73.7
    ResNet3422473.991.88:3320.60.921.87.4
    ResNet5022476.893.411:1023.41.025.68.5
    ResNet10122478.594.317:1042.11.944.515.9
    EfficientNet_b022475.192.413:0312.51.35.31.0
    EfficientNet_b122476.493.217:0414.91.67.81.5
    EfficientNet_b222476.693.417:1015.91.69.11.7
    EfficientNet_b322477.794.019:1918.91.912.22.4
    • 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

    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.

    # 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:

    # 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:

    # Run prediction
    python classify/predict.py --weights yolov5s-cls.pt --source data/images/bus.jpg
    
    # 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:

    # 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!

    Ultralytics open-source contributors

    📜 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!