Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
hapi
提交
244d73a7
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看板
提交
244d73a7
编写于
4月 18, 2020
作者:
D
dengkaipeng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
clean vision
上级
c54980b9
变更
19
隐藏空白更改
内联
并排
Showing
19 changed file
with
87 addition
and
48 deletion
+87
-48
examples/bmn/eval.py
examples/bmn/eval.py
+2
-1
examples/bmn/modeling.py
examples/bmn/modeling.py
+2
-2
examples/bmn/predict.py
examples/bmn/predict.py
+2
-1
examples/bmn/train.py
examples/bmn/train.py
+2
-1
examples/tsm/infer.py
examples/tsm/infer.py
+1
-1
examples/tsm/main.py
examples/tsm/main.py
+1
-1
examples/tsm/modeling.py
examples/tsm/modeling.py
+1
-1
examples/yolov3/README.md
examples/yolov3/README.md
+2
-8
examples/yolov3/coco.py
examples/yolov3/coco.py
+0
-0
examples/yolov3/infer.py
examples/yolov3/infer.py
+3
-2
examples/yolov3/main.py
examples/yolov3/main.py
+7
-11
examples/yolov3/modeling.py
examples/yolov3/modeling.py
+44
-4
examples/yolov3/transforms.py
examples/yolov3/transforms.py
+0
-0
hapi/datasets/__init__.py
hapi/datasets/__init__.py
+8
-1
hapi/model.py
hapi/model.py
+1
-1
hapi/vision/models/__init__.py
hapi/vision/models/__init__.py
+1
-10
hapi/vision/models/darknet.py
hapi/vision/models/darknet.py
+2
-2
hapi/vision/transforms/__init__.py
hapi/vision/transforms/__init__.py
+6
-1
hapi/vision/transforms/functional.py
hapi/vision/transforms/functional.py
+2
-0
未找到文件。
examples/bmn/eval.py
浏览文件 @
244d73a7
...
...
@@ -19,7 +19,8 @@ import logging
import
paddle.fluid
as
fluid
from
hapi.model
import
set_device
,
Input
from
hapi.vision.models
import
bmn
,
BmnLoss
from
modeling
import
bmn
,
BmnLoss
from
bmn_metric
import
BmnMetric
from
reader
import
BmnDataset
from
config_utils
import
*
...
...
hapi/vision/models/bmn_model
.py
→
examples/bmn/modeling
.py
浏览文件 @
244d73a7
...
...
@@ -26,7 +26,7 @@ DATATYPE = 'float32'
pretrain_infos
=
{
'bmn'
:
(
'https://paddlemodels.bj.bcebos.com/hapi/bmn.pdparams'
,
'
9286c821acc4cad46d6613b931ba468c
'
)
'
aa84e3386e1fbd117fb96fa572feeb94
'
)
}
...
...
@@ -462,5 +462,5 @@ def bmn(tscale,
weight_path
=
get_weights_path
(
*
(
pretrain_infos
[
'bmn'
]))
assert
weight_path
.
endswith
(
'.pdparams'
),
\
"suffix of weight must be .pdparams"
model
.
load
(
weight_path
[:
-
9
]
)
model
.
load
(
weight_path
)
return
model
examples/bmn/predict.py
浏览文件 @
244d73a7
...
...
@@ -19,7 +19,8 @@ import logging
import
paddle.fluid
as
fluid
from
hapi.model
import
set_device
,
Input
from
hapi.vision.models
import
bmn
,
BmnLoss
from
modeling
import
bmn
,
BmnLoss
from
bmn_metric
import
BmnMetric
from
reader
import
BmnDataset
from
config_utils
import
*
...
...
examples/bmn/train.py
浏览文件 @
244d73a7
...
...
@@ -19,9 +19,10 @@ import sys
import
os
from
hapi.model
import
set_device
,
Input
from
hapi.vision.models
import
bmn
,
BmnLoss
from
reader
import
BmnDataset
from
config_utils
import
*
from
modeling
import
bmn
,
BmnLoss
DATATYPE
=
'float32'
...
...
examples/tsm/infer.py
浏览文件 @
244d73a7
...
...
@@ -20,9 +20,9 @@ import argparse
import
numpy
as
np
from
hapi.model
import
Input
,
set_device
from
hapi.vision.models
import
tsm_resnet50
from
check
import
check_gpu
,
check_version
from
modeling
import
tsm_resnet50
from
kinetics_dataset
import
KineticsDataset
from
transforms
import
*
...
...
examples/tsm/main.py
浏览文件 @
244d73a7
...
...
@@ -24,8 +24,8 @@ from paddle.fluid.dygraph.parallel import ParallelEnv
from
hapi.model
import
Model
,
CrossEntropy
,
Input
,
set_device
from
hapi.metrics
import
Accuracy
from
hapi.vision.models
import
tsm_resnet50
from
modeling
import
tsm_resnet50
from
check
import
check_gpu
,
check_version
from
kinetics_dataset
import
KineticsDataset
from
transforms
import
*
...
...
hapi/vision/models/tsm
.py
→
examples/tsm/modeling
.py
浏览文件 @
244d73a7
...
...
@@ -196,7 +196,7 @@ def _tsm_resnet(num_layers, seg_num=8, num_classes=400, pretrained=True):
weight_path
=
get_weights_path
(
*
(
pretrain_infos
[
num_layers
]))
assert
weight_path
.
endswith
(
'.pdparams'
),
\
"suffix of weight must be .pdparams"
model
.
load
(
weight_path
[:
-
9
]
)
model
.
load
(
weight_path
)
return
model
...
...
examples/yolov3/README.md
浏览文件 @
244d73a7
...
...
@@ -99,18 +99,12 @@ YOLOv3 的网络结构由基础特征提取网络、multi-scale特征融合层
| ...
```
```
bash
sh pretrain_weights/download.sh
```
### 模型训练
数据准备完成后,可使用
`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`
脚本参数可通过如下命令查询
```
bash
...
...
@@ -122,7 +116,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
--pretrain_weights
=
https://paddlemodels.bj.bcebos.com/hapi/darknet53_pretrained.pdparams
CUDA_VISIBLE_DEVICES
=
0,1,2,3 python
-m
paddle.distributed.launch main.py
--data
=
<path/to/dataset>
--batch_size
=
16
```
#### 动态图训练
...
...
@@ -132,7 +126,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
--pretrain_weights
=
https://paddlemodels.bj.bcebos.com/hapi/darknet53_pretrained.pdparams
CUDA_VISIBLE_DEVICES
=
0,1,2,3 python main.py
-m
paddle.distributed.launch
--data
=
<path/to/dataset>
--batch_size
=
16
-d
```
...
...
hapi/datasets
/coco.py
→
examples/yolov3
/coco.py
浏览文件 @
244d73a7
文件已移动
examples/yolov3/infer.py
浏览文件 @
244d73a7
...
...
@@ -25,8 +25,9 @@ from paddle.fluid.optimizer import Momentum
from
paddle.io
import
DataLoader
from
hapi.model
import
Model
,
Input
,
set_device
from
hapi.vision.models
import
yolov3_darknet53
,
YoloLoss
from
hapi.vision.transforms
import
*
from
modeling
import
yolov3_darknet53
,
YoloLoss
from
transforms
import
*
from
visualizer
import
draw_bbox
...
...
examples/yolov3/main.py
浏览文件 @
244d73a7
...
...
@@ -27,12 +27,12 @@ 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
from
hapi.vision.transforms
import
Compose
,
BatchCompose
from
modeling
import
yolov3_darknet53
,
YoloLoss
from
coco
import
COCODataset
from
coco_metric
import
COCOMetric
from
transforms
import
*
NUM_MAX_BOXES
=
50
...
...
@@ -126,10 +126,7 @@ def main():
pretrained
=
pretrained
)
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
)
model
.
load
(
FLAGS
.
pretrain_weights
,
skip_mismatch
=
True
,
reset_optimizer
=
True
)
optim
=
make_optimizer
(
len
(
batch_sampler
),
parameter_list
=
model
.
parameters
())
...
...
@@ -168,7 +165,7 @@ def main():
save_dir
=
"yolo_checkpoint/mixup"
,
save_freq
=
10
)
# do not use image mixup transfrom in
laste
FLAGS.no_mixup_epoch epoches
# do not use image mixup transfrom in
the last
FLAGS.no_mixup_epoch epoches
dataset
.
mixup
=
False
model
.
fit
(
train_data
=
loader
,
epochs
=
FLAGS
.
no_mixup_epoch
,
...
...
@@ -200,8 +197,7 @@ if __name__ == '__main__':
parser
.
add_argument
(
"-j"
,
"--num_workers"
,
default
=
4
,
type
=
int
,
help
=
"reader worker number"
)
parser
.
add_argument
(
"-p"
,
"--pretrain_weights"
,
default
=
"./pretrain_weights/darknet53_pretrained"
,
type
=
str
,
"-p"
,
"--pretrain_weights"
,
default
=
None
,
type
=
str
,
help
=
"path to pretrained weights"
)
parser
.
add_argument
(
"-r"
,
"--resume"
,
default
=
None
,
type
=
str
,
...
...
hapi/vision/models/yolov3
.py
→
examples/yolov3/modeling
.py
浏览文件 @
244d73a7
...
...
@@ -16,13 +16,13 @@ from __future__ import division
from
__future__
import
print_function
import
paddle.fluid
as
fluid
from
paddle.fluid.dygraph.nn
import
Conv2D
from
paddle.fluid.dygraph.nn
import
Conv2D
,
BatchNorm
from
paddle.fluid.param_attr
import
ParamAttr
from
paddle.fluid.regularizer
import
L2Decay
from
hapi.model
import
Model
,
Loss
from
hapi.download
import
get_weights_path
from
.darknet
import
darknet53
,
ConvBNLayer
from
hapi.vision.models
import
darknet53
__all__
=
[
'YoloLoss'
,
'YOLOv3'
,
'yolov3_darknet53'
]
...
...
@@ -33,6 +33,46 @@ pretrain_infos = {
}
class
ConvBNLayer
(
fluid
.
dygraph
.
Layer
):
def
__init__
(
self
,
ch_in
,
ch_out
,
filter_size
=
3
,
stride
=
1
,
groups
=
1
,
padding
=
0
,
act
=
"leaky"
):
super
(
ConvBNLayer
,
self
).
__init__
()
self
.
conv
=
Conv2D
(
num_channels
=
ch_in
,
num_filters
=
ch_out
,
filter_size
=
filter_size
,
stride
=
stride
,
padding
=
padding
,
groups
=
groups
,
param_attr
=
ParamAttr
(
initializer
=
fluid
.
initializer
.
Normal
(
0.
,
0.02
)),
bias_attr
=
False
,
act
=
None
)
self
.
batch_norm
=
BatchNorm
(
num_channels
=
ch_out
,
param_attr
=
ParamAttr
(
initializer
=
fluid
.
initializer
.
Normal
(
0.
,
0.02
),
regularizer
=
L2Decay
(
0.
)),
bias_attr
=
ParamAttr
(
initializer
=
fluid
.
initializer
.
Constant
(
0.0
),
regularizer
=
L2Decay
(
0.
)))
self
.
act
=
act
def
forward
(
self
,
inputs
):
out
=
self
.
conv
(
inputs
)
out
=
self
.
batch_norm
(
out
)
if
self
.
act
==
'leaky'
:
out
=
fluid
.
layers
.
leaky_relu
(
x
=
out
,
alpha
=
0.1
)
return
out
class
YoloDetectionBlock
(
fluid
.
dygraph
.
Layer
):
def
__init__
(
self
,
ch_in
,
channel
):
super
(
YoloDetectionBlock
,
self
).
__init__
()
...
...
@@ -118,7 +158,7 @@ class YOLOv3(Model):
self
.
nms_posk
=
100
self
.
draw_thresh
=
0.5
self
.
backbone
=
darknet53
(
pretrained
=
False
)
self
.
backbone
=
darknet53
(
pretrained
=
(
model_mode
==
'train'
)
)
self
.
block_outputs
=
[]
self
.
yolo_blocks
=
[]
self
.
route_blocks
=
[]
...
...
@@ -254,7 +294,7 @@ def _yolov3_darknet(num_layers=53, num_classes=80,
weight_path
=
get_weights_path
(
*
(
pretrain_infos
[
num_layers
]))
assert
weight_path
.
endswith
(
'.pdparams'
),
\
"suffix of weight must be .pdparams"
model
.
load
(
weight_path
[:
-
9
]
)
model
.
load
(
weight_path
)
return
model
...
...
hapi/vision/transforms/detection_
transforms.py
→
examples/yolov3/
transforms.py
浏览文件 @
244d73a7
文件已移动
hapi/datasets/__init__.py
浏览文件 @
244d73a7
...
...
@@ -12,7 +12,14 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from
.
import
folder
from
.
import
mnist
from
.
import
flowers
from
.folder
import
*
from
.mnist
import
*
from
.flowers
import
*
from
.coco
import
*
__all__
=
folder
.
__all__
\
+
mnist
.
__all__
\
+
flowers
.
__all__
hapi/model.py
浏览文件 @
244d73a7
...
...
@@ -816,7 +816,7 @@ class Model(fluid.dygraph.Layer):
except
ValueError
as
err
:
if
skip_mismatch
:
warnings
.
warn
(
(
"Skip loading for {}. "
.
format
(
key
)
+
err
.
message
))
(
"Skip loading for {}. "
.
format
(
key
)
+
str
(
err
)
))
# reset optimizer when mismatch happens
reset_optimizer
=
True
else
:
...
...
hapi/vision/models/__init__.py
浏览文件 @
244d73a7
...
...
@@ -17,24 +17,15 @@ from . import vgg
from
.
import
mobilenetv1
from
.
import
mobilenetv2
from
.
import
darknet
from
.
import
yolov3
from
.
import
tsm
from
.
import
bmn_model
from
.resnet
import
*
from
.mobilenetv1
import
*
from
.mobilenetv2
import
*
from
.vgg
import
*
from
.darknet
import
*
from
.yolov3
import
*
from
.tsm
import
*
from
.bmn_model
import
*
__all__
=
resnet
.
__all__
\
+
vgg
.
__all__
\
+
mobilenetv1
.
__all__
\
+
mobilenetv2
.
__all__
\
+
darknet
.
__all__
\
+
yolov3
.
__all__
\
+
tsm
.
__all__
\
+
bmn_model
.
__all__
+
darknet
.
__all__
hapi/vision/models/darknet.py
浏览文件 @
244d73a7
...
...
@@ -21,7 +21,7 @@ from paddle.fluid.dygraph.nn import Conv2D, BatchNorm
from
hapi.model
import
Model
from
hapi.download
import
get_weights_path
__all__
=
[
'DarkNet'
,
'
ConvBNLayer'
,
'
darknet53'
]
__all__
=
[
'DarkNet'
,
'darknet53'
]
# {num_layers: (url, md5)}
pretrain_infos
=
{
...
...
@@ -136,7 +136,7 @@ class LayerWarp(fluid.dygraph.Layer):
DarkNet_cfg
=
{
53
:
([
1
,
2
,
8
,
8
,
4
])}
class
DarkNet
(
fluid
.
dygraph
.
Layer
):
class
DarkNet
(
Model
):
"""DarkNet model from
`"YOLOv3: An Incremental Improvement" <https://arxiv.org/abs/1804.02767>`_
...
...
hapi/vision/transforms/__init__.py
浏览文件 @
244d73a7
...
...
@@ -12,6 +12,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from
.
import
transforms
from
.
import
functional
from
.transforms
import
*
from
.functional
import
*
from
.detection_transforms
import
*
__all__
=
transforms
.
__all__
\
+
functional
.
__all__
hapi/vision/transforms/functional.py
浏览文件 @
244d73a7
...
...
@@ -26,6 +26,8 @@ else:
Sequence
=
collections
.
abc
.
Sequence
Iterable
=
collections
.
abc
.
Iterable
__all__
=
[
'flip'
,
'resize'
]
def
flip
(
image
,
code
):
"""
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录