Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
s920243400
PaddleDetection
提交
89b98703
P
PaddleDetection
项目概览
s920243400
/
PaddleDetection
与 Fork 源项目一致
Fork自
PaddlePaddle / PaddleDetection
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleDetection
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
89b98703
编写于
10月 12, 2019
作者:
W
wangguanzhong
提交者:
GitHub
10月 12, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
unify reader to dataloader (#3487)
* unify reader to dataloader * add check_version
上级
709b706d
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
49 addition
and
31 deletion
+49
-31
ppdet/modeling/model_input.py
ppdet/modeling/model_input.py
+7
-9
ppdet/utils/check.py
ppdet/utils/check.py
+16
-2
ppdet/utils/eval_utils.py
ppdet/utils/eval_utils.py
+3
-3
tools/eval.py
tools/eval.py
+6
-4
tools/infer.py
tools/infer.py
+7
-5
tools/train.py
tools/train.py
+10
-8
未找到文件。
ppdet/modeling/model_input.py
浏览文件 @
89b98703
...
@@ -38,7 +38,7 @@ feed_var_def = [
...
@@ -38,7 +38,7 @@ feed_var_def = [
# yapf: enable
# yapf: enable
def
create_feed
(
feed
,
use_pyreader
=
Tru
e
):
def
create_feed
(
feed
,
iterable
=
Fals
e
):
image_shape
=
feed
.
image_shape
image_shape
=
feed
.
image_shape
feed_var_map
=
{
var
[
'name'
]:
var
for
var
in
feed_var_def
}
feed_var_map
=
{
var
[
'name'
]:
var
for
var
in
feed_var_def
}
feed_var_map
[
'image'
]
=
{
feed_var_map
[
'image'
]
=
{
...
@@ -66,11 +66,9 @@ def create_feed(feed, use_pyreader=True):
...
@@ -66,11 +66,9 @@ def create_feed(feed, use_pyreader=True):
dtype
=
feed_var_map
[
key
][
'dtype'
],
dtype
=
feed_var_map
[
key
][
'dtype'
],
lod_level
=
feed_var_map
[
key
][
'lod_level'
]))
for
key
in
feed
.
fields
])
lod_level
=
feed_var_map
[
key
][
'lod_level'
]))
for
key
in
feed
.
fields
])
pyreader
=
None
loader
=
fluid
.
io
.
DataLoader
.
from_generator
(
if
use_pyreader
:
feed_list
=
list
(
feed_vars
.
values
()),
pyreader
=
fluid
.
io
.
PyReader
(
capacity
=
64
,
feed_list
=
list
(
feed_vars
.
values
()),
use_double_buffer
=
True
,
capacity
=
64
,
iterable
=
iterable
)
use_double_buffer
=
True
,
return
loader
,
feed_vars
iterable
=
False
)
return
pyreader
,
feed_vars
ppdet/utils/check.py
浏览文件 @
89b98703
...
@@ -15,7 +15,6 @@
...
@@ -15,7 +15,6 @@
from
__future__
import
absolute_import
from
__future__
import
absolute_import
from
__future__
import
division
from
__future__
import
division
from
__future__
import
print_function
from
__future__
import
print_function
from
__future__
import
unicode_literals
import
sys
import
sys
...
@@ -24,7 +23,7 @@ import paddle.fluid as fluid
...
@@ -24,7 +23,7 @@ import paddle.fluid as fluid
import
logging
import
logging
logger
=
logging
.
getLogger
(
__name__
)
logger
=
logging
.
getLogger
(
__name__
)
__all__
=
[
'check_gpu'
]
__all__
=
[
'check_gpu'
,
'check_version'
]
def
check_gpu
(
use_gpu
):
def
check_gpu
(
use_gpu
):
...
@@ -45,3 +44,18 @@ def check_gpu(use_gpu):
...
@@ -45,3 +44,18 @@ def check_gpu(use_gpu):
except
Exception
as
e
:
except
Exception
as
e
:
pass
pass
def
check_version
():
"""
Log error and exit when the installed version of paddlepaddle is
not satisfied.
"""
err
=
"PaddlePaddle version 1.6 or higher is required, "
\
"or a suitable develop version is satisfied as well.
\n
"
\
"Please make sure the version is good with your code."
\
try
:
fluid
.
require_version
(
'1.6.0'
)
except
Exception
as
e
:
logger
.
error
(
err
)
sys
.
exit
(
1
)
ppdet/utils/eval_utils.py
浏览文件 @
89b98703
...
@@ -57,7 +57,7 @@ def parse_fetches(fetches, prog=None, extra_keys=None):
...
@@ -57,7 +57,7 @@ def parse_fetches(fetches, prog=None, extra_keys=None):
return
keys
,
values
,
cls
return
keys
,
values
,
cls
def
eval_run
(
exe
,
compile_program
,
pyre
ader
,
keys
,
values
,
cls
):
def
eval_run
(
exe
,
compile_program
,
lo
ader
,
keys
,
values
,
cls
):
"""
"""
Run evaluation program, return program outputs.
Run evaluation program, return program outputs.
"""
"""
...
@@ -75,7 +75,7 @@ def eval_run(exe, compile_program, pyreader, keys, values, cls):
...
@@ -75,7 +75,7 @@ def eval_run(exe, compile_program, pyreader, keys, values, cls):
has_bbox
=
'bbox'
in
keys
has_bbox
=
'bbox'
in
keys
try
:
try
:
pyre
ader
.
start
()
lo
ader
.
start
()
while
True
:
while
True
:
outs
=
exe
.
run
(
compile_program
,
outs
=
exe
.
run
(
compile_program
,
fetch_list
=
values
,
fetch_list
=
values
,
...
@@ -90,7 +90,7 @@ def eval_run(exe, compile_program, pyreader, keys, values, cls):
...
@@ -90,7 +90,7 @@ def eval_run(exe, compile_program, pyreader, keys, values, cls):
iter_id
+=
1
iter_id
+=
1
images_num
+=
len
(
res
[
'bbox'
][
1
][
0
])
if
has_bbox
else
1
images_num
+=
len
(
res
[
'bbox'
][
1
][
0
])
if
has_bbox
else
1
except
(
StopIteration
,
fluid
.
core
.
EOFException
):
except
(
StopIteration
,
fluid
.
core
.
EOFException
):
pyre
ader
.
reset
()
lo
ader
.
reset
()
logger
.
info
(
'Test finish iter {}'
.
format
(
iter_id
))
logger
.
info
(
'Test finish iter {}'
.
format
(
iter_id
))
end_time
=
time
.
time
()
end_time
=
time
.
time
()
...
...
tools/eval.py
浏览文件 @
89b98703
...
@@ -35,7 +35,7 @@ import paddle.fluid as fluid
...
@@ -35,7 +35,7 @@ import paddle.fluid as fluid
from
ppdet.utils.eval_utils
import
parse_fetches
,
eval_run
,
eval_results
,
json_eval_results
from
ppdet.utils.eval_utils
import
parse_fetches
,
eval_run
,
eval_results
,
json_eval_results
import
ppdet.utils.checkpoint
as
checkpoint
import
ppdet.utils.checkpoint
as
checkpoint
from
ppdet.utils.check
import
check_gpu
from
ppdet.utils.check
import
check_gpu
,
check_version
from
ppdet.modeling.model_input
import
create_feed
from
ppdet.modeling.model_input
import
create_feed
from
ppdet.data.data_feed
import
create_reader
from
ppdet.data.data_feed
import
create_reader
from
ppdet.core.workspace
import
load_config
,
merge_config
,
create
from
ppdet.core.workspace
import
load_config
,
merge_config
,
create
...
@@ -62,6 +62,8 @@ def main():
...
@@ -62,6 +62,8 @@ def main():
# check if set use_gpu=True in paddlepaddle cpu version
# check if set use_gpu=True in paddlepaddle cpu version
check_gpu
(
cfg
.
use_gpu
)
check_gpu
(
cfg
.
use_gpu
)
# check if paddlepaddle version is satisfied
check_version
()
print_total_cfg
(
cfg
)
print_total_cfg
(
cfg
)
if
'eval_feed'
not
in
cfg
:
if
'eval_feed'
not
in
cfg
:
...
@@ -79,12 +81,12 @@ def main():
...
@@ -79,12 +81,12 @@ def main():
eval_prog
=
fluid
.
Program
()
eval_prog
=
fluid
.
Program
()
with
fluid
.
program_guard
(
eval_prog
,
startup_prog
):
with
fluid
.
program_guard
(
eval_prog
,
startup_prog
):
with
fluid
.
unique_name
.
guard
():
with
fluid
.
unique_name
.
guard
():
pyre
ader
,
feed_vars
=
create_feed
(
eval_feed
)
lo
ader
,
feed_vars
=
create_feed
(
eval_feed
)
fetches
=
model
.
eval
(
feed_vars
)
fetches
=
model
.
eval
(
feed_vars
)
eval_prog
=
eval_prog
.
clone
(
True
)
eval_prog
=
eval_prog
.
clone
(
True
)
reader
=
create_reader
(
eval_feed
,
args_path
=
FLAGS
.
dataset_dir
)
reader
=
create_reader
(
eval_feed
,
args_path
=
FLAGS
.
dataset_dir
)
pyreader
.
decorate
_sample_list_generator
(
reader
,
place
)
loader
.
set
_sample_list_generator
(
reader
,
place
)
# eval already exists json file
# eval already exists json file
if
FLAGS
.
json_eval
:
if
FLAGS
.
json_eval
:
...
@@ -120,7 +122,7 @@ def main():
...
@@ -120,7 +122,7 @@ def main():
callable
(
model
.
is_bbox_normalized
):
callable
(
model
.
is_bbox_normalized
):
is_bbox_normalized
=
model
.
is_bbox_normalized
()
is_bbox_normalized
=
model
.
is_bbox_normalized
()
results
=
eval_run
(
exe
,
compile_program
,
pyre
ader
,
keys
,
values
,
cls
)
results
=
eval_run
(
exe
,
compile_program
,
lo
ader
,
keys
,
values
,
cls
)
# evaluation
# evaluation
resolution
=
None
resolution
=
None
...
...
tools/infer.py
浏览文件 @
89b98703
...
@@ -44,7 +44,7 @@ from ppdet.data.data_feed import create_reader
...
@@ -44,7 +44,7 @@ from ppdet.data.data_feed import create_reader
from
ppdet.utils.eval_utils
import
parse_fetches
from
ppdet.utils.eval_utils
import
parse_fetches
from
ppdet.utils.cli
import
ArgsParser
from
ppdet.utils.cli
import
ArgsParser
from
ppdet.utils.check
import
check_gpu
from
ppdet.utils.check
import
check_gpu
,
check_version
from
ppdet.utils.visualizer
import
visualize_results
from
ppdet.utils.visualizer
import
visualize_results
import
ppdet.utils.checkpoint
as
checkpoint
import
ppdet.utils.checkpoint
as
checkpoint
...
@@ -150,6 +150,8 @@ def main():
...
@@ -150,6 +150,8 @@ def main():
# check if set use_gpu=True in paddlepaddle cpu version
# check if set use_gpu=True in paddlepaddle cpu version
check_gpu
(
cfg
.
use_gpu
)
check_gpu
(
cfg
.
use_gpu
)
# check if paddlepaddle version is satisfied
check_version
()
print_total_cfg
(
cfg
)
print_total_cfg
(
cfg
)
if
'test_feed'
not
in
cfg
:
if
'test_feed'
not
in
cfg
:
...
@@ -169,12 +171,12 @@ def main():
...
@@ -169,12 +171,12 @@ def main():
infer_prog
=
fluid
.
Program
()
infer_prog
=
fluid
.
Program
()
with
fluid
.
program_guard
(
infer_prog
,
startup_prog
):
with
fluid
.
program_guard
(
infer_prog
,
startup_prog
):
with
fluid
.
unique_name
.
guard
():
with
fluid
.
unique_name
.
guard
():
_
,
feed_vars
=
create_feed
(
test_feed
,
use_pyreader
=
Fals
e
)
loader
,
feed_vars
=
create_feed
(
test_feed
,
iterable
=
Tru
e
)
test_fetches
=
model
.
test
(
feed_vars
)
test_fetches
=
model
.
test
(
feed_vars
)
infer_prog
=
infer_prog
.
clone
(
True
)
infer_prog
=
infer_prog
.
clone
(
True
)
reader
=
create_reader
(
test_feed
)
reader
=
create_reader
(
test_feed
)
feeder
=
fluid
.
DataFeeder
(
place
=
place
,
feed_list
=
feed_vars
.
values
()
)
loader
.
set_sample_list_generator
(
reader
,
place
)
exe
.
run
(
startup_prog
)
exe
.
run
(
startup_prog
)
if
cfg
.
weights
:
if
cfg
.
weights
:
...
@@ -219,9 +221,9 @@ def main():
...
@@ -219,9 +221,9 @@ def main():
tb_image_frame
=
0
# each frame can display ten pictures at most.
tb_image_frame
=
0
# each frame can display ten pictures at most.
imid2path
=
reader
.
imid2path
imid2path
=
reader
.
imid2path
for
iter_id
,
data
in
enumerate
(
re
ader
()):
for
iter_id
,
data
in
enumerate
(
lo
ader
()):
outs
=
exe
.
run
(
infer_prog
,
outs
=
exe
.
run
(
infer_prog
,
feed
=
feeder
.
feed
(
data
)
,
feed
=
data
,
fetch_list
=
values
,
fetch_list
=
values
,
return_numpy
=
False
)
return_numpy
=
False
)
res
=
{
res
=
{
...
...
tools/train.py
浏览文件 @
89b98703
...
@@ -46,7 +46,7 @@ from ppdet.utils import dist_utils
...
@@ -46,7 +46,7 @@ from ppdet.utils import dist_utils
from
ppdet.utils.eval_utils
import
parse_fetches
,
eval_run
,
eval_results
from
ppdet.utils.eval_utils
import
parse_fetches
,
eval_run
,
eval_results
from
ppdet.utils.stats
import
TrainingStats
from
ppdet.utils.stats
import
TrainingStats
from
ppdet.utils.cli
import
ArgsParser
from
ppdet.utils.cli
import
ArgsParser
from
ppdet.utils.check
import
check_gpu
from
ppdet.utils.check
import
check_gpu
,
check_version
import
ppdet.utils.checkpoint
as
checkpoint
import
ppdet.utils.checkpoint
as
checkpoint
from
ppdet.modeling.model_input
import
create_feed
from
ppdet.modeling.model_input
import
create_feed
...
@@ -81,6 +81,8 @@ def main():
...
@@ -81,6 +81,8 @@ def main():
# check if set use_gpu=True in paddlepaddle cpu version
# check if set use_gpu=True in paddlepaddle cpu version
check_gpu
(
cfg
.
use_gpu
)
check_gpu
(
cfg
.
use_gpu
)
# check if paddlepaddle version is satisfied
check_version
()
if
not
FLAGS
.
dist
or
trainer_id
==
0
:
if
not
FLAGS
.
dist
or
trainer_id
==
0
:
print_total_cfg
(
cfg
)
print_total_cfg
(
cfg
)
...
@@ -116,7 +118,7 @@ def main():
...
@@ -116,7 +118,7 @@ def main():
with
fluid
.
program_guard
(
train_prog
,
startup_prog
):
with
fluid
.
program_guard
(
train_prog
,
startup_prog
):
with
fluid
.
unique_name
.
guard
():
with
fluid
.
unique_name
.
guard
():
model
=
create
(
main_arch
)
model
=
create
(
main_arch
)
train_
pyre
ader
,
feed_vars
=
create_feed
(
train_feed
)
train_
lo
ader
,
feed_vars
=
create_feed
(
train_feed
)
with
mixed_precision_context
(
FLAGS
.
loss_scale
,
FLAGS
.
fp16
)
as
ctx
:
with
mixed_precision_context
(
FLAGS
.
loss_scale
,
FLAGS
.
fp16
)
as
ctx
:
train_fetches
=
model
.
train
(
feed_vars
)
train_fetches
=
model
.
train
(
feed_vars
)
...
@@ -139,12 +141,12 @@ def main():
...
@@ -139,12 +141,12 @@ def main():
with
fluid
.
program_guard
(
eval_prog
,
startup_prog
):
with
fluid
.
program_guard
(
eval_prog
,
startup_prog
):
with
fluid
.
unique_name
.
guard
():
with
fluid
.
unique_name
.
guard
():
model
=
create
(
main_arch
)
model
=
create
(
main_arch
)
eval_
pyre
ader
,
feed_vars
=
create_feed
(
eval_feed
)
eval_
lo
ader
,
feed_vars
=
create_feed
(
eval_feed
)
fetches
=
model
.
eval
(
feed_vars
)
fetches
=
model
.
eval
(
feed_vars
)
eval_prog
=
eval_prog
.
clone
(
True
)
eval_prog
=
eval_prog
.
clone
(
True
)
eval_reader
=
create_reader
(
eval_feed
,
args_path
=
FLAGS
.
dataset_dir
)
eval_reader
=
create_reader
(
eval_feed
,
args_path
=
FLAGS
.
dataset_dir
)
eval_
pyreader
.
decorate
_sample_list_generator
(
eval_reader
,
place
)
eval_
loader
.
set
_sample_list_generator
(
eval_reader
,
place
)
# parse eval fetches
# parse eval fetches
extra_keys
=
[]
extra_keys
=
[]
...
@@ -197,7 +199,7 @@ def main():
...
@@ -197,7 +199,7 @@ def main():
train_reader
=
create_reader
(
train_feed
,
(
cfg
.
max_iters
-
start_iter
)
*
train_reader
=
create_reader
(
train_feed
,
(
cfg
.
max_iters
-
start_iter
)
*
devices_num
,
FLAGS
.
dataset_dir
)
devices_num
,
FLAGS
.
dataset_dir
)
train_
pyreader
.
decorate
_sample_list_generator
(
train_reader
,
place
)
train_
loader
.
set
_sample_list_generator
(
train_reader
,
place
)
# whether output bbox is normalized in model output layer
# whether output bbox is normalized in model output layer
is_bbox_normalized
=
False
is_bbox_normalized
=
False
...
@@ -209,7 +211,7 @@ def main():
...
@@ -209,7 +211,7 @@ def main():
map_type
=
cfg
.
map_type
if
'map_type'
in
cfg
else
'11point'
map_type
=
cfg
.
map_type
if
'map_type'
in
cfg
else
'11point'
train_stats
=
TrainingStats
(
cfg
.
log_smooth_window
,
train_keys
)
train_stats
=
TrainingStats
(
cfg
.
log_smooth_window
,
train_keys
)
train_
pyre
ader
.
start
()
train_
lo
ader
.
start
()
start_time
=
time
.
time
()
start_time
=
time
.
time
()
end_time
=
time
.
time
()
end_time
=
time
.
time
()
...
@@ -256,7 +258,7 @@ def main():
...
@@ -256,7 +258,7 @@ def main():
if
FLAGS
.
eval
:
if
FLAGS
.
eval
:
# evaluation
# evaluation
results
=
eval_run
(
exe
,
compiled_eval_prog
,
eval_
pyre
ader
,
results
=
eval_run
(
exe
,
compiled_eval_prog
,
eval_
lo
ader
,
eval_keys
,
eval_values
,
eval_cls
)
eval_keys
,
eval_values
,
eval_cls
)
resolution
=
None
resolution
=
None
if
'mask'
in
results
[
0
]:
if
'mask'
in
results
[
0
]:
...
@@ -278,7 +280,7 @@ def main():
...
@@ -278,7 +280,7 @@ def main():
logger
.
info
(
"Best test box ap: {}, in iter: {}"
.
format
(
logger
.
info
(
"Best test box ap: {}, in iter: {}"
.
format
(
best_box_ap_list
[
0
],
best_box_ap_list
[
1
]))
best_box_ap_list
[
0
],
best_box_ap_list
[
1
]))
train_
pyre
ader
.
reset
()
train_
lo
ader
.
reset
()
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录