Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleDetection
提交
a65904d8
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看板
未验证
提交
a65904d8
编写于
2月 08, 2023
作者:
W
Wenyu
提交者:
GitHub
2月 08, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add ema filter no_grad (#7691)
* add ema filter no_grad * update file name and default value
上级
1e21400e
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
51 addition
and
2 deletion
+51
-2
ppdet/engine/trainer.py
ppdet/engine/trainer.py
+4
-1
ppdet/optimizer/ema.py
ppdet/optimizer/ema.py
+10
-1
ppdet/optimizer/utils.py
ppdet/optimizer/utils.py
+37
-0
未找到文件。
ppdet/engine/trainer.py
浏览文件 @
a65904d8
...
@@ -187,12 +187,14 @@ class Trainer(object):
...
@@ -187,12 +187,14 @@ class Trainer(object):
ema_decay_type
=
self
.
cfg
.
get
(
'ema_decay_type'
,
'threshold'
)
ema_decay_type
=
self
.
cfg
.
get
(
'ema_decay_type'
,
'threshold'
)
cycle_epoch
=
self
.
cfg
.
get
(
'cycle_epoch'
,
-
1
)
cycle_epoch
=
self
.
cfg
.
get
(
'cycle_epoch'
,
-
1
)
ema_black_list
=
self
.
cfg
.
get
(
'ema_black_list'
,
None
)
ema_black_list
=
self
.
cfg
.
get
(
'ema_black_list'
,
None
)
ema_filter_no_grad
=
self
.
cfg
.
get
(
'ema_filter_no_grad'
,
False
)
self
.
ema
=
ModelEMA
(
self
.
ema
=
ModelEMA
(
self
.
model
,
self
.
model
,
decay
=
ema_decay
,
decay
=
ema_decay
,
ema_decay_type
=
ema_decay_type
,
ema_decay_type
=
ema_decay_type
,
cycle_epoch
=
cycle_epoch
,
cycle_epoch
=
cycle_epoch
,
ema_black_list
=
ema_black_list
)
ema_black_list
=
ema_black_list
,
ema_filter_no_grad
=
ema_filter_no_grad
)
self
.
_nranks
=
dist
.
get_world_size
()
self
.
_nranks
=
dist
.
get_world_size
()
self
.
_local_rank
=
dist
.
get_rank
()
self
.
_local_rank
=
dist
.
get_rank
()
...
@@ -1040,6 +1042,7 @@ class Trainer(object):
...
@@ -1040,6 +1042,7 @@ class Trainer(object):
start
=
end
start
=
end
return
results
return
results
def
_get_save_image_name
(
self
,
output_dir
,
image_path
):
def
_get_save_image_name
(
self
,
output_dir
,
image_path
):
"""
"""
Get save image name from source image path.
Get save image name from source image path.
...
...
ppdet/optimizer/ema.py
浏览文件 @
a65904d8
...
@@ -21,6 +21,8 @@ import paddle
...
@@ -21,6 +21,8 @@ import paddle
import
weakref
import
weakref
from
copy
import
deepcopy
from
copy
import
deepcopy
from
.utils
import
get_bn_running_state_names
__all__
=
[
'ModelEMA'
,
'SimpleModelEMA'
]
__all__
=
[
'ModelEMA'
,
'SimpleModelEMA'
]
...
@@ -49,7 +51,8 @@ class ModelEMA(object):
...
@@ -49,7 +51,8 @@ class ModelEMA(object):
decay
=
0.9998
,
decay
=
0.9998
,
ema_decay_type
=
'threshold'
,
ema_decay_type
=
'threshold'
,
cycle_epoch
=-
1
,
cycle_epoch
=-
1
,
ema_black_list
=
None
):
ema_black_list
=
None
,
ema_filter_no_grad
=
False
):
self
.
step
=
0
self
.
step
=
0
self
.
epoch
=
0
self
.
epoch
=
0
self
.
decay
=
decay
self
.
decay
=
decay
...
@@ -64,6 +67,12 @@ class ModelEMA(object):
...
@@ -64,6 +67,12 @@ class ModelEMA(object):
else
:
else
:
self
.
state_dict
[
k
]
=
paddle
.
zeros_like
(
v
)
self
.
state_dict
[
k
]
=
paddle
.
zeros_like
(
v
)
bn_states_names
=
get_bn_running_state_names
(
model
)
if
ema_filter_no_grad
:
for
n
,
p
in
model
.
named_parameters
():
if
p
.
stop_gradient
==
True
and
n
not
in
bn_states_names
:
self
.
ema_black_list
.
append
(
n
)
self
.
_model_state
=
{
self
.
_model_state
=
{
k
:
weakref
.
ref
(
p
)
k
:
weakref
.
ref
(
p
)
for
k
,
p
in
model
.
state_dict
().
items
()
for
k
,
p
in
model
.
state_dict
().
items
()
...
...
ppdet/optimizer/utils.py
0 → 100644
浏览文件 @
a65904d8
# Copyright (c) 2023 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from
__future__
import
absolute_import
from
__future__
import
division
from
__future__
import
print_function
import
paddle
import
paddle.nn
as
nn
from
typing
import
List
def
get_bn_running_state_names
(
model
:
nn
.
Layer
)
->
List
[
str
]:
"""Get all bn state full names including running mean and variance
"""
names
=
[]
for
n
,
m
in
model
.
named_sublayers
():
if
isinstance
(
m
,
(
nn
.
BatchNorm2D
,
nn
.
SyncBatchNorm
)):
assert
hasattr
(
m
,
'_mean'
),
f
'assert
{
m
}
has _mean'
assert
hasattr
(
m
,
'_variance'
),
f
'assert
{
m
}
has _variance'
running_mean
=
f
'
{
n
}
._mean'
running_var
=
f
'
{
n
}
._variance'
names
.
extend
([
running_mean
,
running_var
])
return
names
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录