Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
models
提交
82ac38e3
M
models
项目概览
PaddlePaddle
/
models
大约 1 年 前同步成功
通知
222
Star
6828
Fork
2962
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
602
列表
看板
标记
里程碑
合并请求
255
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
models
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
602
Issue
602
列表
看板
标记
里程碑
合并请求
255
合并请求
255
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
82ac38e3
编写于
8月 15, 2018
作者:
B
Bai Yifan
提交者:
GitHub
8月 15, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refine eval.py and update pyramidbox parameter init method (#1091)
* refine eval and update pyramidbox parameter init
上级
53fbde83
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
63 addition
and
41 deletion
+63
-41
fluid/face_detection/pyramidbox.py
fluid/face_detection/pyramidbox.py
+10
-5
fluid/face_detection/train.py
fluid/face_detection/train.py
+2
-2
fluid/face_detection/widerface_eval.py
fluid/face_detection/widerface_eval.py
+51
-34
未找到文件。
fluid/face_detection/pyramidbox.py
浏览文件 @
82ac38e3
...
...
@@ -145,7 +145,6 @@ class PyramidBox(object):
upsampling
=
fluid
.
layers
.
resize_bilinear
(
conv1
,
out_shape
=
up_to
.
shape
[
2
:])
b_attr
=
ParamAttr
(
learning_rate
=
2.
,
regularizer
=
L2Decay
(
0.
))
conv2
=
fluid
.
layers
.
conv2d
(
up_to
,
ch
,
1
,
act
=
'relu'
,
bias_attr
=
b_attr
)
if
self
.
is_infer
:
...
...
@@ -220,10 +219,13 @@ class PyramidBox(object):
def
permute_and_reshape
(
input
,
last_dim
):
trans
=
fluid
.
layers
.
transpose
(
input
,
perm
=
[
0
,
2
,
3
,
1
])
new
_shape
=
[
compile
_shape
=
[
trans
.
shape
[
0
],
np
.
prod
(
trans
.
shape
[
1
:])
/
last_dim
,
last_dim
]
return
fluid
.
layers
.
reshape
(
trans
,
shape
=
new_shape
)
run_shape
=
fluid
.
layers
.
assign
(
np
.
array
([
0
,
-
1
,
last_dim
]).
astype
(
"int32"
))
return
fluid
.
layers
.
reshape
(
trans
,
shape
=
compile_shape
,
actual_shape
=
run_shape
)
face_locs
,
face_confs
=
[],
[]
head_locs
,
head_confs
=
[],
[]
...
...
@@ -288,10 +290,13 @@ class PyramidBox(object):
def
permute_and_reshape
(
input
,
last_dim
):
trans
=
fluid
.
layers
.
transpose
(
input
,
perm
=
[
0
,
2
,
3
,
1
])
new
_shape
=
[
compile
_shape
=
[
trans
.
shape
[
0
],
np
.
prod
(
trans
.
shape
[
1
:])
/
last_dim
,
last_dim
]
return
fluid
.
layers
.
reshape
(
trans
,
shape
=
new_shape
)
run_shape
=
fluid
.
layers
.
assign
(
np
.
array
([
0
,
-
1
,
last_dim
]).
astype
(
"int32"
))
return
fluid
.
layers
.
reshape
(
trans
,
shape
=
compile_shape
,
actual_shape
=
run_shape
)
locs
,
confs
=
[],
[]
boxes
,
vars
=
[],
[]
...
...
fluid/face_detection/train.py
浏览文件 @
82ac38e3
...
...
@@ -16,14 +16,14 @@ add_arg = functools.partial(add_arguments, argparser=parser)
# yapf: disable
add_arg
(
'parallel'
,
bool
,
True
,
"Whether use multi-GPU/threads or not."
)
add_arg
(
'learning_rate'
,
float
,
0.001
,
"The start learning rate."
)
add_arg
(
'batch_size'
,
int
,
1
2
,
"Minibatch size."
)
add_arg
(
'batch_size'
,
int
,
1
6
,
"Minibatch size."
)
add_arg
(
'num_passes'
,
int
,
160
,
"Epoch number."
)
add_arg
(
'use_gpu'
,
bool
,
True
,
"Whether use GPU."
)
add_arg
(
'use_pyramidbox'
,
bool
,
True
,
"Whether use PyramidBox model."
)
add_arg
(
'model_save_dir'
,
str
,
'output'
,
"The path to save model."
)
add_arg
(
'resize_h'
,
int
,
640
,
"The resized image height."
)
add_arg
(
'resize_w'
,
int
,
640
,
"The resized image width."
)
add_arg
(
'with_mem_opt'
,
bool
,
Fals
e
,
"Whether to use memory optimization or not."
)
add_arg
(
'with_mem_opt'
,
bool
,
Tru
e
,
"Whether to use memory optimization or not."
)
add_arg
(
'pretrained_model'
,
str
,
'./vgg_ilsvrc_16_fc_reduced/'
,
"The init model path."
)
#yapf: enable
...
...
fluid/face_detection/widerface_eval.py
浏览文件 @
82ac38e3
...
...
@@ -8,6 +8,7 @@ from PIL import Image
import
paddle.fluid
as
fluid
import
reader
from
pyramidbox
import
PyramidBox
from
visualize
import
draw_bboxes
from
utility
import
add_arguments
,
print_arguments
parser
=
argparse
.
ArgumentParser
(
description
=
__doc__
)
add_arg
=
functools
.
partial
(
add_arguments
,
argparser
=
parser
)
...
...
@@ -19,21 +20,37 @@ add_arg('data_dir', str, 'data/WIDER_val/images/', "The validati
add_arg
(
'model_dir'
,
str
,
''
,
"The model path."
)
add_arg
(
'pred_dir'
,
str
,
'pred'
,
"The path to save the evaluation results."
)
add_arg
(
'file_list'
,
str
,
'data/wider_face_split/wider_face_val_bbx_gt.txt'
,
"The validation dataset path."
)
add_arg
(
'infer'
,
bool
,
False
,
"Whether do infer or eval."
)
add_arg
(
'confs_threshold'
,
float
,
0.15
,
"Confidence threshold to draw bbox."
)
add_arg
(
'image_path'
,
str
,
''
,
"The image used to inference and visualize."
)
# yapf: enable
def
infer
(
args
,
config
):
batch_size
=
1
model_dir
=
args
.
model_dir
data_dir
=
args
.
data_dir
file_list
=
args
.
file_list
pred_dir
=
args
.
pred_dir
if
not
os
.
path
.
exists
(
model_dir
):
raise
ValueError
(
"The model path [%s] does not exist."
%
(
model_dir
))
test_reader
=
reader
.
test
(
config
,
file_list
)
if
args
.
infer
:
image_path
=
args
.
image_path
image
=
Image
.
open
(
image_path
)
if
image
.
mode
==
'L'
:
image
=
img
.
convert
(
'RGB'
)
shrink
,
max_shrink
=
get_shrink
(
image
.
size
[
1
],
image
.
size
[
0
])
det0
=
detect_face
(
image
,
shrink
)
det1
=
flip_test
(
image
,
shrink
)
[
det2
,
det3
]
=
multi_scale_test
(
image
,
max_shrink
)
det4
=
multi_scale_test_pyramid
(
image
,
max_shrink
)
det
=
np
.
row_stack
((
det0
,
det1
,
det2
,
det3
,
det4
))
dets
=
bbox_vote
(
det
)
keep_index
=
np
.
where
(
dets
[:,
4
]
>=
args
.
confs_threshold
)[
0
]
dets
=
dets
[
keep_index
,
:]
draw_bboxes
(
image_path
,
dets
[:,
0
:
4
])
else
:
test_reader
=
reader
.
test
(
config
,
args
.
file_list
)
for
image
,
image_path
in
test_reader
():
shrink
,
max_shrink
=
get_shrink
(
image
.
size
[
1
],
image
.
size
[
0
])
...
...
@@ -97,20 +114,6 @@ def detect_face(image, shrink):
img
=
[
img
]
img
=
np
.
array
(
img
)
place
=
fluid
.
CUDAPlace
(
0
)
if
args
.
use_gpu
else
fluid
.
CPUPlace
()
exe
=
fluid
.
Executor
(
place
)
main_program
=
fluid
.
Program
()
startup_program
=
fluid
.
Program
()
with
fluid
.
unique_name
.
guard
():
with
fluid
.
program_guard
(
main_program
,
startup_program
):
network
=
PyramidBox
(
image_shape
,
sub_network
=
args
.
use_pyramidbox
,
is_infer
=
True
)
infer_program
,
nmsed_out
=
network
.
infer
(
main_program
)
fetches
=
[
nmsed_out
]
fluid
.
io
.
load_persistables
(
exe
,
args
.
model_dir
,
main_program
=
main_program
)
detection
,
=
exe
.
run
(
infer_program
,
feed
=
{
'image'
:
img
},
fetch_list
=
fetches
,
...
...
@@ -290,4 +293,18 @@ if __name__ == '__main__':
args
=
parser
.
parse_args
()
print_arguments
(
args
)
config
=
reader
.
Settings
(
data_dir
=
args
.
data_dir
)
place
=
fluid
.
CUDAPlace
(
0
)
if
args
.
use_gpu
else
fluid
.
CPUPlace
()
exe
=
fluid
.
Executor
(
place
)
main_program
=
fluid
.
Program
()
startup_program
=
fluid
.
Program
()
image_shape
=
[
3
,
1024
,
1024
]
with
fluid
.
program_guard
(
main_program
,
startup_program
):
network
=
PyramidBox
(
image_shape
,
sub_network
=
args
.
use_pyramidbox
,
is_infer
=
True
)
infer_program
,
nmsed_out
=
network
.
infer
(
main_program
)
fetches
=
[
nmsed_out
]
fluid
.
io
.
load_persistables
(
exe
,
args
.
model_dir
,
main_program
=
main_program
)
infer
(
args
,
config
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录