Link to this sectionYOLOv5 快速入门 🚀#
开启你的实时 object detection 之旅,与 Ultralytics YOLOv5 一起探索动态领域!本指南专为旨在掌握 YOLOv5 的 AI 爱好者和专业人士设计,是一个全面的起点。从初始设置到高级 training techniques,我们已为你准备好一切。读完本指南后,你将有信心使用先进的 deep learning 方法将 YOLOv5 应用于你的项目中。让我们点火升空,翱翔于 YOLOv5 的世界吧!
Link to this section安装#
通过克隆 YOLOv5 repository 并配置环境来准备起飞。这能确保安装所有必要的 requirements。检查并确保你已准备好 Python>=3.8.0 和 PyTorch>=1.8。这些基础工具对于高效运行 YOLOv5 至关重要。
git clone https://github.com/ultralytics/yolov5 # clone repository
cd yolov5
pip install -r requirements.txt # install dependenciesLink to this section使用 PyTorch Hub 进行推理#
体验 YOLOv5 PyTorch Hub 推理的简便性,通过这种方式,models 可从最新的 YOLOv5 release 中无缝下载。该方法利用 PyTorch 的能力进行轻松的模型加载和执行,让获取预测结果变得简单直接。
import torch
# Model loading
model = torch.hub.load("ultralytics/yolov5", "yolov5s") # Can be 'yolov5n' - 'yolov5x6', or 'custom'
# Inference on images
img = "https://ultralytics.com/images/zidane.jpg" # Can be a file, Path, PIL, OpenCV, numpy, or list of images
# Run inference
results = model(img)
# Display results
results.print() # Other options: .show(), .save(), .crop(), .pandas(), etc. Explore these in the Predict mode documentation.Link to this section使用 detect.py 进行推理#
Harness detect.py for versatile inference on various sources. It automatically fetches models from the latest YOLOv5 release and saves results with ease. This script is ideal for command-line usage and integrating YOLOv5 into larger systems, supporting inputs like images, videos, directories, webcams, and even live streams.
python detect.py --weights yolov5s.pt --source 0 # webcam
python detect.py --weights yolov5s.pt --source image.jpg # image
python detect.py --weights yolov5s.pt --source video.mp4 # video
python detect.py --weights yolov5s.pt --source screen # screenshot
python detect.py --weights yolov5s.pt --source path/ # directory
python detect.py --weights yolov5s.pt --source list.txt # list of images
python detect.py --weights yolov5s.pt --source list.streams # list of streams
python detect.py --weights yolov5s.pt --source 'path/*.jpg' # glob pattern
python detect.py --weights yolov5s.pt --source 'https://youtu.be/LNwODJXcvt4' # YouTube video
python detect.py --weights yolov5s.pt --source 'rtsp://example.com/media.mp4' # RTSP, RTMP, HTTP streamLink to this section训练#
Replicate the YOLOv5 COCO dataset benchmarks by following the training instructions below. The necessary models and datasets (like coco128.yaml or the full coco.yaml) are pulled directly from the latest YOLOv5 release. Training YOLOv5n/s/m/l/x on a V100 GPU should typically take 1/2/4/6/8 days respectively (note that Multi-GPU training setups work faster). Maximize performance by using the highest possible --batch-size or use --batch-size -1 for the YOLOv5 AutoBatch feature, which automatically finds the optimal batch size. The following batch sizes are ideal for V100-16GB GPUs. Refer to our configuration guide for details on model configuration files (*.yaml).
# Train YOLOv5n on COCO128 for 3 epochs
python train.py --data coco128.yaml --epochs 3 --weights yolov5n.pt --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
总之,YOLOv5 不仅是用于目标检测的尖端工具,也是 machine learning 力量的证明,它改变了我们通过视觉理解与世界互动的方式。随着你通过本指南逐步深入并将 YOLOv5 应用于你的项目,请记住你正处于技术革命的前沿,能够在 computer vision 领域取得卓越成就。如果你需要更多见解或来自其他梦想家的支持,欢迎来到我们的 GitHub repository,这里汇聚了庞大的开发者和研究人员社区。探索更多资源,如用于无代码数据集管理和模型训练的 Ultralytics Platform,或查看我们的 Solutions 页面以获取实际应用和灵感。继续探索,继续创新,享受 YOLOv5 带来的奇迹吧。祝你检测愉快!🌠🔍