yolov5入门

1、创建python虚拟环境
打开命令行或终端,然后导航到你希望存放虚拟环境的位置。接着,运行以下命令来创建一个新的虚拟环境:

python -m venv test-env

激活虚拟环境

C:\Users\Administrator\test-env\Scripts\activate

关闭虚拟环境

C:\Users\Administrator\test-env\Scripts\deactivate

2、进入yolo下载地址https://github.com/ultralytics/yolov5下载yolov5源码

git clone https://github.com/ultralytics/yolov5  # clone

下载yolo依赖

cd yolov5
C:\Users\Administrator\test-env\Scripts\activate   #切换虚拟环境
pip install -r requirements.txt  -i https://pypi.tuna.tsinghua.edu.cn/simple #添加清华源

下载yolo的yolov5s.pt文件:https://download.csdn.net/download/qq_23350817/89709700

3、python代码实现图片识别

import torch

# Model
model = torch.hub.load("ultralytics/yolov5", "yolov5s")  # or yolov5n - yolov5x6, custom

# Images
img = "D:\\yolo\\ultralytics-yolo\\bus.jpg"  # or file, Path, PIL, OpenCV, numpy, list

# Inference
results = model(img)

# Results
results.print()  # or .show(), .save(), .crop(), .pandas(), etc.
results.show() 

4、python命令行实现图片识别

python detect.py --weights yolov5s.pt --source  'D:\\yolo\\ultralytics-yolo\\picture\\bus.jpg'

5、python命令行实现视频文件识别

python detect.py --weights yolov5s.pt --source  'D:\\yolo\\ultralytics-yolo\\video\\1.mp4'

命令行运行的结果将保存到yolov5/runs/detect目录下。

6 、python命令行实现RTSP流识别:

python detect.py --weights yolov5s.pt --source "rtsp://admin:[email protected]:554/h264/ch1/main/av_stream"

volov5支持的命令行输出格式:

python detect.py --weights yolov5s.pt --source 0                               # webcam
                                               img.jpg                         # image
                                               vid.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

你可能感兴趣的:(YOLO)