目录
0 前言
电脑:RTX3070、cuda-11.0,系统ubuntu18.04
官网:https://github.com/ultralytics/yolov5
yolov5注释大神:https://github.com/SCAU-HuKai/yolov5-5.x-annotations
其CSDN:https://blog.csdn.net/qq_38253797/article/details/119043919
1 环境配置
1.1 python环境
下载代码:
git clone https://github.com/ultralytics/yolov5
进入到下载目录:
#创建python3.7的环境
conda create -n yolov5py37 python=3.7
#安装gpu版本的pytorch
#官网链接:https://pytorch.org/get-started/previous-versions/
pip install torch==1.7.1+cu110 torchvision==0.8.2+cu110 torchaudio==0.7.2 -f https://download.pytorch.org/whl/torch_stable.html
#上面这个命令安装的包:
torch==1.7.1+cu110
torchvision==0.8.2+cu110
torchaudio==0.7.2
#安装其他需要的包
pip install -r requirements.txt
#安装包的版本可能不固定,但都是满足要求的版本
1.2 官方github的样例
1.2.1 打印检测结果
创建文件inference.py
import torch
# Model
model = torch.hub.load('ultralytics/yolov5', 'yolov5s') # or yolov5m, yolov5l, yolov5x, custom
# Images
img = 'https://ultralytics.com/images/zidane.jpg' # or file, Path, PIL, OpenCV, numpy, list
# Inference
results = model(img)
# Results
results.print() # or .show(), .save(), .crop(), .pandas(), etc.
在1.1的python环境中执行,终端打印输出的有yolov5软件信息、计算机硬件信息、下载.pt模型文件、模型概况、图像、检测结果。
python inference.py
(yolov5py37) meng@meng:~/deeplearning/yolov5$ python inference.py
Downloading: "https://github.com/ultralytics/yolov5/archive/master.zip" to /home/meng/.cache/torch/hub/master.zip
Downloading https://ultralytics.com/assets/Arial.ttf to /home/meng/.config/Ultralytics/Arial.ttf...
fatal: 不是一个 git 仓库(或者任何父目录):.git
YOLOv5 2022-3-12 torch 1.7.1+cu110 CUDA:0 (NVIDIA GeForce RTX 3070, 7960MiB)
Downloading https://github.com/ultralytics/yolov5/releases/download/v6.1/yolov5s.pt to yolov5s.pt...
100%|█████████████████████████████████████| 14.1M/14.1M [00:07<00:00, 2.06MB/s]
Fusing layers...
Model Summary: 213 layers, 7225885 parameters, 0 gradients, 16.5 GFLOPs
Adding AutoShape...
image 1/1: 720x1280 2 persons, 2 ties
Speed: 7411.2ms pre-process, 8.4ms inference, 1.2ms NMS per image at shape (1, 3, 384, 640)
评论(0)
您还未登录,请登录后发表或查看评论