Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Y
yolov5
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
Administrator
yolov5
Commits
31f33100
提交
31f33100
authored
6月 13, 2020
作者:
Glenn Jocher
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
assert best possible recall > 0.9 before training
上级
19e68e8a
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
22 行增加
和
4 行删除
+22
-4
train.py
train.py
+4
-1
datasets.py
utils/datasets.py
+5
-3
utils.py
utils/utils.py
+13
-0
没有找到文件。
train.py
浏览文件 @
31f33100
...
@@ -191,7 +191,7 @@ def train(hyp):
...
@@ -191,7 +191,7 @@ def train(hyp):
model
.
class_weights
=
labels_to_class_weights
(
dataset
.
labels
,
nc
)
.
to
(
device
)
# attach class weights
model
.
class_weights
=
labels_to_class_weights
(
dataset
.
labels
,
nc
)
.
to
(
device
)
# attach class weights
model
.
names
=
data_dict
[
'names'
]
model
.
names
=
data_dict
[
'names'
]
#
c
lass frequency
#
C
lass frequency
labels
=
np
.
concatenate
(
dataset
.
labels
,
0
)
labels
=
np
.
concatenate
(
dataset
.
labels
,
0
)
c
=
torch
.
tensor
(
labels
[:,
0
])
# classes
c
=
torch
.
tensor
(
labels
[:,
0
])
# classes
# cf = torch.bincount(c.long(), minlength=nc) + 1.
# cf = torch.bincount(c.long(), minlength=nc) + 1.
...
@@ -199,6 +199,9 @@ def train(hyp):
...
@@ -199,6 +199,9 @@ def train(hyp):
plot_labels
(
labels
)
plot_labels
(
labels
)
tb_writer
.
add_histogram
(
'classes'
,
c
,
0
)
tb_writer
.
add_histogram
(
'classes'
,
c
,
0
)
# Check anchors
check_best_possible_recall
(
dataset
,
anchors
=
model
.
model
[
-
1
]
.
anchor_grid
,
thr
=
hyp
[
'anchor_t'
])
# Exponential moving average
# Exponential moving average
ema
=
torch_utils
.
ModelEMA
(
model
)
ema
=
torch_utils
.
ModelEMA
(
model
)
...
...
utils/datasets.py
浏览文件 @
31f33100
...
@@ -291,8 +291,6 @@ class LoadImagesAndLabels(Dataset): # for training/testing
...
@@ -291,8 +291,6 @@ class LoadImagesAndLabels(Dataset): # for training/testing
self
.
label_files
=
[
x
.
replace
(
'images'
,
'labels'
)
.
replace
(
os
.
path
.
splitext
(
x
)[
-
1
],
'.txt'
)
self
.
label_files
=
[
x
.
replace
(
'images'
,
'labels'
)
.
replace
(
os
.
path
.
splitext
(
x
)[
-
1
],
'.txt'
)
for
x
in
self
.
img_files
]
for
x
in
self
.
img_files
]
# Rectangular Training https://github.com/ultralytics/yolov3/issues/232
if
self
.
rect
:
# Read image shapes (wh)
# Read image shapes (wh)
sp
=
path
.
replace
(
'.txt'
,
''
)
+
'.shapes'
# shapefile path
sp
=
path
.
replace
(
'.txt'
,
''
)
+
'.shapes'
# shapefile path
try
:
try
:
...
@@ -303,8 +301,12 @@ class LoadImagesAndLabels(Dataset): # for training/testing
...
@@ -303,8 +301,12 @@ class LoadImagesAndLabels(Dataset): # for training/testing
s
=
[
exif_size
(
Image
.
open
(
f
))
for
f
in
tqdm
(
self
.
img_files
,
desc
=
'Reading image shapes'
)]
s
=
[
exif_size
(
Image
.
open
(
f
))
for
f
in
tqdm
(
self
.
img_files
,
desc
=
'Reading image shapes'
)]
np
.
savetxt
(
sp
,
s
,
fmt
=
'
%
g'
)
# overwrites existing (if any)
np
.
savetxt
(
sp
,
s
,
fmt
=
'
%
g'
)
# overwrites existing (if any)
self
.
shapes
=
np
.
array
(
s
,
dtype
=
np
.
float64
)
# Rectangular Training https://github.com/ultralytics/yolov3/issues/232
if
self
.
rect
:
# Sort by aspect ratio
# Sort by aspect ratio
s
=
np
.
array
(
s
,
dtype
=
np
.
float64
)
s
=
self
.
shapes
# wh
ar
=
s
[:,
1
]
/
s
[:,
0
]
# aspect ratio
ar
=
s
[:,
1
]
/
s
[:,
0
]
# aspect ratio
irect
=
ar
.
argsort
()
irect
=
ar
.
argsort
()
self
.
img_files
=
[
self
.
img_files
[
i
]
for
i
in
irect
]
self
.
img_files
=
[
self
.
img_files
[
i
]
for
i
in
irect
]
...
...
utils/utils.py
浏览文件 @
31f33100
...
@@ -51,6 +51,19 @@ def check_img_size(img_size, s=32):
...
@@ -51,6 +51,19 @@ 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
):
# 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
)]))
# width-height
ratio
=
wh
[:,
None
]
/
anchors
.
view
(
-
1
,
2
)[
None
]
# ratio
m
=
torch
.
max
(
ratio
,
1.
/
ratio
)
.
max
(
2
)[
0
]
# max ratio
bpr
=
(
m
.
min
(
1
)[
0
]
<
thr
)
.
float
()
.
mean
()
# best possible recall
mr
=
(
m
<
thr
)
.
float
()
.
mean
()
# match ratio
print
((
'Label width-height:'
+
'
%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
))
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
def
make_divisible
(
x
,
divisor
):
def
make_divisible
(
x
,
divisor
):
# Returns x evenly divisble by divisor
# Returns x evenly divisble by divisor
return
math
.
ceil
(
x
/
divisor
)
*
divisor
return
math
.
ceil
(
x
/
divisor
)
*
divisor
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论