Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
models
提交
5b584500
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,发现更多精彩内容 >>
未验证
提交
5b584500
编写于
6月 24, 2019
作者:
W
whs
提交者:
GitHub
6月 24, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix reader of slim. (#2477)
* Fix reader of slim. * Remove unused comments.
上级
2aed7f63
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
30 addition
and
27 deletion
+30
-27
PaddleSlim/reader.py
PaddleSlim/reader.py
+30
-27
未找到文件。
PaddleSlim/reader.py
浏览文件 @
5b584500
...
...
@@ -133,33 +133,36 @@ def _reader_creator(file_list,
data_dir
=
DATA_DIR
,
batch_size
=
1
):
def
reader
():
with
open
(
file_list
)
as
flist
:
full_lines
=
[
line
.
strip
()
for
line
in
flist
]
if
shuffle
:
np
.
random
.
shuffle
(
full_lines
)
if
mode
==
'train'
and
os
.
getenv
(
'PADDLE_TRAINING_ROLE'
):
# distributed mode if the env var `PADDLE_TRAINING_ROLE` exits
trainer_id
=
int
(
os
.
getenv
(
"PADDLE_TRAINER_ID"
,
"0"
))
trainer_count
=
int
(
os
.
getenv
(
"PADDLE_TRAINERS"
,
"1"
))
per_node_lines
=
len
(
full_lines
)
//
trainer_count
lines
=
full_lines
[
trainer_id
*
per_node_lines
:(
trainer_id
+
1
)
*
per_node_lines
]
print
(
"read images from %d, length: %d, lines length: %d, total: %d"
%
(
trainer_id
*
per_node_lines
,
per_node_lines
,
len
(
lines
),
len
(
full_lines
)))
else
:
lines
=
full_lines
for
line
in
lines
:
if
mode
==
'train'
or
mode
==
'val'
:
img_path
,
label
=
line
.
split
()
# img_path = img_path.replace("JPEG", "jpeg")
img_path
=
os
.
path
.
join
(
data_dir
,
img_path
)
yield
img_path
,
int
(
label
)
elif
mode
==
'test'
:
img_path
=
os
.
path
.
join
(
data_dir
,
line
)
yield
[
img_path
]
try
:
with
open
(
file_list
)
as
flist
:
full_lines
=
[
line
.
strip
()
for
line
in
flist
]
if
shuffle
:
np
.
random
.
shuffle
(
full_lines
)
if
mode
==
'train'
and
os
.
getenv
(
'PADDLE_TRAINING_ROLE'
):
# distributed mode if the env var `PADDLE_TRAINING_ROLE` exits
trainer_id
=
int
(
os
.
getenv
(
"PADDLE_TRAINER_ID"
,
"0"
))
trainer_count
=
int
(
os
.
getenv
(
"PADDLE_TRAINERS"
,
"1"
))
per_node_lines
=
len
(
full_lines
)
//
trainer_count
lines
=
full_lines
[
trainer_id
*
per_node_lines
:(
trainer_id
+
1
)
*
per_node_lines
]
print
(
"read images from %d, length: %d, lines length: %d, total: %d"
%
(
trainer_id
*
per_node_lines
,
per_node_lines
,
len
(
lines
),
len
(
full_lines
)))
else
:
lines
=
full_lines
for
line
in
lines
:
if
mode
==
'train'
or
mode
==
'val'
:
img_path
,
label
=
line
.
split
()
img_path
=
os
.
path
.
join
(
data_dir
,
img_path
)
yield
img_path
,
int
(
label
)
elif
mode
==
'test'
:
img_path
=
os
.
path
.
join
(
data_dir
,
line
)
yield
[
img_path
]
except
Exception
as
e
:
print
(
"Reader failed!
\n
{}"
.
format
(
str
(
e
)))
os
.
_exit
(
1
)
mapper
=
functools
.
partial
(
process_image
,
mode
=
mode
,
color_jitter
=
color_jitter
,
rotate
=
rotate
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录