Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
models
提交
d82ded52
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看板
提交
d82ded52
编写于
1月 14, 2020
作者:
Y
Yang Zhang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Enable multi device evaluation with DALI reader
上级
2b8f904e
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
58 addition
and
65 deletion
+58
-65
PaddleCV/image_classification/dali.py
PaddleCV/image_classification/dali.py
+58
-65
未找到文件。
PaddleCV/image_classification/dali.py
浏览文件 @
d82ded52
...
...
@@ -148,6 +148,8 @@ def build(settings, mode='train'):
file_root
=
settings
.
data_dir
bs
=
settings
.
batch_size
if
mode
!=
'train'
and
hasattr
(
settings
,
'test_batch_size'
):
bs
=
settings
.
test_batch_size
assert
bs
%
paddle
.
fluid
.
core
.
get_cuda_device_count
()
==
0
,
\
"batch size must be multiple of number of devices"
batch_size
=
bs
//
paddle
.
fluid
.
core
.
get_cuda_device_count
()
...
...
@@ -170,69 +172,13 @@ def build(settings, mode='train'):
assert
interp
in
interp_map
,
"interpolation method not supported by DALI"
interp
=
interp_map
[
interp
]
if
mode
!=
'train'
:
p
=
fluid
.
framework
.
cuda_places
()[
0
]
place
=
fluid
.
core
.
Place
()
place
.
set_place
(
p
)
device_id
=
place
.
gpu_device_id
()
file_list
=
os
.
path
.
join
(
file_root
,
'val_list.txt'
)
if
not
os
.
path
.
exists
(
file_list
):
file_list
=
None
file_root
=
os
.
path
.
join
(
file_root
,
'val'
)
pipe
=
HybridValPipe
(
file_root
,
file_list
,
batch_size
,
resize_shorter
,
crop
,
interp
,
mean
,
std
,
device_id
=
device_id
)
pipe
.
build
()
return
DALIGenericIterator
(
pipe
,
[
'feed_image'
,
'feed_label'
],
size
=
len
(
pipe
),
dynamic_shape
=
True
,
fill_last_batch
=
False
,
last_batch_padded
=
True
)
file_list
=
os
.
path
.
join
(
file_root
,
'train_list.txt'
)
file_list
=
os
.
path
.
join
(
file_root
,
'{}_list.txt'
.
format
(
mode
))
if
not
os
.
path
.
exists
(
file_list
):
file_list
=
None
file_root
=
os
.
path
.
join
(
file_root
,
'train'
)
file_root
=
os
.
path
.
join
(
file_root
,
mode
)
if
'PADDLE_TRAINER_ID'
in
env
and
'PADDLE_TRAINERS_NUM'
in
env
:
shard_id
=
int
(
env
[
'PADDLE_TRAINER_ID'
])
num_shards
=
int
(
env
[
'PADDLE_TRAINERS_NUM'
])
device_id
=
int
(
env
[
'FLAGS_selected_gpus'
])
pipe
=
HybridTrainPipe
(
file_root
,
file_list
,
batch_size
,
resize_shorter
,
crop
,
min_area
,
lower
,
upper
,
interp
,
mean
,
std
,
device_id
,
shard_id
,
num_shards
,
seed
=
42
+
shard_id
)
pipe
.
build
()
pipelines
=
[
pipe
]
sample_per_shard
=
len
(
pipe
)
//
num_shards
else
:
pipelines
=
[]
places
=
fluid
.
framework
.
cuda_places
()
num_shards
=
len
(
places
)
for
idx
,
p
in
enumerate
(
places
):
place
=
fluid
.
core
.
Place
()
place
.
set_place
(
p
)
device_id
=
place
.
gpu_device_id
()
def
build_pipe
(
device_id
,
num_shards
=
1
,
shard_id
=
0
,
seed
=
42
):
if
mode
==
'train'
:
pipe
=
HybridTrainPipe
(
file_root
,
file_list
,
...
...
@@ -245,16 +191,63 @@ def build(settings, mode='train'):
interp
,
mean
,
std
,
device_id
,
idx
,
num_shards
,
device_id
=
device_id
,
shard_id
=
shard_id
,
num_shards
=
num_shards
,
seed
=
seed
)
else
:
pipe
=
HybridValPipe
(
file_root
,
file_list
,
batch_size
,
resize_shorter
,
crop
,
interp
,
mean
,
std
,
device_id
=
device_id
,
shard_id
=
shard_id
,
num_shards
=
num_shards
)
pipe
.
build
()
return
pipe
shard_id
=
0
num_shards
=
1
device_id
=
0
if
'PADDLE_TRAINER_ID'
in
env
and
'PADDLE_TRAINERS_NUM'
in
env
:
if
mode
==
'train'
:
shard_id
=
int
(
env
[
'PADDLE_TRAINER_ID'
])
num_shards
=
int
(
env
[
'PADDLE_TRAINERS_NUM'
])
device_id
=
int
(
env
[
'FLAGS_selected_gpus'
])
pipe
=
build_pipe
(
device_id
=
device_id
,
shard_id
=
shard_id
,
num_shards
=
num_shards
,
seed
=
42
+
shard_id
)
pipelines
=
[
pipe
]
sample_per_shard
=
len
(
pipe
)
//
num_shards
else
:
pipelines
=
[]
places
=
fluid
.
framework
.
cuda_places
()
num_shards
=
len
(
places
)
for
idx
,
p
in
enumerate
(
places
):
place
=
fluid
.
core
.
Place
()
place
.
set_place
(
p
)
device_id
=
place
.
gpu_device_id
()
pipe
=
build_pipe
(
device_id
=
device_id
,
shard_id
=
shard_id
,
num_shards
=
num_shards
,
seed
=
42
+
idx
)
pipe
.
build
()
pipelines
.
append
(
pipe
)
sample_per_shard
=
len
(
pipelines
[
0
])
return
DALIGenericIterator
(
pipelines
,
[
'feed_image'
,
'feed_label'
],
size
=
sample_per_shard
)
pipelines
,
[
'feed_image'
,
'feed_label'
],
size
=
sample_per_shard
,
fill_last_batch
=
mode
==
'train'
,
dynamic_shape
=
mode
!=
'train'
,
last_batch_padded
=
mode
!=
'train'
)
def
train
(
settings
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录