Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Y
yolov5
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
Administrator
yolov5
Commits
c1a2a7a4
提交
c1a2a7a4
authored
8月 02, 2020
作者:
Glenn Jocher
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
hyperparameter evolution bug fix (#566)
上级
80747459
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
18 行增加
和
14 行删除
+18
-14
train.py
train.py
+2
-2
utils.py
utils/utils.py
+16
-12
没有找到文件。
train.py
浏览文件 @
c1a2a7a4
...
@@ -465,7 +465,7 @@ if __name__ == '__main__':
...
@@ -465,7 +465,7 @@ if __name__ == '__main__':
# Evolve hyperparameters (optional)
# Evolve hyperparameters (optional)
else
:
else
:
# Hyperparameter evolution metadata (mutation scale 0-1, lower_limit, upper_limit)
# Hyperparameter evolution metadata (mutation scale 0-1, lower_limit, upper_limit)
meta
=
{
'lr0'
:
(
1
,
1e-5
,
1e-
2
),
# initial learning rate (SGD=1E-2, Adam=1E-3)
meta
=
{
'lr0'
:
(
1
,
1e-5
,
1e-
1
),
# initial learning rate (SGD=1E-2, Adam=1E-3)
'momentum'
:
(
0.1
,
0.6
,
0.98
),
# SGD momentum/Adam beta1
'momentum'
:
(
0.1
,
0.6
,
0.98
),
# SGD momentum/Adam beta1
'weight_decay'
:
(
1
,
0.0
,
0.001
),
# optimizer weight decay
'weight_decay'
:
(
1
,
0.0
,
0.001
),
# optimizer weight decay
'giou'
:
(
1
,
0.02
,
0.2
),
# GIoU loss gain
'giou'
:
(
1
,
0.02
,
0.2
),
# GIoU loss gain
...
@@ -534,6 +534,6 @@ if __name__ == '__main__':
...
@@ -534,6 +534,6 @@ if __name__ == '__main__':
print_mutation
(
hyp
.
copy
(),
results
,
yaml_file
,
opt
.
bucket
)
print_mutation
(
hyp
.
copy
(),
results
,
yaml_file
,
opt
.
bucket
)
# Plot results
# Plot results
plot_evolution
_results
(
yaml_file
)
plot_evolution
(
yaml_file
)
print
(
'Hyperparameter evolution complete. Best results saved as:
%
s
\n
Command to train a new model with these '
print
(
'Hyperparameter evolution complete. Best results saved as:
%
s
\n
Command to train a new model with these '
'hyperparameters: $ python train.py --hyp
%
s'
%
(
yaml_file
,
yaml_file
))
'hyperparameters: $ python train.py --hyp
%
s'
%
(
yaml_file
,
yaml_file
))
utils/utils.py
浏览文件 @
c1a2a7a4
...
@@ -919,6 +919,15 @@ def increment_dir(dir, comment=''):
...
@@ -919,6 +919,15 @@ def increment_dir(dir, comment=''):
# Plotting functions ---------------------------------------------------------------------------------------------------
# Plotting functions ---------------------------------------------------------------------------------------------------
def
hist2d
(
x
,
y
,
n
=
100
):
# 2d histogram used in labels.png and evolve.png
xedges
,
yedges
=
np
.
linspace
(
x
.
min
(),
x
.
max
(),
n
),
np
.
linspace
(
y
.
min
(),
y
.
max
(),
n
)
hist
,
xedges
,
yedges
=
np
.
histogram2d
(
x
,
y
,
(
xedges
,
yedges
))
xidx
=
np
.
clip
(
np
.
digitize
(
x
,
xedges
)
-
1
,
0
,
hist
.
shape
[
0
]
-
1
)
yidx
=
np
.
clip
(
np
.
digitize
(
y
,
yedges
)
-
1
,
0
,
hist
.
shape
[
1
]
-
1
)
return
np
.
log
(
hist
[
xidx
,
yidx
])
def
butter_lowpass_filtfilt
(
data
,
cutoff
=
1500
,
fs
=
50000
,
order
=
5
):
def
butter_lowpass_filtfilt
(
data
,
cutoff
=
1500
,
fs
=
50000
,
order
=
5
):
# https://stackoverflow.com/questions/28536191/how-to-filter-smooth-with-scipy-numpy
# https://stackoverflow.com/questions/28536191/how-to-filter-smooth-with-scipy-numpy
def
butter_lowpass
(
cutoff
,
fs
,
order
):
def
butter_lowpass
(
cutoff
,
fs
,
order
):
...
@@ -1130,13 +1139,6 @@ def plot_study_txt(f='study.txt', x=None): # from utils.utils import *; plot_st
...
@@ -1130,13 +1139,6 @@ def plot_study_txt(f='study.txt', x=None): # from utils.utils import *; plot_st
def
plot_labels
(
labels
,
save_dir
=
''
):
def
plot_labels
(
labels
,
save_dir
=
''
):
# plot dataset labels
# plot dataset labels
def
hist2d
(
x
,
y
,
n
=
100
):
xedges
,
yedges
=
np
.
linspace
(
x
.
min
(),
x
.
max
(),
n
),
np
.
linspace
(
y
.
min
(),
y
.
max
(),
n
)
hist
,
xedges
,
yedges
=
np
.
histogram2d
(
x
,
y
,
(
xedges
,
yedges
))
xidx
=
np
.
clip
(
np
.
digitize
(
x
,
xedges
)
-
1
,
0
,
hist
.
shape
[
0
]
-
1
)
yidx
=
np
.
clip
(
np
.
digitize
(
y
,
yedges
)
-
1
,
0
,
hist
.
shape
[
1
]
-
1
)
return
np
.
log
(
hist
[
xidx
,
yidx
])
c
,
b
=
labels
[:,
0
],
labels
[:,
1
:]
.
transpose
()
# classes, boxes
c
,
b
=
labels
[:,
0
],
labels
[:,
1
:]
.
transpose
()
# classes, boxes
nc
=
int
(
c
.
max
()
+
1
)
# number of classes
nc
=
int
(
c
.
max
()
+
1
)
# number of classes
...
@@ -1154,23 +1156,25 @@ def plot_labels(labels, save_dir=''):
...
@@ -1154,23 +1156,25 @@ def plot_labels(labels, save_dir=''):
plt
.
close
()
plt
.
close
()
def
plot_evolution
_results
(
yaml_file
=
'hyp_evolved.yaml'
):
# from utils.utils import *; plot_evolution_results
()
def
plot_evolution
(
yaml_file
=
'runs/evolve/hyp_evolved.yaml'
):
# from utils.utils import *; plot_evolution
()
# Plot hyperparameter evolution results in evolve.txt
# Plot hyperparameter evolution results in evolve.txt
with
open
(
yaml_file
)
as
f
:
with
open
(
yaml_file
)
as
f
:
hyp
=
yaml
.
load
(
f
,
Loader
=
yaml
.
FullLoader
)
hyp
=
yaml
.
load
(
f
,
Loader
=
yaml
.
FullLoader
)
x
=
np
.
loadtxt
(
'evolve.txt'
,
ndmin
=
2
)
x
=
np
.
loadtxt
(
'evolve.txt'
,
ndmin
=
2
)
f
=
fitness
(
x
)
f
=
fitness
(
x
)
# weights = (f - f.min()) ** 2 # for weighted results
# weights = (f - f.min()) ** 2 # for weighted results
plt
.
figure
(
figsize
=
(
1
4
,
10
),
tight_layout
=
True
)
plt
.
figure
(
figsize
=
(
1
0
,
10
),
tight_layout
=
True
)
matplotlib
.
rc
(
'font'
,
**
{
'size'
:
8
})
matplotlib
.
rc
(
'font'
,
**
{
'size'
:
8
})
for
i
,
(
k
,
v
)
in
enumerate
(
hyp
.
items
()):
for
i
,
(
k
,
v
)
in
enumerate
(
hyp
.
items
()):
y
=
x
[:,
i
+
7
]
y
=
x
[:,
i
+
7
]
# mu = (y * weights).sum() / weights.sum() # best weighted result
# mu = (y * weights).sum() / weights.sum() # best weighted result
mu
=
y
[
f
.
argmax
()]
# best single result
mu
=
y
[
f
.
argmax
()]
# best single result
plt
.
subplot
(
4
,
6
,
i
+
1
)
plt
.
subplot
(
5
,
5
,
i
+
1
)
plt
.
plot
(
mu
,
f
.
max
(),
'o'
,
markersize
=
10
)
plt
.
scatter
(
y
,
f
,
c
=
hist2d
(
y
,
f
,
20
),
cmap
=
'viridis'
,
alpha
=.
8
,
edgecolors
=
'none'
)
plt
.
plot
(
y
,
f
,
'.'
)
plt
.
plot
(
mu
,
f
.
max
(),
'k+'
,
markersize
=
15
)
plt
.
title
(
'
%
s =
%.3
g'
%
(
k
,
mu
),
fontdict
=
{
'size'
:
9
})
# limit to 40 characters
plt
.
title
(
'
%
s =
%.3
g'
%
(
k
,
mu
),
fontdict
=
{
'size'
:
9
})
# limit to 40 characters
if
i
%
5
!=
0
:
plt
.
yticks
([])
print
(
'
%15
s:
%.3
g'
%
(
k
,
mu
))
print
(
'
%15
s:
%.3
g'
%
(
k
,
mu
))
plt
.
savefig
(
'evolve.png'
,
dpi
=
200
)
plt
.
savefig
(
'evolve.png'
,
dpi
=
200
)
print
(
'
\n
Plot saved as evolve.png'
)
print
(
'
\n
Plot saved as evolve.png'
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论