Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
s920243400
PaddleDetection
提交
2ecbbe59
P
PaddleDetection
项目概览
s920243400
/
PaddleDetection
与 Fork 源项目一致
Fork自
PaddlePaddle / PaddleDetection
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleDetection
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
2ecbbe59
编写于
9月 09, 2020
作者:
G
Guanghua Yu
提交者:
GitHub
9月 09, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
remove unnecessary code and sort out code in deploy/infer (#1378)
上级
57a02fd6
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
45 addition
and
31 deletion
+45
-31
deploy/python/infer.py
deploy/python/infer.py
+25
-17
tools/export_model.py
tools/export_model.py
+20
-14
未找到文件。
deploy/python/infer.py
浏览文件 @
2ecbbe59
...
...
@@ -25,6 +25,24 @@ import numpy as np
import
paddle.fluid
as
fluid
from
visualize
import
visualize_box_mask
# Global dictionary
RESIZE_SCALE_SET
=
{
'RCNN'
,
'RetinaNet'
,
'FCOS'
,
}
SUPPORT_MODELS
=
{
'YOLO'
,
'SSD'
,
'RetinaNet'
,
'EfficientDet'
,
'RCNN'
,
'Face'
,
'TTF'
,
'FCOS'
,
}
def
decode_image
(
im_file
,
im_info
):
"""read rgb image
...
...
@@ -70,11 +88,10 @@ class Resize(object):
interp
=
cv2
.
INTER_LINEAR
):
self
.
target_size
=
target_size
self
.
max_size
=
max_size
self
.
image_shape
=
image_shape
,
self
.
image_shape
=
image_shape
self
.
arch
=
arch
self
.
use_cv2
=
use_cv2
self
.
interp
=
interp
self
.
scale_set
=
{
'RCNN'
,
'RetinaNet'
,
'FCOS'
}
def
__call__
(
self
,
im
,
im_info
):
"""
...
...
@@ -124,12 +141,12 @@ class Resize(object):
Args:
im (np.ndarray): image (np.ndarray)
Returns:
im_scale_x: the resize ratio of X
im_scale_y: the resize ratio of Y
im_scale_x: the resize ratio of X
im_scale_y: the resize ratio of Y
"""
origin_shape
=
im
.
shape
[:
2
]
im_c
=
im
.
shape
[
2
]
if
self
.
max_size
!=
0
and
self
.
arch
in
self
.
scale_set
:
if
self
.
max_size
!=
0
and
self
.
arch
in
RESIZE_SCALE_SET
:
im_size_min
=
np
.
min
(
origin_shape
[
0
:
2
])
im_size_max
=
np
.
max
(
origin_shape
[
0
:
2
])
im_scale
=
float
(
self
.
target_size
)
/
float
(
im_size_min
)
...
...
@@ -255,7 +272,7 @@ def create_inputs(im, im_info, model_arch='YOLO'):
if
'YOLO'
in
model_arch
:
im_size
=
np
.
array
([
origin_shape
]).
astype
(
'int32'
)
inputs
[
'im_size'
]
=
im_size
elif
'RetinaNet'
in
model_arch
:
elif
'RetinaNet'
or
'EfficientDet'
in
model_arch
:
scale
=
scale_x
im_info
=
np
.
array
([
resize_shape
+
[
scale
]]).
astype
(
'float32'
)
inputs
[
'im_info'
]
=
im_info
...
...
@@ -276,15 +293,6 @@ class Config():
Args:
model_dir (str): root path of model.yml
"""
support_models
=
[
'YOLO'
,
'SSD'
,
'RetinaNet'
,
'RCNN'
,
'Face'
,
'TTF'
,
'FCOS'
,
]
def
__init__
(
self
,
model_dir
):
# parsing Yaml config for Preprocess
...
...
@@ -307,11 +315,11 @@ class Config():
Raises:
ValueError: loaded model not in supported model type
"""
for
support_model
in
self
.
support_models
:
for
support_model
in
SUPPORT_MODELS
:
if
support_model
in
yml_conf
[
'arch'
]:
return
True
raise
ValueError
(
"Unsupported arch: {}, expect {}"
.
format
(
yml_conf
[
'arch'
],
self
.
support_models
))
'arch'
],
SUPPORT_MODELS
))
def
print_config
(
self
):
print
(
'----------- Model Configuration -----------'
)
...
...
tools/export_model.py
浏览文件 @
2ecbbe59
...
...
@@ -36,13 +36,29 @@ FORMAT = '%(asctime)s-%(levelname)s: %(message)s'
logging
.
basicConfig
(
level
=
logging
.
INFO
,
format
=
FORMAT
)
logger
=
logging
.
getLogger
(
__name__
)
# Global dictionary
TRT_MIN_SUBGRAPH
=
{
'YOLO'
:
3
,
'SSD'
:
3
,
'RCNN'
:
40
,
'RetinaNet'
:
40
,
'EfficientDet'
:
40
,
'Face'
:
3
,
'TTFNet'
:
3
,
'FCOS'
:
3
,
}
RESIZE_SCALE_SET
=
{
'RCNN'
,
'RetinaNet'
,
'FCOS'
,
}
def
parse_reader
(
reader_cfg
,
metric
,
arch
):
preprocess_list
=
[]
image_shape
=
reader_cfg
[
'inputs_def'
].
get
(
'image_shape'
,
[
3
,
None
,
None
])
has_shape_def
=
not
None
in
image_shape
scale_set
=
{
'RCNN'
,
'RetinaNet'
}
dataset
=
reader_cfg
[
'dataset'
]
anno_file
=
dataset
.
get_anno
()
...
...
@@ -72,9 +88,9 @@ def parse_reader(reader_cfg, metric, arch):
params
.
pop
(
'_id'
)
if
p
[
'type'
]
==
'Resize'
and
has_shape_def
:
params
[
'target_size'
]
=
min
(
image_shape
[
1
:])
if
arch
in
scale_set
else
image_shape
[
1
]
1
:])
if
arch
in
RESIZE_SCALE_SET
else
image_shape
[
1
]
params
[
'max_size'
]
=
max
(
image_shape
[
1
:])
if
arch
in
scale_set
else
0
1
:])
if
arch
in
RESIZE_SCALE_SET
else
0
params
[
'image_shape'
]
=
image_shape
[
1
:]
if
'target_dim'
in
params
:
params
.
pop
(
'target_dim'
)
...
...
@@ -114,19 +130,9 @@ def dump_infer_config(FLAGS, config):
'draw_threshold'
:
0.5
,
'metric'
:
config
[
'metric'
]
})
trt_min_subgraph
=
{
'YOLO'
:
3
,
'SSD'
:
3
,
'RCNN'
:
40
,
'RetinaNet'
:
40
,
'Face'
:
3
,
'TTFNet'
:
3
,
'FCOS'
:
3
,
}
infer_arch
=
config
[
'architecture'
]
infer_arch
=
'RetinaNet'
if
infer_arch
==
'EfficientDet'
else
infer_arch
for
arch
,
min_subgraph_size
in
trt_min_subgraph
.
items
():
for
arch
,
min_subgraph_size
in
TRT_MIN_SUBGRAPH
.
items
():
if
arch
in
infer_arch
:
infer_cfg
[
'arch'
]
=
arch
infer_cfg
[
'min_subgraph_size'
]
=
min_subgraph_size
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录