惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

aimingoo的专栏
aimingoo的专栏
S
Securelist
博客园 - Franky
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
IT之家
IT之家
GbyAI
GbyAI
Microsoft Azure Blog
Microsoft Azure Blog
The Cloudflare Blog
云风的 BLOG
云风的 BLOG
N
News and Events Feed by Topic
AI
AI
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Schneier on Security
Schneier on Security
Attack and Defense Labs
Attack and Defense Labs
Vercel News
Vercel News
腾讯CDC
Google DeepMind News
Google DeepMind News
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
M
MIT News - Artificial intelligence
WordPress大学
WordPress大学
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
N
Netflix TechBlog - Medium
量子位
S
Schneier on Security
Hacker News: Ask HN
Hacker News: Ask HN
Cyberwarzone
Cyberwarzone
S
Security Affairs
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
N
News and Events Feed by Topic
T
Tenable Blog
PCI Perspectives
PCI Perspectives
MyScale Blog
MyScale Blog
L
Lohrmann on Cybersecurity
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
C
Cyber Attacks, Cyber Crime and Cyber Security
W
WeLiveSecurity
N
News | PayPal Newsroom
P
Proofpoint News Feed
O
OpenAI News
C
CERT Recently Published Vulnerability Notes
B
Blog
Cisco Talos Blog
Cisco Talos Blog
Microsoft Security Blog
Microsoft Security Blog
V
Visual Studio Blog
MongoDB | Blog
MongoDB | Blog
大猫的无限游戏
大猫的无限游戏
A
Arctic Wolf
Y
Y Combinator Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Spread Privacy
Spread Privacy

洛屿的小站

STM32F407 IAR环境下uC/OS-III移植完整指南 STM32 UCOS3+HAL库集成中的FPU HardFault问题 一种简单的卡尔曼滤波器设计 Cadence - 应律而动,落指成音 Zephyr - 聆风之息,为你而奏 不改一行插件代码,实现消息优先级与阻断 洛玖定时任务系统 在 butterfly 主题中添加首页点集动画(基于p2line项目) 你好,2026 stm32f4xx-ads1256驱动 stm32f4xx-ad9854并行驱动 主动式网站状态监测实现及其应用 右键菜单加入用Trae打开文件和文件夹 三角洲行动ID映射表 洛玖SDK说明 为网页文章开头添加原文连接 Hexo-Butterfly主题在主页添加GitHub贡献日历 Proteus中555定时器仿真问题 装饰器 洛玖开发日记 STS3032舵机获取力矩输出 kotlin网页前后端那些事 mspm0g3507-ad9850 奇怪的bug Paddle模型转PaddleLite 人工智能考核 构建一个yolov3网络 yolo和paddle模型常见输出参数 PaddleDetection 随便写的一些东西 实验室C语言第一次考核题目讲解及相关代码解读 C语言神经网络房价预测系统 C、C++数组,指针,指针数组,数组指针的区别 C、C++的大括号是必须的部分吗? C、C++预处理详解 C、C++其他关键字详解 C、C++存储类型关键字详解 C、C++控制语句关键字详解 C、C++数据类型关键字详解 C、C++关键字 C++药品管理系统 Bi-LSTM(Attention)的PyTorch实现 C语言实现波士顿房价预测 easy库的使用 edgeboardFZ3A相关问题 Predict.py的编写 Paddle环境搭建 GMD09601-0.96OLED显示屏 【LeetCode 1617】统计子树中城市之间最大距离 C语言学习相关 STM32阵列按键 CH32(F10X F20X) 最短路 拓扑排序
百度Paddle模型训练
洛屿 · 2023-04-04 · via 洛屿的小站

注意:本说明并没有详细谈及各参数的调整

对于多卡训练,只需要将python tools/trainxxxx改为:

python -m paddle.distributed.launch --selected_gpus 0,1,2,3 tools/trainxxxxxx

其中0,1,2,3参数是因为有4张卡,若是两张卡训练,此处应写0,1

你可以通过nvidia-smi查询显卡数量


以百度飞浆推出的PaddleDetection目标检测开发套件为例

项目架构

这是其Github项目文件

我们将要用到的基本架构如下:


对于数据集

其中,car_train是我们自己的数据集,这里的数据集格式为VOC

JPEGImages存放所有数据集图片,Annotations中存放所有标注文件

你可以通过labelimg软件进行数据的标注

当我们有了这样的数据集后,就可以准备进行模型训练了


模型训练前的准备

我们这里使用的是yolov3模型,你可以在克隆下来的PaddleDetection的:PaddleDetection/configs/中找到它

但是可以发现,在这些yml中,没有我们想要的yolov3_mobilenet_v3_small_270e_voc

我们复制yolov3_mobilenet_v3_large_270e_voc.yml 将其更名为yolov3_mobilenet_v3_small_270e_voc.yml

cp yolov3_mobilenet_v3_large_270e_voc.yml yolov3_mobilenet_v3_small_270e_voc.yml

更改复制好的small_270e中的内容:

改前:

改后:

随后,我们需要修改与yolov3同一目录下datasets中的文件voc.yml

注意这里的dataset_dir要改成我们数据集的路径

**这里的num_classes要着重注意!**其大小应与我们的标签数一致

TrainDataset中的anno_path是每次训练时要用到的文件,其格式可以点我查看

EvalDataset中的anno_path是每次检验模型时要用到的文件,其格式可以点我查看

label_list的格式可以点我查看

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
metric: VOC
map_type: 11point
num_classes: 8

TrainDataset:
!VOCDataSet
dataset_dir: dataset/car_train
anno_path: train.txt
label_list: labels.txt
data_fields: ['image', 'gt_bbox', 'gt_class', 'difficult']

EvalDataset:
!VOCDataSet
dataset_dir: dataset/car_train
anno_path: eval.txt
label_list: labels.txt
data_fields: ['image', 'gt_bbox', 'gt_class', 'difficult']

TestDataset:
!ImageFolder
anno_path: dataset/car_train/labels.txt


模型训练

当你完成以上步骤:

PaddleDetection的下载

数据集的准备(包括图片文件,图片数据标注文件,训练文件train.txt 测试文件eval.txt 标签文件labels.txt)

训练config的配置

恭喜,你可以进行模型训练了

模型训练

1
python tools/train.py -c configs/yolov3/yolov3_mobilenet_v3_small_270e_voc.yml --use_vdl=True --eval

断点训练

1
python tools/train.py -c configs/yolov3/yolov3_mobilenet_v3_small_270e_voc.yml -r output/yolov3_mobilenet_v3_small_270e_voc/100

注意这里的100需要根据你的中断点而调整,比如上一次训练被我停止在了第19次

(该文件的位置位于之前yolov3_mobilenet_v3_small_270e_voc.yml中设置的weight目录路径中

那这里就需要填写19


模型评估

1
python tools/eval.py -c configs/yolov3/yolov3_mobilenet_v3_small_270e_voc.yml -o weights=output/yolov3_mobilenet_v3_small_270e_voc/best_model

模型导出

1
python tools/export_model.py -c configs/yolov3/yolov3_mobilenet_v3_small_270e_voc.yml --output_dir=./inference_model -o weights=output/yolov3_mobilenet_v3_small_270e_voc/best_model

模型预测

1
python deploy/python/infer.py --model_dir=./inference_model/yolov3_mobilenet_v3_small_270e_voc --image_file=./street.jpg --device=GPU --threshold=0.2

杂项解析

train.txt格式

1
2
3
4
第一列为图片路径,	第二列为图片对应的xml文件路径
JPEGImages/4457.jpg Annotations/4457.xml
JPEGImages/212.jpg Annotations/212.xml
JPEGImages/642.jpg Annotations/642.xml

eval.txt格式

与train.txt一致

labels.txt格式

1
2
3
4
5
6
7
8
9
bump
cone
bridge
granary
CrossWalk
tractor
corn
pig

randlist.py代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import os
import random
import xml.dom.minidom

lst = ['bump', 'cone', 'bridge', 'granary', 'CrossWalk', 'tractor', 'corn', 'pig']
def ReadFileDatas():
FileNamelist = []
file = open('train.txt','r+')
for line in file:
line = line.strip('\n')
FileNamelist.append(line)
#print('len ( FileNamelist ) = ' ,len(FileNamelist))
file.close()
return FileNamelist

def WriteDatasToFile(listInfo):
file_handle_train = open('train.txt',mode='w')
file_handle_eval = open("eval.txt",mode='w')
i = 0
for idx in range(len(listInfo)):
str = listInfo[idx]

ndex = str.rfind('_')
str_Result = str + '\n'
if(i%6 != 0):
file_handle_train.write(str_Result)
else:
file_handle_eval.write(str_Result)
i += 1
file_handle_train.close()
file_handle_eval.close()

path = './Annotations/'
res = os.listdir(path)

def WriteDataToFile(DataList):
file_handle_train = open('train.txt',mode='w')
file_handle_eval = open("eval.txt",mode='w')
i = 0
for idx in range(len(DataList)):
str = DataList[idx]
if(i%6 != 0):
file_handle_train.write(str+'\n')
else:
file_handle_eval.write(str+'\n')
i += 1
file_handle_train.close()
file_handle_eval.close()

dataList = []
for i in res:
#print("./Images/"+ str(i[0:-4:1]) + ".jpg "+ path + str(i))
dataList.append("./JPEGImages/"+ str(i[0:-4:1]) + ".jpg "+ path + str(i))
WriteDataToFile(DataList=dataList)

listFileInfo = ReadFileDatas()
random.shuffle(listFileInfo)# 打乱
WriteDatasToFile(listFileInfo)

版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 洛屿的小站

打赏

  • wechat

    wechat

  • alipay

    alipay