Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
models
提交
fff5cc27
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看板
未验证
提交
fff5cc27
编写于
2月 17, 2020
作者:
X
xiaoting
提交者:
GitHub
2月 17, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
change reader to DataLoader (#4293)
* fix load for yolo_dy
上级
c3829289
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
25 addition
and
32 deletion
+25
-32
dygraph/yolov3/reader.py
dygraph/yolov3/reader.py
+21
-28
dygraph/yolov3/train.py
dygraph/yolov3/train.py
+4
-4
未找到文件。
dygraph/yolov3/reader.py
浏览文件 @
fff5cc27
...
@@ -126,7 +126,6 @@ class DataSetReader(object):
...
@@ -126,7 +126,6 @@ class DataSetReader(object):
for
k
in
[
'date_captured'
,
'url'
,
'license'
,
'file_name'
]:
for
k
in
[
'date_captured'
,
'url'
,
'license'
,
'file_name'
]:
if
k
in
img
:
if
k
in
img
:
del
img
[
k
]
del
img
[
k
]
if
is_train
:
if
is_train
:
self
.
_parse_gt_annotations
(
img
)
self
.
_parse_gt_annotations
(
img
)
...
@@ -147,6 +146,7 @@ class DataSetReader(object):
...
@@ -147,6 +146,7 @@ class DataSetReader(object):
shuffle
=
False
,
shuffle
=
False
,
shuffle_seed
=
None
,
shuffle_seed
=
None
,
mixup_iter
=
0
,
mixup_iter
=
0
,
max_iter
=
0
,
random_sizes
=
[],
random_sizes
=
[],
image
=
None
):
image
=
None
):
assert
mode
in
[
'train'
,
'test'
,
'infer'
],
"Unknow mode type!"
assert
mode
in
[
'train'
,
'test'
,
'infer'
],
"Unknow mode type!"
...
@@ -248,6 +248,8 @@ class DataSetReader(object):
...
@@ -248,6 +248,8 @@ class DataSetReader(object):
yield
batch_out
yield
batch_out
batch_out
=
[]
batch_out
=
[]
total_iter
+=
1
total_iter
+=
1
if
total_iter
>=
max_iter
:
return
img_size
=
get_img_size
(
size
,
random_sizes
)
img_size
=
get_img_size
(
size
,
random_sizes
)
elif
mode
==
'test'
:
elif
mode
==
'test'
:
...
@@ -296,10 +298,10 @@ def train(size=416,
...
@@ -296,10 +298,10 @@ def train(size=416,
random_sizes
=
[],
random_sizes
=
[],
num_workers
=
8
,
num_workers
=
8
,
max_queue
=
32
,
max_queue
=
32
,
use_multiprocess_reader
=
True
):
use_multiprocess_reader
=
True
,
use_gpu
=
True
):
generator
=
dsr
.
get_reader
(
'train'
,
size
,
batch_size
,
shuffle
,
shuffle_seed
,
generator
=
dsr
.
get_reader
(
'train'
,
size
,
batch_size
,
shuffle
,
shuffle_seed
,
int
(
mixup_iter
/
num_workers
),
random_sizes
)
int
(
mixup_iter
/
num_workers
),
total_iter
,
random_sizes
)
if
not
use_multiprocess_reader
:
if
not
use_multiprocess_reader
:
return
generator
return
generator
else
:
else
:
...
@@ -317,30 +319,21 @@ def train(size=416,
...
@@ -317,30 +319,21 @@ def train(size=416,
def
reader
():
def
reader
():
cnt
=
0
cnt
=
0
try
:
data_loader
=
fluid
.
io
.
DataLoader
.
from_generator
(
capacity
=
64
,
use_multiprocess
=
True
,
iterable
=
True
)
enqueuer
=
GeneratorEnqueuer
(
if
use_gpu
:
infinite_reader
(),
use_multiprocessing
=
use_multiprocess_reader
)
place
=
fluid
.
CUDAPlace
(
fluid
.
dygraph
.
parallel
.
Env
().
dev_id
)
if
cfg
.
use_data_parallel
else
fluid
.
CUDAPlace
(
0
)
enqueuer
.
start
(
max_queue_size
=
max_queue
,
workers
=
num_workers
)
else
:
generator_out
=
None
place
=
fluid
.
CPUPlace
()
while
True
:
data_loader
.
set_sample_list_generator
(
infinite_reader
,
places
=
place
)
while
enqueuer
.
is_running
():
generator_out
=
[]
if
not
enqueuer
.
queue
.
empty
():
for
data
in
data_loader
():
generator_out
=
enqueuer
.
queue
.
get
()
for
i
in
data
:
break
generator_out
.
append
(
i
.
numpy
()[
0
])
else
:
yield
[
generator_out
]
time
.
sleep
(
0.02
)
generator_out
=
[]
yield
generator_out
cnt
+=
1
cnt
+=
1
if
cnt
>=
total_iter
:
if
cnt
>=
total_iter
:
return
enqueuer
.
stop
()
return
generator_out
=
None
except
Exception
as
e
:
print
(
"Exception occured in reader: {}"
.
format
(
str
(
e
)))
finally
:
if
enqueuer
:
enqueuer
.
stop
()
return
reader
return
reader
...
...
dygraph/yolov3/train.py
浏览文件 @
fff5cc27
...
@@ -75,7 +75,8 @@ def train():
...
@@ -75,7 +75,8 @@ def train():
gpu_id
=
int
(
os
.
environ
.
get
(
'FLAGS_selected_gpus'
,
0
))
gpu_id
=
int
(
os
.
environ
.
get
(
'FLAGS_selected_gpus'
,
0
))
place
=
fluid
.
CUDAPlace
(
fluid
.
dygraph
.
parallel
.
Env
().
dev_id
)
if
cfg
.
use_data_parallel
else
fluid
.
CUDAPlace
(
0
)
place
=
fluid
.
CUDAPlace
(
fluid
.
dygraph
.
parallel
.
Env
().
dev_id
)
if
cfg
.
use_data_parallel
else
fluid
.
CUDAPlace
(
0
)
if
not
cfg
.
use_gpu
:
palce
=
fluid
.
CPUPlace
()
with
fluid
.
dygraph
.
guard
(
place
):
with
fluid
.
dygraph
.
guard
(
place
):
if
args
.
use_data_parallel
:
if
args
.
use_data_parallel
:
strategy
=
fluid
.
dygraph
.
parallel
.
prepare_context
()
strategy
=
fluid
.
dygraph
.
parallel
.
prepare_context
()
...
@@ -141,8 +142,8 @@ def train():
...
@@ -141,8 +142,8 @@ def train():
mixup_iter
=
mixup_iter
*
devices_num
,
mixup_iter
=
mixup_iter
*
devices_num
,
random_sizes
=
random_sizes
,
random_sizes
=
random_sizes
,
use_multiprocess_reader
=
cfg
.
use_multiprocess_reader
,
use_multiprocess_reader
=
cfg
.
use_multiprocess_reader
,
num_workers
=
cfg
.
worker_num
)
num_workers
=
cfg
.
worker_num
,
use_gpu
=
cfg
.
use_gpu
)
if
args
.
use_data_parallel
:
if
args
.
use_data_parallel
:
train_reader
=
fluid
.
contrib
.
reader
.
distributed_batch_reader
(
train_reader
)
train_reader
=
fluid
.
contrib
.
reader
.
distributed_batch_reader
(
train_reader
)
smoothed_loss
=
SmoothedValue
()
smoothed_loss
=
SmoothedValue
()
...
@@ -150,7 +151,6 @@ def train():
...
@@ -150,7 +151,6 @@ def train():
for
iter_id
,
data
in
enumerate
(
train_reader
()):
for
iter_id
,
data
in
enumerate
(
train_reader
()):
prev_start_time
=
start_time
prev_start_time
=
start_time
start_time
=
time
.
time
()
start_time
=
time
.
time
()
img
=
np
.
array
([
x
[
0
]
for
x
in
data
]).
astype
(
'float32'
)
img
=
np
.
array
([
x
[
0
]
for
x
in
data
]).
astype
(
'float32'
)
img
=
to_variable
(
img
)
img
=
to_variable
(
img
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录