Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleSlim
提交
803a0b22
P
PaddleSlim
项目概览
PaddlePaddle
/
PaddleSlim
大约 2 年 前同步成功
通知
51
Star
1434
Fork
344
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
53
列表
看板
标记
里程碑
合并请求
16
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleSlim
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
53
Issue
53
列表
看板
标记
里程碑
合并请求
16
合并请求
16
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
803a0b22
编写于
11月 20, 2019
作者:
W
wanghaoshuang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add cached reader.
上级
c69ae501
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
60 addition
and
0 deletion
+60
-0
paddleslim/common/__init__.py
paddleslim/common/__init__.py
+3
-0
paddleslim/common/cached_reader.py
paddleslim/common/cached_reader.py
+57
-0
未找到文件。
paddleslim/common/__init__.py
浏览文件 @
803a0b22
...
@@ -23,6 +23,8 @@ import controller_client
...
@@ -23,6 +23,8 @@ import controller_client
from
controller_client
import
*
from
controller_client
import
*
import
lock_utils
import
lock_utils
from
lock_utils
import
*
from
lock_utils
import
*
import
cached_reader
from
cached_reader
import
*
__all__
=
[]
__all__
=
[]
__all__
+=
controller
.
__all__
__all__
+=
controller
.
__all__
...
@@ -30,3 +32,4 @@ __all__ += sa_controller.__all__
...
@@ -30,3 +32,4 @@ __all__ += sa_controller.__all__
__all__
+=
controller_server
.
__all__
__all__
+=
controller_server
.
__all__
__all__
+=
controller_client
.
__all__
__all__
+=
controller_client
.
__all__
__all__
+=
lock_utils
.
__all__
__all__
+=
lock_utils
.
__all__
__all__
+=
cached_reader
.
__all__
paddleslim/common/cached_reader.py
0 → 100644
浏览文件 @
803a0b22
# Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import
os
import
logging
import
numpy
as
np
from
.log_helper
import
get_logger
__all__
=
[
'cached_reader'
]
_logger
=
get_logger
(
__name__
,
level
=
logging
.
INFO
)
def
cached_reader
(
reader
,
sampled_rate
,
cache_path
,
cached_id
):
"""
Sample partial data from reader and cache them into local file system.
Args:
reader: Iterative data source.
sampled_rate(float): The sampled rate used to sample partial data for evaluation. None means using all data in eval_reader. default: None.
cache_path(str): The path to cache the sampled data.
cached_id(int): The id of dataset sampled. Evaluations with same cached_id use the same sampled dataset. default: 0.
"""
np
.
random
.
seed
(
cached_id
)
cache_path
=
os
.
path
.
join
(
cache_path
,
str
(
cached_id
))
_logger
.
debug
(
'read data from: {}'
.
format
(
cache_path
))
def
s_reader
():
if
os
.
path
.
isdir
(
cache_path
):
for
file_name
in
open
(
os
.
path
.
join
(
cache_path
,
"list"
)):
yield
np
.
load
(
os
.
path
.
join
(
cache_path
,
file_name
.
strip
()),
allow_pickle
=
True
)
else
:
os
.
makedirs
(
cache_path
)
list_file
=
open
(
os
.
path
.
join
(
cache_path
,
"list"
),
'w'
)
batch
=
0
dtype
=
None
for
data
in
reader
():
if
batch
==
0
or
(
np
.
random
.
uniform
()
<
sampled_rate
):
np
.
save
(
os
.
path
.
join
(
cache_path
,
'batch'
+
str
(
batch
)),
data
)
list_file
.
write
(
'batch'
+
str
(
batch
)
+
'.npy
\n
'
)
batch
+=
1
yield
data
return
s_reader
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录