Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleDetection
提交
23d24764
P
PaddleDetection
项目概览
PaddlePaddle
/
PaddleDetection
大约 1 年 前同步成功
通知
695
Star
11112
Fork
2696
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
184
列表
看板
标记
里程碑
合并请求
40
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleDetection
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
184
Issue
184
列表
看板
标记
里程碑
合并请求
40
合并请求
40
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
23d24764
编写于
11月 20, 2020
作者:
G
Guanghua Yu
提交者:
GitHub
11月 20, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
adapt infer reader (#1727)
上级
7a65af0c
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
61 addition
and
12 deletion
+61
-12
configs/_base_/readers/mask_reader.yml
configs/_base_/readers/mask_reader.yml
+2
-0
ppdet/data/source/dataset.py
ppdet/data/source/dataset.py
+50
-3
tools/infer.py
tools/infer.py
+9
-9
未找到文件。
configs/_base_/readers/mask_reader.yml
浏览文件 @
23d24764
...
@@ -39,6 +39,8 @@ TestReader:
...
@@ -39,6 +39,8 @@ TestReader:
-
NormalizeImage
:
{
is_channel_first
:
false
,
is_scale
:
true
,
mean
:
[
0.485
,
0.456
,
0.406
],
std
:
[
0.229
,
0.224
,
0.225
]}
-
NormalizeImage
:
{
is_channel_first
:
false
,
is_scale
:
true
,
mean
:
[
0.485
,
0.456
,
0.406
],
std
:
[
0.229
,
0.224
,
0.225
]}
-
ResizeImage
:
{
interp
:
1
,
max_size
:
1333
,
target_size
:
800
,
use_cv2
:
true
}
-
ResizeImage
:
{
interp
:
1
,
max_size
:
1333
,
target_size
:
800
,
use_cv2
:
true
}
-
Permute
:
{
channel_first
:
true
,
to_bgr
:
false
}
-
Permute
:
{
channel_first
:
true
,
to_bgr
:
false
}
batch_transforms
:
-
PadBatch
:
{
pad_to_stride
:
32
,
use_padded_im_info
:
false
,
pad_gt
:
false
}
batch_size
:
1
batch_size
:
1
shuffle
:
false
shuffle
:
false
drop_last
:
false
drop_last
:
false
ppdet/data/source/dataset.py
浏览文件 @
23d24764
...
@@ -68,6 +68,23 @@ class DetDataset(Dataset):
...
@@ -68,6 +68,23 @@ class DetDataset(Dataset):
return
os
.
path
.
join
(
self
.
dataset_dir
,
self
.
anno_path
)
return
os
.
path
.
join
(
self
.
dataset_dir
,
self
.
anno_path
)
def
_is_valid_file
(
f
,
extensions
=
(
'.jpg'
,
'.jpeg'
,
'.png'
,
'.bmp'
)):
return
f
.
lower
().
endswith
(
extensions
)
def
_make_dataset
(
dir
):
dir
=
os
.
path
.
expanduser
(
dir
)
if
not
os
.
path
.
isdir
(
d
):
raise
(
'{} should be a dir'
.
format
(
dir
))
images
=
[]
for
root
,
_
,
fnames
in
sorted
(
os
.
walk
(
dir
,
followlinks
=
True
)):
for
fname
in
sorted
(
fnames
):
path
=
os
.
path
.
join
(
root
,
fname
)
if
is_valid_file
(
path
):
images
.
append
(
path
)
return
images
@
register
@
register
@
serializable
@
serializable
class
ImageFolder
(
DetDataset
):
class
ImageFolder
(
DetDataset
):
...
@@ -76,11 +93,18 @@ class ImageFolder(DetDataset):
...
@@ -76,11 +93,18 @@ class ImageFolder(DetDataset):
image_dir
=
None
,
image_dir
=
None
,
anno_path
=
None
,
anno_path
=
None
,
sample_num
=-
1
,
sample_num
=-
1
,
use_default_label
=
None
,
**
kwargs
):
**
kwargs
):
super
(
ImageFolder
,
self
).
__init__
(
dataset_dir
,
image_dir
,
anno_path
,
super
(
ImageFolder
,
self
).
__init__
(
dataset_dir
,
image_dir
,
anno_path
,
sample_num
)
sample_num
,
use_default_label
)
self
.
_imid2path
=
{}
self
.
roidbs
=
None
def
parse_dataset
(
self
):
def
parse_dataset
(
self
,
with_background
=
True
):
if
not
self
.
roidbs
:
self
.
roidbs
=
self
.
_load_images
()
def
_parse
(
self
):
image_dir
=
self
.
image_dir
image_dir
=
self
.
image_dir
if
not
isinstance
(
image_dir
,
Sequence
):
if
not
isinstance
(
image_dir
,
Sequence
):
image_dir
=
[
image_dir
]
image_dir
=
[
image_dir
]
...
@@ -91,4 +115,27 @@ class ImageFolder(DetDataset):
...
@@ -91,4 +115,27 @@ class ImageFolder(DetDataset):
images
.
extend
(
_make_dataset
(
im_dir
))
images
.
extend
(
_make_dataset
(
im_dir
))
elif
os
.
path
.
isfile
(
im_dir
)
and
_is_valid_file
(
im_dir
):
elif
os
.
path
.
isfile
(
im_dir
)
and
_is_valid_file
(
im_dir
):
images
.
append
(
im_dir
)
images
.
append
(
im_dir
)
self
.
roidbs
=
images
return
images
def
_load_images
(
self
):
images
=
self
.
_parse
()
ct
=
0
records
=
[]
for
image
in
images
:
assert
image
!=
''
and
os
.
path
.
isfile
(
image
),
\
"Image {} not found"
.
format
(
image
)
if
self
.
sample_num
>
0
and
ct
>=
self
.
sample_num
:
break
rec
=
{
'im_id'
:
np
.
array
([
ct
]),
'im_file'
:
image
}
self
.
_imid2path
[
ct
]
=
image
ct
+=
1
records
.
append
(
rec
)
assert
len
(
records
)
>
0
,
"No image file found"
return
records
def
get_imid2path
(
self
):
return
self
.
_imid2path
def
set_images
(
self
,
images
):
self
.
image_dir
=
images
self
.
roidbs
=
self
.
_load_images
()
tools/infer.py
浏览文件 @
23d24764
...
@@ -33,7 +33,6 @@ from ppdet.core.workspace import load_config, merge_config, create
...
@@ -33,7 +33,6 @@ from ppdet.core.workspace import load_config, merge_config, create
from
ppdet.utils.check
import
check_gpu
,
check_version
,
check_config
from
ppdet.utils.check
import
check_gpu
,
check_version
,
check_config
from
ppdet.utils.visualizer
import
visualize_results
from
ppdet.utils.visualizer
import
visualize_results
from
ppdet.utils.cli
import
ArgsParser
from
ppdet.utils.cli
import
ArgsParser
from
ppdet.data.reader
import
create_reader
from
ppdet.utils.checkpoint
import
load_weight
from
ppdet.utils.checkpoint
import
load_weight
from
ppdet.utils.eval_utils
import
get_infer_results
from
ppdet.utils.eval_utils
import
get_infer_results
import
logging
import
logging
...
@@ -120,22 +119,24 @@ def get_test_images(infer_dir, infer_img):
...
@@ -120,22 +119,24 @@ def get_test_images(infer_dir, infer_img):
return
images
return
images
def
run
(
FLAGS
,
cfg
):
def
run
(
FLAGS
,
cfg
,
place
):
# Model
# Model
main_arch
=
cfg
.
architecture
main_arch
=
cfg
.
architecture
model
=
create
(
cfg
.
architecture
)
model
=
create
(
cfg
.
architecture
)
dataset
=
cfg
.
TestReader
[
'dataset'
]
# data
dataset
=
cfg
.
TestDataset
test_images
=
get_test_images
(
FLAGS
.
infer_dir
,
FLAGS
.
infer_img
)
test_images
=
get_test_images
(
FLAGS
.
infer_dir
,
FLAGS
.
infer_img
)
dataset
.
set_images
(
test_images
)
dataset
.
set_images
(
test_images
)
test_loader
,
_
=
create
(
'TestReader'
)(
dataset
,
cfg
[
'worker_num'
],
place
)
# TODO: support other metrics
# TODO: support other metrics
imid2path
=
dataset
.
get_imid2path
()
imid2path
=
dataset
.
get_imid2path
()
from
ppdet.utils.coco_eval
import
get_category_info
from
ppdet.utils.coco_eval
import
get_category_info
anno_file
=
dataset
.
get_anno
()
anno_file
=
dataset
.
get_anno
()
with_background
=
dataset
.
with_background
with_background
=
cfg
.
with_background
use_default_label
=
dataset
.
use_default_label
use_default_label
=
dataset
.
use_default_label
clsid2catid
,
catid2name
=
get_category_info
(
anno_file
,
with_background
,
clsid2catid
,
catid2name
=
get_category_info
(
anno_file
,
with_background
,
use_default_label
)
use_default_label
)
...
@@ -143,11 +144,8 @@ def run(FLAGS, cfg):
...
@@ -143,11 +144,8 @@ def run(FLAGS, cfg):
# Init Model
# Init Model
load_weight
(
model
,
cfg
.
weights
)
load_weight
(
model
,
cfg
.
weights
)
# Data Reader
test_reader
=
create_reader
(
cfg
.
TestDataset
,
cfg
.
TestReader
)
# Run Infer
# Run Infer
for
iter_id
,
data
in
enumerate
(
test_
reader
()
):
for
iter_id
,
data
in
enumerate
(
test_
loader
):
# forward
# forward
model
.
eval
()
model
.
eval
()
outs
=
model
(
data
,
cfg
.
TestReader
[
'inputs_def'
][
'fields'
],
'infer'
)
outs
=
model
(
data
,
cfg
.
TestReader
[
'inputs_def'
][
'fields'
],
'infer'
)
...
@@ -208,7 +206,9 @@ def main():
...
@@ -208,7 +206,9 @@ def main():
check_gpu
(
cfg
.
use_gpu
)
check_gpu
(
cfg
.
use_gpu
)
check_version
()
check_version
()
run
(
FLAGS
,
cfg
)
place
=
'gpu:{}'
.
format
(
ParallelEnv
().
dev_id
)
if
cfg
.
use_gpu
else
'cpu'
place
=
paddle
.
set_device
(
place
)
run
(
FLAGS
,
cfg
,
place
)
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录