跳至内容

YOLOv5 快速入门 🚀

Embark on your journey into the dynamic realm of real-time object detection with YOLOv5! This guide is crafted to serve as a comprehensive starting point for AI enthusiasts and professionals aiming to master YOLOv5. From initial setup to advanced training techniques, we've got you covered. By the end of this guide, you'll have the knowledge to implement YOLOv5 into your projects confidently. Let's ignite the engines and soar into YOLOv5!

安装

通过克隆版本库和建立环境为启动做好准备。这将确保所有必要的要求都已安装。检查 Python>=3.8.0PyTorch>=1.8准备起飞。

git clone https://github.com/ultralytics/yolov5  # clone repository
cd yolov5
pip install -r requirements.txt  # install dependencies

Inference with PyTorch Hub

体验YOLOv5 PyTorch Hub 推断的简便性, 模型可从最新的YOLOv5 版本中无缝下载。

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.

使用 detect.py 进行推理

线束 detect.py 用于对各种来源进行多功能推理。它能自动获取 模型 从最新的YOLOv5 释放 并轻松保存结果。

python detect.py --weights yolov5s.pt --source 0                               # webcam
                                               image.jpg                       # image
                                               video.mp4                       # video
                                               screen                          # screenshot
                                               path/                           # directory
                                               list.txt                        # list of images
                                               list.streams                    # list of streams
                                               'path/*.jpg'                    # glob
                                               'https://youtu.be/LNwODJXcvt4'  # YouTube
                                               'rtsp://example.com/media.mp4'  # RTSP, RTMP, HTTP stream

培训

复制YOLOv5 COCO 按照以下说明进行基准测试。必要的 模型数据集 直接从最新的YOLOv5 释放.在 V100GPU 上训练 YOLOv5n/s/m/l/x,一般应分别需要 1/2/4/6/8 天(注意:在 V100 上训练 YOLOv5n/s/m/l/x,一般应分别需要 1/2/4/6/8 天)。 多GPU 更快地运行)。通过使用尽可能高的 --batch-size 或使用 --batch-size -1 为YOLOv5 自动批处理 feature. The following batch sizes are ideal for V100-16GB GPUs.

python train.py --data coco.yaml --epochs 300 --weights '' --cfg yolov5n.yaml  --batch-size 128
                                                                 yolov5s                    64
                                                                 yolov5m                    40
                                                                 yolov5l                    24
                                                                 yolov5x                    16

YOLO 训练曲线

To conclude, YOLOv5 is not only a state-of-the-art tool for object detection but also a testament to the power of machine learning in transforming the way we interact with the world through visual understanding. As you progress through this guide and begin applying YOLOv5 to your projects, remember that you are at the forefront of a technological revolution, capable of achieving remarkable feats. Should you need further insights or support from fellow visionaries, you're invited to our GitHub repository home to a thriving community of developers and researchers. Keep exploring, keep innovating, and enjoy the marvels of YOLOv5. Happy detecting! 🌠🔍

📅 Created 1 year ago ✏️ Updated 1 month ago

评论