Package: nm-yolov5
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.To request a commercial license please complete the form atUltralytics Licensing.DocumentationSee theYOLOv5 Docsfor full documentation on training, testing and deployment.Quick Start ExamplesInstallClone repo and installrequirements.txtin aPython>=3.7.0environment, includingPyTorch>=1.7.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--source0# webcamimg.jpg# imagevid.mp4# videoscreen# screenshotpath/# directory'path/*.jpg'# glob'https://youtu.be/Zgi9g1ksQHc'# 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--cfgyolov5n.yaml--weights''--batch-size128yolov5s64yolov5m40yolov5l24yolov5x16TutorialsTrain Custom Data🚀 RECOMMENDEDTips for Best Training Results☘️
RECOMMENDEDMulti-GPU TrainingPyTorch Hub🌟 NEWTFLite, ONNX, CoreML, TensorRT Export🚀NVIDIA Jetson Nano Deployment🌟 NEWTest-Time Augmentation (TTA)Model EnsemblingModel Pruning/SparsityHyperparameter EvolutionTransfer Learning with Frozen LayersArchitecture Summary🌟 NEWRoboflow for Datasets, Labeling, and Active Learning🌟 NEWClearML Logging🌟 NEWDeci Platform🌟 NEWComet Logging🌟 NEWIntegrationsRoboflowClearML ⭐ NEWComet ⭐ NEWDeci ⭐ 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 predictionsAutomatically compile and quantize YOLOv5 for better inference performance in one click atDeciWhy YOLOv5YOLOv5 has been designed to be super easy to get started and simple to learn. We prioritize real-world results.YOLOv5-P5 640 Figure (click to expand)Figure Notes (click to expand)COCO 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)mAPval0.5:0.95mAPval0.5SpeedCPU 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 Notes (click to expand)All 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 --augmentClassification ⭐ NEWYOLOv5release v6.2brings support for classification model training, validation, prediction and export! We've made training classifier models super simple. Click below to get started.Classification Checkpoints (click to expand)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 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 Examples (click to expand)TrainYOLOv5 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--datadata/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!ContactFor YOLOv5 bugs and feature requests please visitGitHub Issues. For professional support pleaseContact Us. To request a commercial license please complete the form atUltralytics Licensing.