Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleDetection
提交
8d3b8b47
P
PaddleDetection
项目概览
PaddlePaddle
/
PaddleDetection
1 年多 前同步成功
通知
696
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看板
未验证
提交
8d3b8b47
编写于
3月 30, 2022
作者:
W
wangxinxin08
提交者:
GitHub
3月 30, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
modify fuse normalize (#5513)
上级
1a8c009c
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
22 addition
and
18 deletion
+22
-18
ppdet/modeling/architectures/meta_arch.py
ppdet/modeling/architectures/meta_arch.py
+22
-18
未找到文件。
ppdet/modeling/architectures/meta_arch.py
浏览文件 @
8d3b8b47
...
...
@@ -22,22 +22,23 @@ class BaseArch(nn.Layer):
self
.
fuse_norm
=
False
def
load_meanstd
(
self
,
cfg_transform
):
self
.
scale
=
1.
self
.
mean
=
paddle
.
to_tensor
([
0.485
,
0.456
,
0.406
]).
reshape
(
(
1
,
3
,
1
,
1
))
self
.
std
=
paddle
.
to_tensor
([
0.229
,
0.224
,
0.225
]).
reshape
((
1
,
3
,
1
,
1
))
scale
=
1.
mean
=
np
.
array
([
0.485
,
0.456
,
0.406
],
dtype
=
np
.
float32
)
std
=
np
.
array
([
0.229
,
0.224
,
0.225
],
dtype
=
np
.
float32
)
for
item
in
cfg_transform
:
if
'NormalizeImage'
in
item
:
self
.
mean
=
paddle
.
to_tensor
(
item
[
'NormalizeImage'
][
'mean'
]).
reshape
((
1
,
3
,
1
,
1
))
self
.
std
=
paddle
.
to_tensor
(
item
[
'NormalizeImage'
][
'std'
]).
reshape
((
1
,
3
,
1
,
1
))
mean
=
np
.
array
(
item
[
'NormalizeImage'
][
'mean'
],
dtype
=
np
.
float32
)
std
=
np
.
array
(
item
[
'NormalizeImage'
][
'std'
],
dtype
=
np
.
float32
)
if
item
[
'NormalizeImage'
].
get
(
'is_scale'
,
True
):
s
elf
.
s
cale
=
1.
/
255.
scale
=
1.
/
255.
break
if
self
.
data_format
==
'NHWC'
:
self
.
mean
=
self
.
mean
.
reshape
(
1
,
1
,
1
,
3
)
self
.
std
=
self
.
std
.
reshape
(
1
,
1
,
1
,
3
)
self
.
scale
=
paddle
.
to_tensor
(
scale
/
std
).
reshape
((
1
,
1
,
1
,
3
))
self
.
bias
=
paddle
.
to_tensor
(
-
mean
/
std
).
reshape
((
1
,
1
,
1
,
3
))
else
:
self
.
scale
=
paddle
.
to_tensor
(
scale
/
std
).
reshape
((
1
,
3
,
1
,
1
))
self
.
bias
=
paddle
.
to_tensor
(
-
mean
/
std
).
reshape
((
1
,
3
,
1
,
1
))
def
forward
(
self
,
inputs
):
if
self
.
data_format
==
'NHWC'
:
...
...
@@ -46,7 +47,7 @@ class BaseArch(nn.Layer):
if
self
.
fuse_norm
:
image
=
inputs
[
'image'
]
self
.
inputs
[
'image'
]
=
(
image
*
self
.
scale
-
self
.
mean
)
/
self
.
std
self
.
inputs
[
'image'
]
=
image
*
self
.
scale
+
self
.
bias
self
.
inputs
[
'im_shape'
]
=
inputs
[
'im_shape'
]
self
.
inputs
[
'scale_factor'
]
=
inputs
[
'scale_factor'
]
else
:
...
...
@@ -66,8 +67,7 @@ class BaseArch(nn.Layer):
outs
=
[]
for
inp
in
inputs_list
:
if
self
.
fuse_norm
:
self
.
inputs
[
'image'
]
=
(
inp
[
'image'
]
*
self
.
scale
-
self
.
mean
)
/
self
.
std
self
.
inputs
[
'image'
]
=
inp
[
'image'
]
*
self
.
scale
+
self
.
bias
self
.
inputs
[
'im_shape'
]
=
inp
[
'im_shape'
]
self
.
inputs
[
'scale_factor'
]
=
inp
[
'scale_factor'
]
else
:
...
...
@@ -75,7 +75,7 @@ class BaseArch(nn.Layer):
outs
.
append
(
self
.
get_pred
())
# multi-scale test
if
len
(
outs
)
>
1
:
if
len
(
outs
)
>
1
:
out
=
self
.
merge_multi_scale_predictions
(
outs
)
else
:
out
=
outs
[
0
]
...
...
@@ -92,7 +92,9 @@ class BaseArch(nn.Layer):
keep_top_k
=
self
.
bbox_post_process
.
nms
.
keep_top_k
nms_threshold
=
self
.
bbox_post_process
.
nms
.
nms_threshold
else
:
raise
Exception
(
"Multi scale test only supports CascadeRCNN, FasterRCNN and MaskRCNN for now"
)
raise
Exception
(
"Multi scale test only supports CascadeRCNN, FasterRCNN and MaskRCNN for now"
)
final_boxes
=
[]
all_scale_outs
=
paddle
.
concat
([
o
[
'bbox'
]
for
o
in
outs
]).
numpy
()
...
...
@@ -101,9 +103,11 @@ class BaseArch(nn.Layer):
if
np
.
count_nonzero
(
idxs
)
==
0
:
continue
r
=
nms
(
all_scale_outs
[
idxs
,
1
:],
nms_threshold
)
final_boxes
.
append
(
np
.
concatenate
([
np
.
full
((
r
.
shape
[
0
],
1
),
c
),
r
],
1
))
final_boxes
.
append
(
np
.
concatenate
([
np
.
full
((
r
.
shape
[
0
],
1
),
c
),
r
],
1
))
out
=
np
.
concatenate
(
final_boxes
)
out
=
np
.
concatenate
(
sorted
(
out
,
key
=
lambda
e
:
e
[
1
])[
-
keep_top_k
:]).
reshape
((
-
1
,
6
))
out
=
np
.
concatenate
(
sorted
(
out
,
key
=
lambda
e
:
e
[
1
])[
-
keep_top_k
:]).
reshape
((
-
1
,
6
))
out
=
{
'bbox'
:
paddle
.
to_tensor
(
out
),
'bbox_num'
:
paddle
.
to_tensor
(
np
.
array
([
out
.
shape
[
0
],
]))
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录