Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Y
yolov5
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
Administrator
yolov5
Commits
0f819919
Unverified
提交
0f819919
authored
2月 25, 2022
作者:
Glenn Jocher
提交者:
GitHub
2月 25, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Update EMA decay `tau` (#6769)
* Update EMA * Update EMA * ratio invert * fix ratio invert * fix2 ratio invert * warmup iterations to 100 * ema_k * implement tau * implement tau
上级
b2adc7c3
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
10 行增加
和
12 行删除
+10
-12
torch_utils.py
utils/torch_utils.py
+10
-12
没有找到文件。
utils/torch_utils.py
浏览文件 @
0f819919
...
...
@@ -32,9 +32,7 @@ warnings.filterwarnings('ignore', message='User provided device_type of \'cuda\'
@contextmanager
def
torch_distributed_zero_first
(
local_rank
:
int
):
"""
Decorator to make all processes in distributed training wait for each local_master to do something.
"""
# Decorator to make all processes in distributed training wait for each local_master to do something
if
local_rank
not
in
[
-
1
,
0
]:
dist
.
barrier
(
device_ids
=
[
local_rank
])
yield
...
...
@@ -43,13 +41,13 @@ def torch_distributed_zero_first(local_rank: int):
def
date_modified
(
path
=
__file__
):
#
r
eturn human-readable file modification date, i.e. '2021-3-26'
#
R
eturn human-readable file modification date, i.e. '2021-3-26'
t
=
datetime
.
datetime
.
fromtimestamp
(
Path
(
path
)
.
stat
()
.
st_mtime
)
return
f
'{t.year}-{t.month}-{t.day}'
def
git_describe
(
path
=
Path
(
__file__
)
.
parent
):
# path must be a directory
#
r
eturn human-readable git description, i.e. v5.0-5-g3e25f1e https://git-scm.com/docs/git-describe
#
R
eturn human-readable git description, i.e. v5.0-5-g3e25f1e https://git-scm.com/docs/git-describe
s
=
f
'git -C {path} describe --tags --long --always'
try
:
return
subprocess
.
check_output
(
s
,
shell
=
True
,
stderr
=
subprocess
.
STDOUT
)
.
decode
()[:
-
1
]
...
...
@@ -99,7 +97,7 @@ def select_device(device='', batch_size=0, newline=True):
def
time_sync
():
#
pyt
orch-accurate time
#
PyT
orch-accurate time
if
torch
.
cuda
.
is_available
():
torch
.
cuda
.
synchronize
()
return
time
.
time
()
...
...
@@ -205,7 +203,7 @@ def prune(model, amount=0.3):
def
fuse_conv_and_bn
(
conv
,
bn
):
# Fuse
convolution and batchnorm
layers https://tehnokv.com/posts/fusing-batchnorm-and-conv/
# Fuse
Conv2d() and BatchNorm2d()
layers https://tehnokv.com/posts/fusing-batchnorm-and-conv/
fusedconv
=
nn
.
Conv2d
(
conv
.
in_channels
,
conv
.
out_channels
,
kernel_size
=
conv
.
kernel_size
,
...
...
@@ -214,12 +212,12 @@ def fuse_conv_and_bn(conv, bn):
groups
=
conv
.
groups
,
bias
=
True
)
.
requires_grad_
(
False
)
.
to
(
conv
.
weight
.
device
)
#
p
repare filters
#
P
repare filters
w_conv
=
conv
.
weight
.
clone
()
.
view
(
conv
.
out_channels
,
-
1
)
w_bn
=
torch
.
diag
(
bn
.
weight
.
div
(
torch
.
sqrt
(
bn
.
eps
+
bn
.
running_var
)))
fusedconv
.
weight
.
copy_
(
torch
.
mm
(
w_bn
,
w_conv
)
.
view
(
fusedconv
.
weight
.
shape
))
#
p
repare spatial bias
#
P
repare spatial bias
b_conv
=
torch
.
zeros
(
conv
.
weight
.
size
(
0
),
device
=
conv
.
weight
.
device
)
if
conv
.
bias
is
None
else
conv
.
bias
b_bn
=
bn
.
bias
-
bn
.
weight
.
mul
(
bn
.
running_mean
)
.
div
(
torch
.
sqrt
(
bn
.
running_var
+
bn
.
eps
))
fusedconv
.
bias
.
copy_
(
torch
.
mm
(
w_bn
,
b_conv
.
reshape
(
-
1
,
1
))
.
reshape
(
-
1
)
+
b_bn
)
...
...
@@ -252,7 +250,7 @@ def model_info(model, verbose=False, img_size=640):
def
scale_img
(
img
,
ratio
=
1.0
,
same_shape
=
False
,
gs
=
32
):
# img(16,3,256,416)
#
s
cales img(bs,3,y,x) by ratio constrained to gs-multiple
#
S
cales img(bs,3,y,x) by ratio constrained to gs-multiple
if
ratio
==
1.0
:
return
img
else
:
...
...
@@ -302,13 +300,13 @@ class ModelEMA:
For EMA details see https://www.tensorflow.org/api_docs/python/tf/train/ExponentialMovingAverage
"""
def
__init__
(
self
,
model
,
decay
=
0.9999
,
updates
=
0
):
def
__init__
(
self
,
model
,
decay
=
0.9999
,
tau
=
2000
,
updates
=
0
):
# Create EMA
self
.
ema
=
deepcopy
(
de_parallel
(
model
))
.
eval
()
# FP32 EMA
# if next(model.parameters()).device.type != 'cpu':
# self.ema.half() # FP16 EMA
self
.
updates
=
updates
# number of EMA updates
self
.
decay
=
lambda
x
:
decay
*
(
1
-
math
.
exp
(
-
x
/
2000
))
# decay exponential ramp (to help early epochs)
self
.
decay
=
lambda
x
:
decay
*
(
1
-
math
.
exp
(
-
x
/
tau
))
# decay exponential ramp (to help early epochs)
for
p
in
self
.
ema
.
parameters
():
p
.
requires_grad_
(
False
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论