Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
hapi
提交
f9f2d429
H
hapi
项目概览
PaddlePaddle
/
hapi
通知
11
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
4
列表
看板
标记
里程碑
合并请求
7
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
hapi
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
4
Issue
4
列表
看板
标记
里程碑
合并请求
7
合并请求
7
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
f9f2d429
编写于
4月 15, 2020
作者:
K
Kaipeng Deng
提交者:
GitHub
4月 15, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #38 from heavengate/fix_yolo_backbone
fix yolo backbone
上级
308447ba
0e8b317f
变更
7
显示空白变更内容
内联
并排
Showing
7 changed file
with
37 addition
and
9 deletion
+37
-9
examples/yolov3/.gitignore
examples/yolov3/.gitignore
+1
-0
examples/yolov3/README.md
examples/yolov3/README.md
+8
-3
examples/yolov3/main.py
examples/yolov3/main.py
+8
-3
hapi/download.py
hapi/download.py
+11
-1
hapi/model.py
hapi/model.py
+7
-0
hapi/vision/models/darknet.py
hapi/vision/models/darknet.py
+1
-1
hapi/vision/models/yolov3.py
hapi/vision/models/yolov3.py
+1
-1
未找到文件。
examples/yolov3/.gitignore
浏览文件 @
f9f2d429
dataset/voc*
pretrain_weights/darknet53_pretrained.pdparams
examples/yolov3/README.md
浏览文件 @
f9f2d429
...
...
@@ -99,12 +99,17 @@ YOLOv3 的网络结构由基础特征提取网络、multi-scale特征融合层
| ...
```
```
bash
sh pretrain_weights/download.sh
```
### 模型训练
数据准备完
毕
后,可使用
`main.py`
脚本启动训练和评估,如下脚本会自动每epoch交替进行训练和模型评估,并将checkpoint默认保存在
`yolo_checkpoint`
目录下。
数据准备完
成
后,可使用
`main.py`
脚本启动训练和评估,如下脚本会自动每epoch交替进行训练和模型评估,并将checkpoint默认保存在
`yolo_checkpoint`
目录下。
YOLOv3模型训练总batch_size为64训练,以下以使用4卡Tesla P40每卡batch_size为16训练介绍训练方式。对于静态图和动态图,多卡训练中
`--batch_size`
为每卡上的batch_size,即总batch_size为
`--batch_size`
乘以卡数。
YOLOv3模型训练须加载骨干网络
[
DarkNet53
](
)的预训练权重,可在训练时通过`--pretrain_weights`指定,若指定为URL,将自动下载权重至`~/.cache/paddle/weights`目录并加载。
`main.py`
脚本参数可通过如下命令查询
...
...
@@ -117,7 +122,7 @@ python main.py --help
使用如下方式进行多卡训练:
```
bash
CUDA_VISIBLE_DEVICES
=
0,1,2,3 python
-m
paddle.distributed.launch main.py
--data
=
<path/to/dataset>
--batch_size
=
16
CUDA_VISIBLE_DEVICES
=
0,1,2,3 python
-m
paddle.distributed.launch main.py
--data
=
<path/to/dataset>
--batch_size
=
16
--pretrain_weights
=
https://paddlemodels.bj.bcebos.com/hapi/darknet53_pretrained.pdparams
```
#### 动态图训练
...
...
@@ -127,7 +132,7 @@ CUDA_VISIBLE_DEVICES=0,1,2,3 python -m paddle.distributed.launch main.py --data=
使用如下方式进行多卡训练:
```
bash
CUDA_VISIBLE_DEVICES
=
0,1,2,3 python main.py
-m
paddle.distributed.launch
--data
=
<path/to/dataset>
--batch_size
=
16
-d
CUDA_VISIBLE_DEVICES
=
0,1,2,3 python main.py
-m
paddle.distributed.launch
--data
=
<path/to/dataset>
--batch_size
=
16
-d
--pretrain_weights
=
https://paddlemodels.bj.bcebos.com/hapi/darknet53_pretrained.pdparams
```
...
...
examples/yolov3/main.py
浏览文件 @
f9f2d429
...
...
@@ -27,6 +27,7 @@ from paddle.io import DataLoader
from
hapi.model
import
Model
,
Input
,
set_device
from
hapi.distributed
import
DistributedBatchSampler
from
hapi.download
import
is_url
,
get_weights_path
from
hapi.datasets
import
COCODataset
from
hapi.vision.transforms
import
*
from
hapi.vision.models
import
yolov3_darknet53
,
YoloLoss
...
...
@@ -124,8 +125,11 @@ def main():
model_mode
=
'eval'
if
FLAGS
.
eval_only
else
'train'
,
pretrained
=
pretrained
)
if
FLAGS
.
pretrain_weights
is
not
None
:
model
.
load
(
FLAGS
.
pretrain_weights
,
skip_mismatch
=
True
,
reset_optimizer
=
True
)
if
FLAGS
.
pretrain_weights
and
not
FLAGS
.
eval_only
:
pretrain_weights
=
FLAGS
.
pretrain_weights
if
is_url
(
pretrain_weights
):
pretrain_weights
=
get_weights_path
(
pretrain_weights
)
model
.
load
(
pretrain_weights
,
skip_mismatch
=
True
,
reset_optimizer
=
True
)
optim
=
make_optimizer
(
len
(
batch_sampler
),
parameter_list
=
model
.
parameters
())
...
...
@@ -196,7 +200,8 @@ if __name__ == '__main__':
parser
.
add_argument
(
"-j"
,
"--num_workers"
,
default
=
4
,
type
=
int
,
help
=
"reader worker number"
)
parser
.
add_argument
(
"-p"
,
"--pretrain_weights"
,
default
=
None
,
type
=
str
,
"-p"
,
"--pretrain_weights"
,
default
=
"./pretrain_weights/darknet53_pretrained"
,
type
=
str
,
help
=
"path to pretrained weights"
)
parser
.
add_argument
(
"-r"
,
"--resume"
,
default
=
None
,
type
=
str
,
...
...
hapi/download.py
浏览文件 @
f9f2d429
...
...
@@ -29,13 +29,22 @@ from paddle.fluid.dygraph.parallel import ParallelEnv
import
logging
logger
=
logging
.
getLogger
(
__name__
)
__all__
=
[
'get_weights_path'
]
__all__
=
[
'get_weights_path'
,
'is_url'
]
WEIGHTS_HOME
=
osp
.
expanduser
(
"~/.cache/paddle/hapi/weights"
)
DOWNLOAD_RETRY_LIMIT
=
3
def
is_url
(
path
):
"""
Whether path is URL.
Args:
path (string): URL string or not.
"""
return
path
.
startswith
(
'http://'
)
or
path
.
startswith
(
'https://'
)
def
get_weights_path
(
url
,
md5sum
=
None
):
"""Get weights path from WEIGHT_HOME, if not exists,
download it from url.
...
...
@@ -62,6 +71,7 @@ def get_path(url, root_dir, md5sum=None, check_exist=True):
WEIGHTS_HOME or DATASET_HOME
md5sum (str): md5 sum of download package
"""
assert
is_url
(
url
),
"downloading from {} not a url"
.
format
(
url
)
# parse path after download to decompress under root_dir
fullpath
=
map_path
(
url
,
root_dir
)
...
...
hapi/model.py
浏览文件 @
f9f2d429
...
...
@@ -798,6 +798,13 @@ class Model(fluid.dygraph.Layer):
format
(
key
,
list
(
state
.
shape
),
list
(
param
.
shape
)))
return
param
,
state
def
_strip_postfix
(
path
):
path
,
ext
=
os
.
path
.
splitext
(
path
)
assert
ext
in
[
''
,
'.pdparams'
,
'.pdopt'
,
'.pdmodel'
],
\
"Unknown postfix {} from weights"
.
format
(
ext
)
return
path
path
=
_strip_postfix
(
path
)
param_state
=
_load_state_from_path
(
path
+
".pdparams"
)
assert
param_state
,
"Failed to load parameters, please check path."
...
...
hapi/vision/models/darknet.py
浏览文件 @
f9f2d429
...
...
@@ -136,7 +136,7 @@ class LayerWarp(fluid.dygraph.Layer):
DarkNet_cfg
=
{
53
:
([
1
,
2
,
8
,
8
,
4
])}
class
DarkNet
(
Model
):
class
DarkNet
(
fluid
.
dygraph
.
Layer
):
"""DarkNet model from
`"YOLOv3: An Incremental Improvement" <https://arxiv.org/abs/1804.02767>`_
...
...
hapi/vision/models/yolov3.py
浏览文件 @
f9f2d429
...
...
@@ -118,7 +118,7 @@ class YOLOv3(Model):
self
.
nms_posk
=
100
self
.
draw_thresh
=
0.5
self
.
backbone
=
darknet53
(
pretrained
=
(
model_mode
==
'train'
)
)
self
.
backbone
=
darknet53
(
pretrained
=
False
)
self
.
block_outputs
=
[]
self
.
yolo_blocks
=
[]
self
.
route_blocks
=
[]
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录