Package: signature-lens
English|简体中文YOLOv5 🚀 is the world's most loved vision AI, representingUltralyticsopen-source research into future vision AI methods, incorporating lessons learned and best practices evolved over thousands of hours of research and development.We hope that the resources here will help you get the most out of YOLOv5. Please browse the YOLOv5Docsfor details, raise an issue onGitHubfor support, and join ourDiscordcommunity for questions and discussions!To request an Enterprise License please complete the form atUltralytics Licensing.YOLOv8 🚀 NEWWe are thrilled to announce the launch of Ultralytics YOLOv8 🚀, our NEW cutting-edge, state-of-the-art (SOTA) model
released athttps://github.com/ultralytics/ultralytics.
YOLOv8 is designed to be fast, accurate, and easy to use, making it an excellent choice for a wide range of
object detection, image segmentation and image classification tasks.See theYOLOv8 Docsfor details and get started with:pipinstallultralyticsDocumentationSee theYOLOv5 Docsfor full documentation on training, testing and deployment. See below for quickstart examples.InstallClone repo and installrequirements.txtin aPython>=3.8.0environment, includingPyTorch>=1.8.gitclonehttps://github.com/ultralytics/yolov5# clonecdyolov5
pipinstall-rrequirements.txt# installInferenceYOLOv5PyTorch Hubinference.Modelsdownload automatically from the latest
YOLOv5release.importtorch# Modelmodel=torch.hub.load("ultralytics/yolov5","yolov5s")# or yolov5n - yolov5x6, custom# Imagesimg="https://ultralytics.com/images/zidane.jpg"# or file, Path, PIL, OpenCV, numpy, list# Inferenceresults=model(img)# Resultsresults.print()# or .show(), .save(), .crop(), .pandas(), etc.Inference with detect.pydetect.pyruns inference on a variety of sources, downloadingmodelsautomatically from
the latest YOLOv5releaseand saving results toruns/detect.pythondetect.py--weightsyolov5s.pt--source0# webcamimg.jpg# imagevid.mp4# videoscreen# screenshotpath/# directorylist.txt# list of imageslist.streams# list of streams'path/*.jpg'# glob'https://youtu.be/LNwODJXcvt4'# YouTube'rtsp://example.com/media.mp4'# RTSP, RTMP, HTTP streamTrainingThe commands below reproduce YOLOv5COCOresults.Modelsanddatasetsdownload automatically from the latest
YOLOv5release. Training times for YOLOv5n/s/m/l/x are
1/2/4/6/8 days on a V100 GPU (Multi-GPUtimes faster). Use the
largest--batch-sizepossible, or pass--batch-size -1for
YOLOv5AutoBatch. Batch sizes shown for V100-16GB.pythontrain.py--datacoco.yaml--epochs300--weights''--cfgyolov5n.yaml--batch-size128yolov5s64yolov5m40yolov5l24yolov5x16TutorialsTrain Custom Data🚀 RECOMMENDEDTips for Best Training Results☘️Multi-GPU TrainingPyTorch Hub🌟 NEWTFLite, ONNX, CoreML, TensorRT Export🚀NVIDIA Jetson platform Deployment🌟 NEWTest-Time Augmentation (TTA)Model EnsemblingModel Pruning/SparsityHyperparameter EvolutionTransfer Learning with Frozen LayersArchitecture Summary🌟 NEWRoboflow for Datasets, Labeling, and Active LearningClearML Logging🌟 NEWYOLOv5 with Neural Magic's Deepsparse🌟 NEWComet Logging🌟 NEWIntegrationsRoboflowClearML ⭐ NEWComet ⭐ NEWNeural Magic ⭐ NEWLabel and export your custom datasets directly to YOLOv5 for training withRoboflowAutomatically track, visualize and even remotely train YOLOv5 usingClearML(open-source!)Free forever,Cometlets you save YOLOv5 models, resume training, and interactively visualise and debug predictionsRun YOLOv5 inference up to 6x faster withNeural Magic DeepSparseUltralytics HUBExperience seamless AI withUltralytics HUB⭐, the all-in-one solution for data visualization, YOLOv5 and YOLOv8 🚀 model training and deployment, without any coding. Transform images into actionable insights and bring your AI visions to life with ease using our cutting-edge platform and user-friendlyUltralytics App. Start your journey forFreenow!Why YOLOv5YOLOv5 has been designed to be super easy to get started and simple to learn. We prioritize real-world results.YOLOv5-P5 640 FigureFigure NotesCOCO AP valdenotes mAP@0.5:0.95 metric measured on the 5000-imageCOCO val2017dataset over various inference sizes from 256 to 1536.GPU Speedmeasures average inference time per image onCOCO val2017dataset using aAWS p3.2xlargeV100 instance at batch-size 32.EfficientDetdata fromgoogle/automlat batch size 8.Reproducebypython val.py --task study --data coco.yaml --iou 0.7 --weights yolov5n6.pt yolov5s6.pt yolov5m6.pt yolov5l6.pt yolov5x6.ptPretrained CheckpointsModelsize(pixels)mAPval50-95mAPval50SpeedCPU b1(ms)SpeedV100 b1(ms)SpeedV100 b32(ms)params(M)FLOPs@640 (B)YOLOv5n64028.045.7456.30.61.94.5YOLOv5s64037.456.8986.40.97.216.5YOLOv5m64045.464.12248.21.721.249.0YOLOv5l64049.067.343010.12.746.5109.1YOLOv5x64050.768.976612.14.886.7205.7YOLOv5n6128036.054.41538.12.13.24.6YOLOv5s6128044.863.73858.23.612.616.8YOLOv5m6128051.369.388711.16.835.750.0YOLOv5l6128053.771.3178415.810.576.8111.4YOLOv5x6+TTA1280153655.055.872.772.73136-26.2-19.4-140.7-209.8-Table NotesAll checkpoints are trained to 300 epochs with default settings. Nano and Small models usehyp.scratch-low.yamlhyps, all others usehyp.scratch-high.yaml.mAPvalvalues are for single-model single-scale onCOCO val2017dataset.Reproduce bypython val.py --data coco.yaml --img 640 --conf 0.001 --iou 0.65Speedaveraged over COCO val images using aAWS p3.2xlargeinstance. NMS times (~1 ms/img) not included.Reproduce bypython val.py --data coco.yaml --img 640 --task speed --batch 1TTATest Time Augmentationincludes reflection and scale augmentations.Reproduce bypython val.py --data coco.yaml --img 1536 --iou 0.7 --augmentSegmentationOur new YOLOv5release v7.0instance segmentation models are the fastest and most accurate in the world, beating all currentSOTA benchmarks. We've made them super simple to train, validate and deploy. See full details in ourRelease Notesand visit ourYOLOv5 Segmentation Colab Notebookfor quickstart tutorials.Segmentation CheckpointsWe 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 GoogleColab Pronotebooks for easy 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.1YOLOv5s-seg64037.631.788:16173.31.47.626.4YOLOv5m-seg64045.037.1108:36427.02.222.070.8YOLOv5l-seg64049.039.966:43 (2x)857.42.947.9147.7YOLOv5x-seg64050.741.462:56 (3x)1579.24.588.8265.7All checkpoints are trained to 300 epochs with SGD optimizer withlr0=0.01andweight_decay=5e-5at image size 640 and all default settings.Runs logged tohttps://wandb.ai/glenn-jocher/YOLOv5_v70_officialAccuracyvalues are for single-model single-scale on COCO dataset.Reproduce bypython segment/val.py --data coco.yaml --weights yolov5s-seg.ptSpeedaveraged over 100 inference images using aColab ProA100 High-RAM instance. Values indicate inference speed only (NMS adds about 1ms per image).Reproduce bypython segment/val.py --data coco.yaml --weights yolov5s-seg.pt --batch 1Exportto ONNX at FP32 and TensorRT at FP16 done withexport.py.Reproduce bypython export.py --weights yolov5s-seg.pt --include engine --device 0 --halfSegmentation Usage ExamplesTrainYOLOv5 segmentation training supports auto-download COCO128-seg segmentation dataset with--data coco128-seg.yamlargument and manual download of COCO-segments dataset withbash data/scripts/get_coco.sh --train --val --segmentsand thenpython train.py --data coco.yaml.# Single-GPUpythonsegment/train.py--datacoco128-seg.yaml--weightsyolov5s-seg.pt--img640# Multi-GPU DDPpython-mtorch.distributed.run--nproc_per_node4--master_port1segment/train.py--datacoco128-seg.yaml--weightsyolov5s-seg.pt--img640--device0,1,2,3ValValidate YOLOv5s-seg mask mAP on COCO dataset:bashdata/scripts/get_coco.sh--val--segments# download COCO val segments split (780MB, 5000 images)pythonsegment/val.py--weightsyolov5s-seg.pt--datacoco.yaml--img640# validatePredictUse pretrained YOLOv5m-seg.pt to predict bus.jpg:pythonsegment/predict.py--weightsyolov5m-seg.pt--sourcedata/images/bus.jpgmodel=torch.hub.load("ultralytics/yolov5","custom","yolov5m-seg.pt")# load from PyTorch Hub (WARNING: inference not yet supported)ExportExport YOLOv5s-seg model to ONNX and TensorRT:pythonexport.py--weightsyolov5s-seg.pt--includeonnxengine--img640--device0ClassificationYOLOv5release v6.2brings support for classification model training, validation and deployment! See full details in ourRelease Notesand visit ourYOLOv5 Classification Colab Notebookfor quickstart tutorials.Classification CheckpointsWe 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 GoogleColab Profor easy 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.5YOLOv5s-cls22471.590.28:096.60.65.41.4YOLOv5m-cls22475.992.910:0615.50.912.93.9YOLOv5l-cls22478.094.011:5626.91.426.58.5YOLOv5x-cls22479.094.415:0454.31.848.115.9ResNet1822470.389.56:4711.20.511.73.7ResNet3422473.991.88:3320.60.921.87.4ResNet5022476.893.411:1023.41.025.68.5ResNet10122478.594.317:1042.11.944.515.9EfficientNet_b022475.192.413:0312.51.35.31.0EfficientNet_b122476.493.217:0414.91.67.81.5EfficientNet_b222476.693.417:1015.91.69.11.7EfficientNet_b322477.794.019:1918.91.912.22.4Table Notes (click to expand)All checkpoints are trained to 90 epochs with SGD optimizer withlr0=0.001andweight_decay=5e-5at image size 224 and all default settings.Runs logged tohttps://wandb.ai/glenn-jocher/YOLOv5-Classifier-v6-2Accuracyvalues are for single-model single-scale onImageNet-1kdataset.Reproduce bypython classify/val.py --data ../datasets/imagenet --img 224Speedaveraged over 100 inference images using a GoogleColab ProV100 High-RAM instance.Reproduce bypython classify/val.py --data ../datasets/imagenet --img 224 --batch 1Exportto ONNX at FP32 and TensorRT at FP16 done withexport.py.Reproduce bypython export.py --weights yolov5s-cls.pt --include engine onnx --imgsz 224Classification Usage ExamplesTrainYOLOv5 classification training supports auto-download of MNIST, Fashion-MNIST, CIFAR10, CIFAR100, Imagenette, Imagewoof, and ImageNet datasets with the--dataargument. To start training on MNIST for example use--data mnist.# Single-GPUpythonclassify/train.py--modelyolov5s-cls.pt--datacifar100--epochs5--img224--batch128# Multi-GPU DDPpython-mtorch.distributed.run--nproc_per_node4--master_port1classify/train.py--modelyolov5s-cls.pt--dataimagenet--epochs5--img224--device0,1,2,3ValValidate YOLOv5m-cls accuracy on ImageNet-1k dataset:bashdata/scripts/get_imagenet.sh--val# download ImageNet val split (6.3G, 50000 images)pythonclassify/val.py--weightsyolov5m-cls.pt--data../datasets/imagenet--img224# validatePredictUse pretrained YOLOv5s-cls.pt to predict bus.jpg:pythonclassify/predict.py--weightsyolov5s-cls.pt--sourcedata/images/bus.jpgmodel=torch.hub.load("ultralytics/yolov5","custom","yolov5s-cls.pt")# load from PyTorch HubExportExport a group of trained YOLOv5s-cls, ResNet and EfficientNet models to ONNX and TensorRT:pythonexport.py--weightsyolov5s-cls.ptresnet50.ptefficientnet_b0.pt--includeonnxengine--img224EnvironmentsGet started in seconds with our verified environments. Click each icon below for details.ContributeWe love your input! We want to make contributing to YOLOv5 as easy and transparent as possible. Please see ourContributing Guideto get started, and fill out theYOLOv5 Surveyto send us feedback on your experiences. Thank you to all our contributors!LicenseUltralytics offers two licensing options to accommodate diverse use cases:AGPL-3.0 License: ThisOSI-approvedopen-source license is ideal for students and enthusiasts, promoting open collaboration and knowledge sharing. See theLICENSEfile for more details.Enterprise License: Designed for commercial use, this license permits seamless integration of Ultralytics software and AI models into commercial goods and services, bypassing the open-source requirements of AGPL-3.0. If your scenario involves embedding our solutions into a commercial offering, reach out throughUltralytics Licensing.ContactFor YOLOv5 bug reports and feature requests please visitGitHub Issues, and join ourDiscordcommunity for questions and discussions!