Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Y
yolov5
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
Administrator
yolov5
Commits
8b26e890
提交
8b26e890
authored
6月 16, 2020
作者:
Glenn Jocher
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
AutoAnchor bug fix #72
上级
8fa37240
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
7 行增加
和
6 行删除
+7
-6
train.py
train.py
+1
-2
utils.py
utils/utils.py
+6
-4
没有找到文件。
train.py
浏览文件 @
8b26e890
...
@@ -4,7 +4,6 @@ import torch.distributed as dist
...
@@ -4,7 +4,6 @@ import torch.distributed as dist
import
torch.nn.functional
as
F
import
torch.nn.functional
as
F
import
torch.optim
as
optim
import
torch.optim
as
optim
import
torch.optim.lr_scheduler
as
lr_scheduler
import
torch.optim.lr_scheduler
as
lr_scheduler
import
yaml
from
torch.utils.tensorboard
import
SummaryWriter
from
torch.utils.tensorboard
import
SummaryWriter
import
test
# import test.py to get mAP after each epoch
import
test
# import test.py to get mAP after each epoch
...
@@ -200,7 +199,7 @@ def train(hyp):
...
@@ -200,7 +199,7 @@ def train(hyp):
tb_writer
.
add_histogram
(
'classes'
,
c
,
0
)
tb_writer
.
add_histogram
(
'classes'
,
c
,
0
)
# Check anchors
# Check anchors
check_best_possible_recall
(
dataset
,
anchors
=
model
.
model
[
-
1
]
.
anchor_grid
,
thr
=
hyp
[
'anchor_t'
])
check_best_possible_recall
(
dataset
,
anchors
=
model
.
model
[
-
1
]
.
anchor_grid
,
thr
=
hyp
[
'anchor_t'
]
,
imgsz
=
imgsz
)
# Exponential moving average
# Exponential moving average
ema
=
torch_utils
.
ModelEMA
(
model
)
ema
=
torch_utils
.
ModelEMA
(
model
)
...
...
utils/utils.py
浏览文件 @
8b26e890
...
@@ -52,15 +52,17 @@ def check_img_size(img_size, s=32):
...
@@ -52,15 +52,17 @@ def check_img_size(img_size, s=32):
return
make_divisible
(
img_size
,
s
)
# nearest gs-multiple
return
make_divisible
(
img_size
,
s
)
# nearest gs-multiple
def
check_best_possible_recall
(
dataset
,
anchors
,
thr
):
def
check_best_possible_recall
(
dataset
,
anchors
,
thr
=
4.0
,
imgsz
=
640
):
# Check best possible recall of dataset with current anchors
# Check best possible recall of dataset with current anchors
wh
=
torch
.
tensor
(
np
.
concatenate
([
l
[:,
3
:
5
]
*
s
for
s
,
l
in
zip
(
dataset
.
shapes
,
dataset
.
labels
)]))
.
float
()
# wh
shapes
=
imgsz
*
dataset
.
shapes
/
dataset
.
shapes
.
max
(
1
,
keepdims
=
True
)
wh
=
torch
.
tensor
(
np
.
concatenate
([
l
[:,
3
:
5
]
*
s
for
s
,
l
in
zip
(
shapes
,
dataset
.
labels
)]))
.
float
()
# wh
ratio
=
wh
[:,
None
]
/
anchors
.
view
(
-
1
,
2
)
.
cpu
()[
None
]
# ratio
ratio
=
wh
[:,
None
]
/
anchors
.
view
(
-
1
,
2
)
.
cpu
()[
None
]
# ratio
m
=
torch
.
max
(
ratio
,
1.
/
ratio
)
.
max
(
2
)[
0
]
# max ratio
m
=
torch
.
max
(
ratio
,
1.
/
ratio
)
.
max
(
2
)[
0
]
# max ratio
bpr
=
(
m
.
min
(
1
)[
0
]
<
thr
)
.
float
()
.
mean
()
# best possible recall
bpr
=
(
m
.
min
(
1
)[
0
]
<
thr
)
.
float
()
.
mean
()
# best possible recall
mr
=
(
m
<
thr
)
.
float
()
.
mean
()
# match ratio
mr
=
(
m
<
thr
)
.
float
()
.
mean
()
# match ratio
print
((
'Label width-height:'
+
'
%10
s'
*
6
)
%
(
'n'
,
'mean'
,
'min'
,
'max'
,
'matching'
,
'recall'
))
print
((
'AutoAnchor labels:'
+
'
%10
s'
*
6
)
%
(
'n'
,
'mean'
,
'min'
,
'max'
,
'matching'
,
'recall'
))
print
((
' '
+
'
%10.4
g'
*
6
)
%
(
wh
.
shape
[
0
],
wh
.
mean
(),
wh
.
min
(),
wh
.
max
(),
mr
,
bpr
))
print
((
' '
+
'
%10.4
g'
*
6
)
%
(
wh
.
shape
[
0
],
wh
.
mean
(),
wh
.
min
(),
wh
.
max
(),
mr
,
bpr
))
assert
bpr
>
0.9
,
'Best possible recall
%.3
g (BPR) below 0.9 threshold. Training cancelled. '
\
assert
bpr
>
0.9
,
'Best possible recall
%.3
g (BPR) below 0.9 threshold. Training cancelled. '
\
'Compute new anchors with utils.utils.kmeans_anchors() and update model before training.'
%
bpr
'Compute new anchors with utils.utils.kmeans_anchors() and update model before training.'
%
bpr
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论