Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
models
提交
e7442964
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看板
提交
e7442964
编写于
2月 07, 2018
作者:
Y
yangyaming
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Avoid suppressing critical exception.
上级
2738ca10
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
60 addition
and
30 deletion
+60
-30
fluid/DeepASR/data_utils/data_reader.py
fluid/DeepASR/data_utils/data_reader.py
+37
-26
fluid/DeepASR/data_utils/util.py
fluid/DeepASR/data_utils/util.py
+23
-4
未找到文件。
fluid/DeepASR/data_utils/data_reader.py
浏览文件 @
e7442964
...
...
@@ -15,6 +15,7 @@ from multiprocessing import Manager, Process
import
data_utils.augmentor.trans_mean_variance_norm
as
trans_mean_variance_norm
import
data_utils.augmentor.trans_add_delta
as
trans_add_delta
from
data_utils.util
import
suppress_complaints
,
suppress_signal
from
data_utils.util
import
CriticalException
,
ForceExitWrapper
class
SampleInfo
(
object
):
...
...
@@ -166,6 +167,7 @@ class DataReader(object):
self
.
_batch_buffer_size
=
batch_buffer_size
self
.
_process_num
=
process_num
self
.
_verbose
=
verbose
self
.
_force_exit
=
ForceExitWrapper
(
self
.
_manager
.
Value
(
'b'
,
False
))
def
generate_bucket_list
(
self
,
is_shuffle
):
if
self
.
_block_info_list
is
None
:
...
...
@@ -204,15 +206,19 @@ class DataReader(object):
sample_queue
=
self
.
_manager
.
Queue
(
self
.
_sample_buffer_size
)
self
.
_order_id
=
0
@
suppress_complaints
(
verbose
=
self
.
_verbose
)
@
suppress_complaints
(
verbose
=
self
.
_verbose
,
notify
=
self
.
_force_exit
)
def
ordered_feeding_task
(
sample_info_queue
):
for
sample_info_bucket
in
self
.
_bucket_list
:
sample_info_list
=
sample_info_bucket
.
generate_sample_info_list
(
)
self
.
_rng
.
shuffle
(
sample_info_list
)
# do shuffle here
for
sample_info
in
sample_info_list
:
sample_info_queue
.
put
((
sample_info
,
self
.
_order_id
))
self
.
_order_id
+=
1
try
:
sample_info_list
=
\
sample_info_bucket
.
generate_sample_info_list
()
except
Exception
as
e
:
raise
CriticalException
(
e
)
else
:
self
.
_rng
.
shuffle
(
sample_info_list
)
# do shuffle here
for
sample_info
in
sample_info_list
:
sample_info_queue
.
put
((
sample_info
,
self
.
_order_id
))
self
.
_order_id
+=
1
for
i
in
xrange
(
self
.
_process_num
):
sample_info_queue
.
put
(
EpochEndSignal
())
...
...
@@ -222,18 +228,21 @@ class DataReader(object):
feeding_thread
.
daemon
=
True
feeding_thread
.
start
()
@
suppress_complaints
(
verbose
=
self
.
_verbose
)
@
suppress_complaints
(
verbose
=
self
.
_verbose
,
notify
=
self
.
_force_exit
)
def
ordered_processing_task
(
sample_info_queue
,
sample_queue
,
out_order
):
if
self
.
_verbose
==
0
:
signal
.
signal
(
signal
.
SIGTERM
,
suppress_signal
)
signal
.
signal
(
signal
.
SIGINT
,
suppress_signal
)
def
read_bytes
(
fpath
,
start
,
size
):
f
=
open
(
fpath
,
'r'
)
f
.
seek
(
start
,
0
)
binary_bytes
=
f
.
read
(
size
)
f
.
close
()
return
binary_bytes
try
:
f
=
open
(
fpath
,
'r'
)
f
.
seek
(
start
,
0
)
binary_bytes
=
f
.
read
(
size
)
f
.
close
()
return
binary_bytes
except
Exception
as
e
:
raise
CriticalException
(
e
)
ins
=
sample_info_queue
.
get
()
...
...
@@ -295,16 +304,20 @@ class DataReader(object):
finished_process_num
=
0
while
finished_process_num
<
self
.
_process_num
:
sample
=
sample_queue
.
get
()
if
isinstance
(
sample
,
EpochEndSignal
):
finished_process_num
+=
1
continue
yield
sample
while
self
.
_force_exit
==
False
:
try
:
sample
=
sample_queue
.
get_nowait
()
except
Queue
.
Empty
:
time
.
sleep
(
0.001
)
else
:
if
isinstance
(
sample
,
EpochEndSignal
):
finished_process_num
+=
1
if
finished_process_num
>=
self
.
_process_num
:
break
else
:
continue
feeding_thread
.
join
()
for
w
in
workers
:
w
.
join
()
yield
sample
def
batch_iterator
(
self
,
batch_size
,
minimum_batch_size
):
def
batch_to_ndarray
(
batch_samples
,
lod
):
...
...
@@ -320,7 +333,7 @@ class DataReader(object):
start
+=
frame_num
return
(
batch_feature
,
batch_label
)
@
suppress_complaints
(
verbose
=
self
.
_verbose
)
@
suppress_complaints
(
verbose
=
self
.
_verbose
,
notify
=
self
.
_force_exit
)
def
batch_assembling_task
(
sample_generator
,
batch_queue
):
batch_samples
=
[]
lod
=
[
0
]
...
...
@@ -349,7 +362,7 @@ class DataReader(object):
assembling_thread
.
daemon
=
True
assembling_thread
.
start
()
while
Tru
e
:
while
self
.
_force_exit
==
Fals
e
:
try
:
batch_data
=
batch_queue
.
get_nowait
()
except
Queue
.
Empty
:
...
...
@@ -358,5 +371,3 @@ class DataReader(object):
if
isinstance
(
batch_data
,
EpochEndSignal
):
break
yield
batch_data
assembling_thread
.
join
()
fluid/DeepASR/data_utils/util.py
浏览文件 @
e7442964
...
...
@@ -35,21 +35,40 @@ def lodtensor_to_ndarray(lod_tensor):
return
ret
,
lod_tensor
.
lod
()
class
CriticalException
(
Exception
):
pass
def
suppress_signal
(
signo
,
stack_frame
):
pass
def
suppress_complaints
(
verbose
):
def
suppress_complaints
(
verbose
,
notify
=
None
):
def
decorator_maker
(
func
):
def
suppress_warpper
(
*
args
,
**
kwargs
):
try
:
func
(
*
args
,
**
kwargs
)
except
:
et
,
ev
,
tb
=
sys
.
exc_info
()
tb
=
Traceback
(
tb
)
if
verbose
==
1
:
reraise
(
et
,
ev
,
tb
.
as_traceback
())
if
notify
is
not
None
:
notify
(
except_type
=
et
,
except_value
=
ev
,
traceback
=
tb
)
if
verbose
==
1
or
isinstance
(
ev
,
CriticalException
):
reraise
(
et
,
ev
,
Traceback
(
tb
).
as_traceback
())
return
suppress_warpper
return
decorator_maker
class
ForceExitWrapper
(
object
):
def
__init__
(
self
,
exit_flag
):
self
.
_exit_flag
=
exit_flag
@
suppress_complaints
(
verbose
=
0
)
def
__call__
(
self
,
*
args
,
**
kwargs
):
self
.
_exit_flag
.
value
=
True
def
__eq__
(
self
,
flag
):
return
self
.
_exit_flag
.
value
==
flag
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录