Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
models
提交
cd4059fb
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看板
提交
cd4059fb
编写于
1月 07, 2019
作者:
Z
zhengya01
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add ce for faster_rcnn
上级
92c2da28
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
129 addition
and
1 deletion
+129
-1
fluid/PaddleCV/faster_rcnn/.run_ce.sh
fluid/PaddleCV/faster_rcnn/.run_ce.sh
+17
-0
fluid/PaddleCV/faster_rcnn/__init__.py
fluid/PaddleCV/faster_rcnn/__init__.py
+0
-0
fluid/PaddleCV/faster_rcnn/_ce.py
fluid/PaddleCV/faster_rcnn/_ce.py
+62
-0
fluid/PaddleCV/faster_rcnn/config.py
fluid/PaddleCV/faster_rcnn/config.py
+4
-0
fluid/PaddleCV/faster_rcnn/train.py
fluid/PaddleCV/faster_rcnn/train.py
+41
-1
fluid/PaddleCV/faster_rcnn/utility.py
fluid/PaddleCV/faster_rcnn/utility.py
+5
-0
未找到文件。
fluid/PaddleCV/faster_rcnn/.run_ce.sh
0 → 100755
浏览文件 @
cd4059fb
#!/bin/bash
export
MKL_NUM_THREADS
=
1
export
OMP_NUM_THREADS
=
1
cudaid
=
${
face_detection
:
=0
}
# use 0-th card as default
export
CUDA_VISIBLE_DEVICES
=
$cudaid
FLAGS_benchmark
=
true
python train.py
--model_save_dir
=
output/
--data_dir
=
dataset/coco/
--max_iter
=
20
--enable_ce
| python _ce.py
cudaid
=
${
face_detection_m
:
=0,1,2,3
}
# use 0,1,2,3 card as default
export
CUDA_VISIBLE_DEVICES
=
$cudaid
FLAGS_benchmark
=
true
python train.py
--model_save_dir
=
output/
--data_dir
=
dataset/coco/
--max_iter
=
20
--enable_ce
| python _ce.py
fluid/PaddleCV/faster_rcnn/__init__.py
0 → 100644
浏览文件 @
cd4059fb
fluid/PaddleCV/faster_rcnn/_ce.py
0 → 100644
浏览文件 @
cd4059fb
# this file is only used for continuous evaluation test!
import
os
import
sys
os
.
environ
[
'ceroot'
]
=
"./"
sys
.
path
.
append
(
os
.
environ
[
'ceroot'
])
from
kpi
import
CostKpi
from
kpi
import
DurationKpi
each_pass_duration_card1_kpi
=
DurationKpi
(
'each_pass_duration_card1'
,
0.08
,
0
,
actived
=
True
)
train_loss_card1_kpi
=
CostKpi
(
'train_loss_card1'
,
0.08
,
0
)
each_pass_duration_card4_kpi
=
DurationKpi
(
'each_pass_duration_card4'
,
0.08
,
0
,
actived
=
True
)
train_loss_card4_kpi
=
CostKpi
(
'train_loss_card4'
,
0.08
,
0
)
tracking_kpis
=
[
each_pass_duration_card1_kpi
,
train_loss_card1_kpi
,
each_pass_duration_card4_kpi
,
train_loss_card4_kpi
,
]
def
parse_log
(
log
):
'''
This method should be implemented by model developers.
The suggestion:
each line in the log should be key, value, for example:
"
train_cost
\t
1.0
test_cost
\t
1.0
train_cost
\t
1.0
train_cost
\t
1.0
train_acc
\t
1.2
"
'''
for
line
in
log
.
split
(
'
\n
'
):
fs
=
line
.
strip
().
split
(
'
\t
'
)
print
(
fs
)
if
len
(
fs
)
==
3
and
fs
[
0
]
==
'kpis'
:
kpi_name
=
fs
[
1
]
kpi_value
=
float
(
fs
[
2
])
yield
kpi_name
,
kpi_value
def
log_to_ce
(
log
):
kpi_tracker
=
{}
for
kpi
in
tracking_kpis
:
kpi_tracker
[
kpi
.
name
]
=
kpi
for
(
kpi_name
,
kpi_value
)
in
parse_log
(
log
):
print
(
kpi_name
,
kpi_value
)
kpi_tracker
[
kpi_name
].
add_record
(
kpi_value
)
kpi_tracker
[
kpi_name
].
persist
()
if
__name__
==
'__main__'
:
log
=
sys
.
stdin
.
read
()
log_to_ce
(
log
)
fluid/PaddleCV/faster_rcnn/config.py
浏览文件 @
cd4059fb
...
...
@@ -204,6 +204,10 @@ _C.pixel_means = [102.9801, 115.9465, 122.7717]
# clip box to prevent overflowing
_C
.
bbox_clip
=
np
.
log
(
1000.
/
16.
)
# ce
_C
.
enable_ce
=
False
_C
.
num_devices
=
1
# dataset path
_C
.
train_file_list
=
'annotations/instances_train2017.json'
_C
.
train_data_dir
=
'train2017'
...
...
fluid/PaddleCV/faster_rcnn/train.py
浏览文件 @
cd4059fb
...
...
@@ -35,7 +35,7 @@ def train():
learning_rate
=
cfg
.
learning_rate
image_shape
=
[
3
,
cfg
.
TRAIN
.
max_size
,
cfg
.
TRAIN
.
max_size
]
if
cfg
.
debug
:
if
cfg
.
debug
or
cfg
.
enable_ce
:
fluid
.
default_startup_program
().
random_seed
=
1000
fluid
.
default_main_program
().
random_seed
=
1000
import
random
...
...
@@ -118,6 +118,8 @@ def train():
try
:
start_time
=
time
.
time
()
prev_start_time
=
start_time
total_time
=
0
last_loss
=
0
every_pass_loss
=
[]
for
iter_id
in
range
(
cfg
.
max_iter
):
prev_start_time
=
start_time
...
...
@@ -131,9 +133,23 @@ def train():
iter_id
,
lr
[
0
],
smoothed_loss
.
get_median_value
(
),
start_time
-
prev_start_time
))
end_time
=
time
.
time
()
total_time
+=
end_time
-
start_time
last_loss
=
np
.
mean
(
np
.
array
(
losses
[
0
]))
sys
.
stdout
.
flush
()
if
(
iter_id
+
1
)
%
cfg
.
TRAIN
.
snapshot_iter
==
0
:
save_model
(
"model_iter{}"
.
format
(
iter_id
))
# only for ce
if
cfg
.
enable_ce
:
gpu_num
=
get_cards
(
cfg
)
epoch_idx
=
iter_id
+
1
loss
=
last_loss
print
(
"kpis
\t
each_pass_duration_card%s
\t
%s"
%
(
gpu_num
,
total_time
/
epoch_idx
))
print
(
"kpis
\t
train_loss_card%s
\t
%s"
%
(
gpu_num
,
loss
))
except
fluid
.
core
.
EOFException
:
py_reader
.
reset
()
return
np
.
mean
(
every_pass_loss
)
...
...
@@ -142,6 +158,8 @@ def train():
start_time
=
time
.
time
()
prev_start_time
=
start_time
start
=
start_time
total_time
=
0
last_loss
=
0
every_pass_loss
=
[]
smoothed_loss
=
SmoothedValue
(
cfg
.
log_window
)
for
iter_id
,
data
in
enumerate
(
train_reader
()):
...
...
@@ -154,6 +172,9 @@ def train():
smoothed_loss
.
add_value
(
loss_v
)
lr
=
np
.
array
(
fluid
.
global_scope
().
find_var
(
'learning_rate'
)
.
get_tensor
())
end_time
=
time
.
time
()
total_time
+=
end_time
-
start_time
last_loss
=
loss_v
print
(
"Iter {:d}, lr {:.6f}, loss {:.6f}, time {:.5f}"
.
format
(
iter_id
,
lr
[
0
],
smoothed_loss
.
get_median_value
(),
start_time
-
prev_start_time
))
...
...
@@ -162,6 +183,16 @@ def train():
save_model
(
"model_iter{}"
.
format
(
iter_id
))
if
(
iter_id
+
1
)
==
cfg
.
max_iter
:
break
# only for ce
if
cfg
.
enable_ce
:
gpu_num
=
get_cards
(
cfg
)
epoch_idx
=
iter_id
+
1
loss
=
last_loss
print
(
"kpis
\t
each_pass_duration_card%s
\t
%s"
%
(
gpu_num
,
total_time
/
epoch_idx
))
print
(
"kpis
\t
train_loss_card%s
\t
%s"
%
(
gpu_num
,
loss
))
return
np
.
mean
(
every_pass_loss
)
if
cfg
.
use_pyreader
:
...
...
@@ -171,6 +202,15 @@ def train():
save_model
(
'model_final'
)
def
get_cards
(
cfg
):
if
cfg
.
enable_ce
:
cards
=
os
.
environ
.
get
(
'CUDA_VISIBLE_DEVICES'
)
num
=
len
(
cards
.
split
(
","
))
return
num
else
:
return
cfg
.
num_devices
if
__name__
==
'__main__'
:
args
=
parse_args
()
print_arguments
(
args
)
...
...
fluid/PaddleCV/faster_rcnn/utility.py
浏览文件 @
cd4059fb
...
...
@@ -129,6 +129,11 @@ def parse_args():
add_arg
(
'draw_threshold'
,
float
,
0.8
,
"Confidence threshold to draw bbox."
)
add_arg
(
'image_path'
,
str
,
'data/COCO17/val2017'
,
"The image path used to inference and visualize."
)
add_arg
(
'image_name'
,
str
,
''
,
"The single image used to inference and visualize."
)
# ce
parser
.
add_argument
(
'--enable_ce'
,
action
=
'store_true'
,
help
=
'If set, run the task with continuous evaluation logs.'
)
parser
.
add_argument
(
'--num_devices'
,
type
=
int
,
default
=
1
,
help
=
'Number of GPU devices'
)
# yapf: enable
args
=
parser
.
parse_args
()
file_name
=
sys
.
argv
[
0
]
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录