Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
acqpriwny1
Yolov5_PyTorch
Commits
15e84b60
Commit
15e84b60
authored
Jul 22, 2023
by
acqpriwny1
Browse files
Update README.md
parent
ebe2c0ff
Pipeline
#443
canceled with stages
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
127 additions
and
132 deletions
+127
-132
README.md
README.md
+127
-132
No files found.
README.md
View file @
15e84b60
# YOLOV5测试
# YOLOV5算力测试
## 1.模型介绍
## 1.模型介绍
...
@@ -39,27 +38,35 @@ python依赖安装:
...
@@ -39,27 +38,35 @@ python依赖安装:
pip3 install -r requirement.txt
pip3 install -r requirement.txt
```
```
进行训练之前需要对bn进行设置,下面给出示例(function.py的路径根据所用环境进行调整):
本地安装PyTorch1.7
```
```
#具体路径根据当前所使用的python环境进行修正
# 安装torch
vim /usr/local/lib/python3.8/site-packages/torch/nn/functional.py
pip install /public/software/apps/DeepLearning/whl/dtk-21.04/torch-1.8.0a0+56b43f4-cp37-cp37m-linux_x86_64.whl
```
# 安装torchvision
pip install /public/software/apps/DeepLearning/whl/dtk-21.04/torchvision-0.9.0a0-cp37-cp37m-linux_x86_64.whl
如图将torch.backends.cudnn.enabled改为False
```
在本地创建一个pytorch_env.sh的文件,添加环境变量:
```
vi ~/pytorch_env.sh

export
LD_LIBRARY_PATH=/public/software/apps/DeepLearning/PyTorch_Lib/lib:/public/software/apps/DeepLearning/PyTorch_Lib/lmdb-0.9.24-build/lib:/public/software/apps/DeepLearning/PyTorch_Lib/opencv-2.4.13.6-build/lib:/public/software/apps/DeepLearning/PyTorch_Lib/openblas-0.3.7-build/lib:$LD_LIBRARY_PATH
# 记得以后每次登录新的节点时,一定要执行一次source ~/pytorch_env.sh命令,这关系到服务器能不能找到PyTorch
source ~/pytorch_env.sh
```
### 预训练模型
### 预训练模型
预训练模型均在
Checkpoint
s文件夹内
预训练模型均在
model
s文件夹内
### 单卡训练
### 单卡训练
```
```
export HIP_VISIBLE_DEVICES=0
export HIP_VISIBLE_DEVICES=0
python
3
train.py --
b
at
ch 32 --data coco
.yaml --cfg
'
yolov5
m
.yaml
'
--weights
'' --project 'run/train' --hyp 'data/hyps/hyp.scratch-high.yaml' --epochs 1000 2>&1 | tee yolov5m.log
python train.py --
d
at
a data/citrus
.yaml --cfg
models/
yolov5
s
.yaml
--weights
weights/yolov5s.pt --epochs 150 --batch-size 4
```
```
### 单节点多卡训练
### 单节点多卡训练
...
@@ -73,20 +80,23 @@ python3 -m torch.distributed.run --nproc_per_node 4 train.py --batch 128 --data
...
@@ -73,20 +80,23 @@ python3 -m torch.distributed.run --nproc_per_node 4 train.py --batch 128 --data
其中--nproc_per_node参数代表卡的个数,--batch参数代表global batchsize的大小
其中--nproc_per_node参数代表卡的个数,--batch参数代表global batchsize的大小
### 多节点多卡
## 推理测试
```
```
#下面的例子中使用两个节点,每个节点包含4加速张卡
python detect.py --source 0 # webcam
#node 1
file.jpg # image
python3 -m torch.distributed.launch --nproc_per_node 4 --nnodes 2 --node_rank 0 --master_addr "node1" --master_port 34567 train.py --batch 256 --data coco.yaml --weight '' --project 'multi/train' --hyp 'data/hyps/hyp.scratch-high.yaml' --cfg 'yolov5m.yaml' --epochs 1000 2>&1 | tee yolov5m_8.log
file.mp4 # video
path/ # directory
path/*.jpg # glob
'https://youtu.be/NUsoVlDFqZg' # YouTube
'rtsp://example.com/media.mp4' # RTSP, RTMP, HTTP stream
#node2
python3 -m torch.distributed.launch --nproc_per_node 4 --nnodes 2 --node_rank 1 --master_addr "node1" --master_port 34567 train.py --batch 256 --data coco.yaml --weight '' --project 'multi/train' --hyp 'data/hyps/hyp.scratch-high.yaml' --cfg 'yolov5m.yaml' --epochs 1000 2>&1 | tee yolov5m_8.log
```
```
detect.py 在各种来源上运行 YOLOv5 推论,从最新的 YOLOv5 版本中自动下载模型,并将结果保存到 runs/detect 中。推理源示例如下
**tips:需要注意的是,在超参数的选取上,小模型使用hyp.scratch-low,例如yolov5s,而大模型需要使用hyp.scratch-high,例如yolov5m,它们的区别为,low有更快的收敛速度,而high参数收敛速度慢,但是不容易陷入局部最优。**
```
python detect.py --weights yolov5s.pt --img 640 --conf 0.25 --source data/images/
## 推理测试
Image(filename='runs/detect/exp/zidane.jpg', width=600)
```
将训练好的pt文件导入weight参数中即可,推理代码如下:
将训练好的pt文件导入weight参数中即可,推理代码如下:
...
@@ -94,39 +104,24 @@ python3 -m torch.distributed.launch --nproc_per_node 4 --nnodes 2 --node_rank 1
...
@@ -94,39 +104,24 @@ python3 -m torch.distributed.launch --nproc_per_node 4 --nnodes 2 --node_rank 1
python3 val.py --data data/coco-v5.yaml --weights runs/train/exp12/weights/best.pt --device 0
python3 val.py --data data/coco-v5.yaml --weights runs/train/exp12/weights/best.pt --device 0
```
```
## 画出loss和精度曲线
如果在训练一段时间后想要得到类似上述的loss及map曲线,我们提供了view_code.py文件,只需要将您训练过程中--project 指定的路径写入,之后执行python3 view_code.py即可在该路径下得到曲线的图像。
## pycocotools输出结果特别低问题
在训练结束或者推理结束后有时候会发现pycocotools输出的结果异常,数值会非常低,而训练过程中结果正常,如下图所示:

这是由于python的版本过低导致的问题,除了升级Python版本外,还可以对代码进行修改也可以解决问题,将val.py文件中的如图所示位置,注释掉红框部分的代码也可得到正确的结果。

## 准确率数据
## 准确率数据
| 模型 |
数据类型
| map0.5:0.95 | map0.5 |
| 模型 |
size(pixels)
| map0.5:0.95 | map0.5 |
| :-----: | :------: | :---------: | :----: |
| :-----: | :------: | :---------: | :----: |
| yolov5n |
混精
| 27.9 | 46.8 |
| yolov5n |
640
| 27.9 | 46.8 |
| yolov5s |
混精
| 37.2 | 57.1 |
| yolov5s |
640
| 37.2 | 57.1 |
| yolov5m |
混精
| 44.3 | 64.1 |
| yolov5m |
640
| 44.3 | 64.1 |
| yolov5l |
混精
| 48 | 67.3 |
| yolov5l |
640
| 48 | 67.3 |
| yolov5x |
混精
| 49.6 | 68.6 |
| yolov5x |
640
| 49.6 | 68.6 |
## 源码仓库及问题反馈
## 源码仓库及问题反馈
https://developer.hpccube.com/codes/
modelzoo
/yolov
5_
pytorch
https://developer.hpccube.com/codes/
acqpriwny1
/yolov
-5-
pytorch
/
## 参考
## 参考
[
GitHub - ultralytics/yolov5 at v6.
0
](
https://github.com/ultralytics/yolov5/
t
re
e
/v6.
0
)
[GitHub - ultralytics/yolov5 at v6.
1]
https://github.com/ultralytics/yolov5/re
leases/tag
/v6.
1)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment