Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
models
提交
9fb2a20e
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
9fb2a20e
编写于
1月 31, 2019
作者:
D
dengkaipeng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refine test.py and infer.py
上级
3596eca2
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
53 addition
and
62 deletion
+53
-62
fluid/PaddleCV/video/infer.py
fluid/PaddleCV/video/infer.py
+25
-30
fluid/PaddleCV/video/models/attention_cluster/attention_cluster.py
...dleCV/video/models/attention_cluster/attention_cluster.py
+1
-1
fluid/PaddleCV/video/test.py
fluid/PaddleCV/video/test.py
+17
-21
fluid/PaddleCV/video/train.py
fluid/PaddleCV/video/train.py
+10
-10
未找到文件。
fluid/PaddleCV/video/infer.py
浏览文件 @
9fb2a20e
...
...
@@ -114,41 +114,36 @@ def infer(args):
infer_feeder
=
fluid
.
DataFeeder
(
place
=
place
,
feed_list
=
infer_feeds
)
fetch_list
=
[
x
.
name
for
x
in
infer_outputs
]
def
_infer_loop
():
periods
=
[]
results
=
[]
periods
=
[]
results
=
[]
cur_time
=
time
.
time
()
for
infer_iter
,
data
in
enumerate
(
infer_reader
()):
data_feed_in
=
[
items
[:
-
1
]
for
items
in
data
]
video_id
=
[
items
[
-
1
]
for
items
in
data
]
infer_outs
=
exe
.
run
(
fetch_list
=
fetch_list
,
feed
=
infer_feeder
.
feed
(
data_feed_in
))
predictions
=
np
.
array
(
infer_outs
[
0
])
for
i
in
range
(
len
(
predictions
)):
topk_inds
=
predictions
[
i
].
argsort
()[
0
-
args
.
infer_topk
:]
topk_inds
=
topk_inds
[::
-
1
]
preds
=
predictions
[
i
][
topk_inds
]
results
.
append
(
(
video_id
[
i
],
preds
.
tolist
(),
topk_inds
.
tolist
()))
prev_time
=
cur_time
cur_time
=
time
.
time
()
for
infer_iter
,
data
in
enumerate
(
infer_reader
()):
data_feed_in
=
[
items
[:
-
1
]
for
items
in
data
]
video_id
=
[
items
[
-
1
]
for
items
in
data
]
infer_outs
=
exe
.
run
(
fetch_list
=
fetch_list
,
feed
=
infer_feeder
.
feed
(
data_feed_in
))
predictions
=
np
.
array
(
infer_outs
[
0
])
for
i
in
range
(
len
(
predictions
)):
topk_inds
=
predictions
[
i
].
argsort
()[
0
-
args
.
infer_topk
:]
topk_inds
=
topk_inds
[::
-
1
]
preds
=
predictions
[
i
][
topk_inds
]
results
.
append
(
(
video_id
[
i
],
preds
.
tolist
(),
topk_inds
.
tolist
()))
prev_time
=
cur_time
cur_time
=
time
.
time
()
period
=
cur_time
-
prev_time
periods
.
append
(
period
)
logger
.
info
(
'Processed {} samples'
.
format
((
infer_iter
)
*
len
(
predictions
)))
logger
.
info
(
'[INFER] infer finished. average time: {}'
.
format
(
np
.
mean
(
periods
)))
return
results
# start infer loop
infer_results
=
_infer_loop
()
period
=
cur_time
-
prev_time
periods
.
append
(
period
)
logger
.
info
(
'Processed {} samples'
.
format
((
infer_iter
)
*
len
(
predictions
)))
logger
.
info
(
'[INFER] infer finished. average time: {}'
.
format
(
np
.
mean
(
periods
)))
if
not
os
.
path
.
isdir
(
args
.
save_dir
):
os
.
mkdir
(
args
.
save_dir
)
result_file_name
=
os
.
path
.
join
(
args
.
save_dir
,
"{}_infer_result"
.
format
(
args
.
model_name
))
pickle
.
dump
(
infer_
results
,
open
(
result_file_name
,
'wb'
))
pickle
.
dump
(
results
,
open
(
result_file_name
,
'wb'
))
if
__name__
==
"__main__"
:
args
=
parse_args
()
...
...
fluid/PaddleCV/video/models/attention_cluster/attention_cluster.py
浏览文件 @
9fb2a20e
...
...
@@ -34,7 +34,7 @@ class AttentionCluster(ModelBase):
self
.
feature_dims
=
self
.
cfg
.
MODEL
.
feature_dims
self
.
cluster_nums
=
self
.
cfg
.
MODEL
.
cluster_nums
self
.
seg_num
=
self
.
cfg
.
MODEL
.
seg_num
self
.
class_num
=
self
.
cfg
.
MODEL
.
num_classes
#self.cfg.MODEL.class_num
self
.
class_num
=
self
.
cfg
.
MODEL
.
num_classes
self
.
drop_rate
=
self
.
cfg
.
MODEL
.
drop_rate
if
self
.
mode
==
'train'
:
...
...
fluid/PaddleCV/video/test.py
浏览文件 @
9fb2a20e
...
...
@@ -97,27 +97,23 @@ def test(args):
fetch_list
=
[
loss
.
name
]
+
[
x
.
name
for
x
in
test_outputs
]
+
[
test_feeds
[
-
1
].
name
]
def
_test_loop
():
epoch_period
=
[]
for
test_iter
,
data
in
enumerate
(
test_reader
()):
cur_time
=
time
.
time
()
test_outs
=
exe
.
run
(
fetch_list
=
fetch_list
,
feed
=
test_feeder
.
feed
(
data
))
period
=
time
.
time
()
-
cur_time
epoch_period
.
append
(
period
)
loss
=
np
.
array
(
test_outs
[
0
])
pred
=
np
.
array
(
test_outs
[
1
])
label
=
np
.
array
(
test_outs
[
-
1
])
test_metrics
.
accumulate
(
loss
,
pred
,
label
)
# metric here
if
args
.
log_interval
>
0
and
test_iter
%
args
.
log_interval
==
0
:
info_str
=
'[EVAL] Batch {}'
.
format
(
test_iter
)
test_metrics
.
calculate_and_log_out
(
loss
,
pred
,
label
,
info_str
)
test_metrics
.
finalize_and_log_out
(
"[EVAL] eval finished. "
)
# start eval loop
_test_loop
()
epoch_period
=
[]
for
test_iter
,
data
in
enumerate
(
test_reader
()):
cur_time
=
time
.
time
()
test_outs
=
exe
.
run
(
fetch_list
=
fetch_list
,
feed
=
test_feeder
.
feed
(
data
))
period
=
time
.
time
()
-
cur_time
epoch_period
.
append
(
period
)
loss
=
np
.
array
(
test_outs
[
0
])
pred
=
np
.
array
(
test_outs
[
1
])
label
=
np
.
array
(
test_outs
[
-
1
])
test_metrics
.
accumulate
(
loss
,
pred
,
label
)
# metric here
if
args
.
log_interval
>
0
and
test_iter
%
args
.
log_interval
==
0
:
info_str
=
'[EVAL] Batch {}'
.
format
(
test_iter
)
test_metrics
.
calculate_and_log_out
(
loss
,
pred
,
label
,
info_str
)
test_metrics
.
finalize_and_log_out
(
"[EVAL] eval finished. "
)
if
__name__
==
"__main__"
:
...
...
fluid/PaddleCV/video/train.py
浏览文件 @
9fb2a20e
...
...
@@ -188,20 +188,20 @@ def train(args):
if
args
.
no_use_pyreader
:
train_feeder
=
fluid
.
DataFeeder
(
place
=
place
,
feed_list
=
train_feeds
)
valid_feeder
=
fluid
.
DataFeeder
(
place
=
place
,
feed_list
=
valid_feeds
)
train_without_pyreader
(
exe
,
train_prog
,
train_exe
,
train_reader
,
train_feeder
,
\
train_fetch_list
,
train_metrics
,
epochs
=
epochs
,
\
log_interval
=
args
.
log_interval
,
valid_interval
=
args
.
valid_interval
,
\
save_dir
=
args
.
save_dir
,
save_model_name
=
args
.
model_name
,
\
test_exe
=
valid_exe
,
test_reader
=
valid_reader
,
test_feeder
=
valid_feeder
,
\
train_without_pyreader
(
exe
,
train_prog
,
train_exe
,
train_reader
,
train_feeder
,
train_fetch_list
,
train_metrics
,
epochs
=
epochs
,
log_interval
=
args
.
log_interval
,
valid_interval
=
args
.
valid_interval
,
save_dir
=
args
.
save_dir
,
save_model_name
=
args
.
model_name
,
test_exe
=
valid_exe
,
test_reader
=
valid_reader
,
test_feeder
=
valid_feeder
,
test_fetch_list
=
valid_fetch_list
,
test_metrics
=
valid_metrics
)
else
:
train_pyreader
.
decorate_paddle_reader
(
train_reader
)
valid_pyreader
.
decorate_paddle_reader
(
valid_reader
)
train_with_pyreader
(
exe
,
train_prog
,
train_exe
,
train_pyreader
,
train_fetch_list
,
train_metrics
,
\
epochs
=
epochs
,
log_interval
=
args
.
log_interval
,
\
valid_interval
=
args
.
valid_interval
,
\
save_dir
=
args
.
save_dir
,
save_model_name
=
args
.
model_name
,
\
test_exe
=
valid_exe
,
test_pyreader
=
valid_pyreader
,
\
train_with_pyreader
(
exe
,
train_prog
,
train_exe
,
train_pyreader
,
train_fetch_list
,
train_metrics
,
epochs
=
epochs
,
log_interval
=
args
.
log_interval
,
valid_interval
=
args
.
valid_interval
,
save_dir
=
args
.
save_dir
,
save_model_name
=
args
.
model_name
,
test_exe
=
valid_exe
,
test_pyreader
=
valid_pyreader
,
test_fetch_list
=
valid_fetch_list
,
test_metrics
=
valid_metrics
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录