Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Y
yolov5
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
Administrator
yolov5
Commits
0ada058f
Unverified
提交
0ada058f
authored
10月 11, 2020
作者:
Glenn Jocher
提交者:
GitHub
10月 11, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Generalized regression criterion renaming (#1120)
上级
10c85bf4
隐藏空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
22 行增加
和
22 行删除
+22
-22
hyp.finetune.yaml
data/hyp.finetune.yaml
+1
-1
hyp.scratch.yaml
data/hyp.scratch.yaml
+1
-1
sotabench.py
sotabench.py
+1
-1
test.py
test.py
+1
-1
train.py
train.py
+9
-9
general.py
utils/general.py
+9
-9
没有找到文件。
data/hyp.finetune.yaml
浏览文件 @
0ada058f
...
@@ -15,7 +15,7 @@ weight_decay: 0.00036
...
@@ -15,7 +15,7 @@ weight_decay: 0.00036
warmup_epochs
:
2.0
warmup_epochs
:
2.0
warmup_momentum
:
0.5
warmup_momentum
:
0.5
warmup_bias_lr
:
0.05
warmup_bias_lr
:
0.05
giou
:
0.0296
box
:
0.0296
cls
:
0.243
cls
:
0.243
cls_pw
:
0.631
cls_pw
:
0.631
obj
:
0.301
obj
:
0.301
...
...
data/hyp.scratch.yaml
浏览文件 @
0ada058f
...
@@ -10,7 +10,7 @@ weight_decay: 0.0005 # optimizer weight decay 5e-4
...
@@ -10,7 +10,7 @@ weight_decay: 0.0005 # optimizer weight decay 5e-4
warmup_epochs
:
3.0
# warmup epochs (fractions ok)
warmup_epochs
:
3.0
# warmup epochs (fractions ok)
warmup_momentum
:
0.8
# warmup initial momentum
warmup_momentum
:
0.8
# warmup initial momentum
warmup_bias_lr
:
0.1
# warmup initial bias lr
warmup_bias_lr
:
0.1
# warmup initial bias lr
giou
:
0.05
# box loss gain
box
:
0.05
# box loss gain
cls
:
0.5
# cls loss gain
cls
:
0.5
# cls loss gain
cls_pw
:
1.0
# cls BCELoss positive_weight
cls_pw
:
1.0
# cls BCELoss positive_weight
obj
:
1.0
# obj loss gain (scale with pixels)
obj
:
1.0
# obj loss gain (scale with pixels)
...
...
sotabench.py
浏览文件 @
0ada058f
...
@@ -113,7 +113,7 @@ def test(data,
...
@@ -113,7 +113,7 @@ def test(data,
# Compute loss
# Compute loss
if
training
:
# if model has loss hyperparameters
if
training
:
# if model has loss hyperparameters
loss
+=
compute_loss
([
x
.
float
()
for
x
in
train_out
],
targets
,
model
)[
1
][:
3
]
#
GIoU
, obj, cls
loss
+=
compute_loss
([
x
.
float
()
for
x
in
train_out
],
targets
,
model
)[
1
][:
3
]
#
box
, obj, cls
# Run NMS
# Run NMS
t
=
time_synchronized
()
t
=
time_synchronized
()
...
...
test.py
浏览文件 @
0ada058f
...
@@ -106,7 +106,7 @@ def test(data,
...
@@ -106,7 +106,7 @@ def test(data,
# Compute loss
# Compute loss
if
training
:
# if model has loss hyperparameters
if
training
:
# if model has loss hyperparameters
loss
+=
compute_loss
([
x
.
float
()
for
x
in
train_out
],
targets
,
model
)[
1
][:
3
]
#
GIoU
, obj, cls
loss
+=
compute_loss
([
x
.
float
()
for
x
in
train_out
],
targets
,
model
)[
1
][:
3
]
#
box
, obj, cls
# Run NMS
# Run NMS
t
=
time_synchronized
()
t
=
time_synchronized
()
...
...
train.py
浏览文件 @
0ada058f
...
@@ -195,7 +195,7 @@ def train(hyp, opt, device, tb_writer=None):
...
@@ -195,7 +195,7 @@ def train(hyp, opt, device, tb_writer=None):
hyp
[
'cls'
]
*=
nc
/
80.
# scale coco-tuned hyp['cls'] to current dataset
hyp
[
'cls'
]
*=
nc
/
80.
# scale coco-tuned hyp['cls'] to current dataset
model
.
nc
=
nc
# attach number of classes to model
model
.
nc
=
nc
# attach number of classes to model
model
.
hyp
=
hyp
# attach hyperparameters to model
model
.
hyp
=
hyp
# attach hyperparameters to model
model
.
gr
=
1.0
#
giou loss ratio (obj_loss = 1.0 or g
iou)
model
.
gr
=
1.0
#
iou loss ratio (obj_loss = 1.0 or
iou)
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
=
names
model
.
names
=
names
...
@@ -204,7 +204,7 @@ def train(hyp, opt, device, tb_writer=None):
...
@@ -204,7 +204,7 @@ def train(hyp, opt, device, tb_writer=None):
nw
=
max
(
round
(
hyp
[
'warmup_epochs'
]
*
nb
),
1e3
)
# number of warmup iterations, max(3 epochs, 1k iterations)
nw
=
max
(
round
(
hyp
[
'warmup_epochs'
]
*
nb
),
1e3
)
# number of warmup iterations, max(3 epochs, 1k iterations)
# nw = min(nw, (epochs - start_epoch) / 2 * nb) # limit warmup to < 1/2 of training
# nw = min(nw, (epochs - start_epoch) / 2 * nb) # limit warmup to < 1/2 of training
maps
=
np
.
zeros
(
nc
)
# mAP per class
maps
=
np
.
zeros
(
nc
)
# mAP per class
results
=
(
0
,
0
,
0
,
0
,
0
,
0
,
0
)
#
'P', 'R', 'mAP', 'F1', 'val GIoU', 'val Objectness', 'val Classification'
results
=
(
0
,
0
,
0
,
0
,
0
,
0
,
0
)
#
P, R, mAP@.5, mAP@.5-.95, val_loss(box, obj, cls)
scheduler
.
last_epoch
=
start_epoch
-
1
# do not move
scheduler
.
last_epoch
=
start_epoch
-
1
# do not move
scaler
=
amp
.
GradScaler
(
enabled
=
cuda
)
scaler
=
amp
.
GradScaler
(
enabled
=
cuda
)
logger
.
info
(
'Image sizes
%
g train,
%
g test
\n
Using
%
g dataloader workers
\n
Logging results to
%
s
\n
'
logger
.
info
(
'Image sizes
%
g train,
%
g test
\n
Using
%
g dataloader workers
\n
Logging results to
%
s
\n
'
...
@@ -234,7 +234,7 @@ def train(hyp, opt, device, tb_writer=None):
...
@@ -234,7 +234,7 @@ def train(hyp, opt, device, tb_writer=None):
if
rank
!=
-
1
:
if
rank
!=
-
1
:
dataloader
.
sampler
.
set_epoch
(
epoch
)
dataloader
.
sampler
.
set_epoch
(
epoch
)
pbar
=
enumerate
(
dataloader
)
pbar
=
enumerate
(
dataloader
)
logger
.
info
((
'
\n
'
+
'
%10
s'
*
8
)
%
(
'Epoch'
,
'gpu_mem'
,
'
GIoU
'
,
'obj'
,
'cls'
,
'total'
,
'targets'
,
'img_size'
))
logger
.
info
((
'
\n
'
+
'
%10
s'
*
8
)
%
(
'Epoch'
,
'gpu_mem'
,
'
box
'
,
'obj'
,
'cls'
,
'total'
,
'targets'
,
'img_size'
))
if
rank
in
[
-
1
,
0
]:
if
rank
in
[
-
1
,
0
]:
pbar
=
tqdm
(
pbar
,
total
=
nb
)
# progress bar
pbar
=
tqdm
(
pbar
,
total
=
nb
)
# progress bar
optimizer
.
zero_grad
()
optimizer
.
zero_grad
()
...
@@ -245,7 +245,7 @@ def train(hyp, opt, device, tb_writer=None):
...
@@ -245,7 +245,7 @@ def train(hyp, opt, device, tb_writer=None):
# Warmup
# Warmup
if
ni
<=
nw
:
if
ni
<=
nw
:
xi
=
[
0
,
nw
]
# x interp
xi
=
[
0
,
nw
]
# x interp
# model.gr = np.interp(ni, xi, [0.0, 1.0]) #
giou loss ratio (obj_loss = 1.0 or g
iou)
# model.gr = np.interp(ni, xi, [0.0, 1.0]) #
iou loss ratio (obj_loss = 1.0 or
iou)
accumulate
=
max
(
1
,
np
.
interp
(
ni
,
xi
,
[
1
,
nbs
/
total_batch_size
])
.
round
())
accumulate
=
max
(
1
,
np
.
interp
(
ni
,
xi
,
[
1
,
nbs
/
total_batch_size
])
.
round
())
for
j
,
x
in
enumerate
(
optimizer
.
param_groups
):
for
j
,
x
in
enumerate
(
optimizer
.
param_groups
):
# bias lr falls from 0.1 to lr0, all other lrs rise from 0.0 to lr0
# bias lr falls from 0.1 to lr0, all other lrs rise from 0.0 to lr0
...
@@ -319,21 +319,21 @@ def train(hyp, opt, device, tb_writer=None):
...
@@ -319,21 +319,21 @@ def train(hyp, opt, device, tb_writer=None):
# Write
# Write
with
open
(
results_file
,
'a'
)
as
f
:
with
open
(
results_file
,
'a'
)
as
f
:
f
.
write
(
s
+
'
%10.4
g'
*
7
%
results
+
'
\n
'
)
# P, R, mAP
, F1, test_losses=(GIoU
, obj, cls)
f
.
write
(
s
+
'
%10.4
g'
*
7
%
results
+
'
\n
'
)
# P, R, mAP
@.5, mAP@.5-.95, val_loss(box
, obj, cls)
if
len
(
opt
.
name
)
and
opt
.
bucket
:
if
len
(
opt
.
name
)
and
opt
.
bucket
:
os
.
system
(
'gsutil cp
%
s gs://
%
s/results/results
%
s.txt'
%
(
results_file
,
opt
.
bucket
,
opt
.
name
))
os
.
system
(
'gsutil cp
%
s gs://
%
s/results/results
%
s.txt'
%
(
results_file
,
opt
.
bucket
,
opt
.
name
))
# Tensorboard
# Tensorboard
if
tb_writer
:
if
tb_writer
:
tags
=
[
'train/
giou
_loss'
,
'train/obj_loss'
,
'train/cls_loss'
,
# train loss
tags
=
[
'train/
box
_loss'
,
'train/obj_loss'
,
'train/cls_loss'
,
# train loss
'metrics/precision'
,
'metrics/recall'
,
'metrics/mAP_0.5'
,
'metrics/mAP_0.5:0.95'
,
'metrics/precision'
,
'metrics/recall'
,
'metrics/mAP_0.5'
,
'metrics/mAP_0.5:0.95'
,
'val/
giou
_loss'
,
'val/obj_loss'
,
'val/cls_loss'
,
# val loss
'val/
box
_loss'
,
'val/obj_loss'
,
'val/cls_loss'
,
# val loss
'x/lr0'
,
'x/lr1'
,
'x/lr2'
]
# params
'x/lr0'
,
'x/lr1'
,
'x/lr2'
]
# params
for
x
,
tag
in
zip
(
list
(
mloss
[:
-
1
])
+
list
(
results
)
+
lr
,
tags
):
for
x
,
tag
in
zip
(
list
(
mloss
[:
-
1
])
+
list
(
results
)
+
lr
,
tags
):
tb_writer
.
add_scalar
(
tag
,
x
,
epoch
)
tb_writer
.
add_scalar
(
tag
,
x
,
epoch
)
# Update best mAP
# Update best mAP
fi
=
fitness
(
np
.
array
(
results
)
.
reshape
(
1
,
-
1
))
#
fitness_i = weighted combination of [P, R, mAP, F1
]
fi
=
fitness
(
np
.
array
(
results
)
.
reshape
(
1
,
-
1
))
#
weighted combination of [P, R, mAP@.5, mAP@.5-.95
]
if
fi
>
best_fitness
:
if
fi
>
best_fitness
:
best_fitness
=
fi
best_fitness
=
fi
...
@@ -463,7 +463,7 @@ if __name__ == '__main__':
...
@@ -463,7 +463,7 @@ if __name__ == '__main__':
'warmup_epochs'
:
(
1
,
0.0
,
5.0
),
# warmup epochs (fractions ok)
'warmup_epochs'
:
(
1
,
0.0
,
5.0
),
# warmup epochs (fractions ok)
'warmup_momentum'
:
(
1
,
0.0
,
0.95
),
# warmup initial momentum
'warmup_momentum'
:
(
1
,
0.0
,
0.95
),
# warmup initial momentum
'warmup_bias_lr'
:
(
1
,
0.0
,
0.2
),
# warmup initial bias lr
'warmup_bias_lr'
:
(
1
,
0.0
,
0.2
),
# warmup initial bias lr
'
giou'
:
(
1
,
0.02
,
0.2
),
# GIoU
loss gain
'
box'
:
(
1
,
0.02
,
0.2
),
# box
loss gain
'cls'
:
(
1
,
0.2
,
4.0
),
# cls loss gain
'cls'
:
(
1
,
0.2
,
4.0
),
# cls loss gain
'cls_pw'
:
(
1
,
0.5
,
2.0
),
# cls BCELoss positive_weight
'cls_pw'
:
(
1
,
0.5
,
2.0
),
# cls BCELoss positive_weight
'obj'
:
(
1
,
0.2
,
4.0
),
# obj loss gain (scale with pixels)
'obj'
:
(
1
,
0.2
,
4.0
),
# obj loss gain (scale with pixels)
...
...
utils/general.py
浏览文件 @
0ada058f
...
@@ -509,11 +509,11 @@ def compute_loss(p, targets, model): # predictions, targets, model
...
@@ -509,11 +509,11 @@ def compute_loss(p, targets, model): # predictions, targets, model
pxy
=
ps
[:,
:
2
]
.
sigmoid
()
*
2.
-
0.5
pxy
=
ps
[:,
:
2
]
.
sigmoid
()
*
2.
-
0.5
pwh
=
(
ps
[:,
2
:
4
]
.
sigmoid
()
*
2
)
**
2
*
anchors
[
i
]
pwh
=
(
ps
[:,
2
:
4
]
.
sigmoid
()
*
2
)
**
2
*
anchors
[
i
]
pbox
=
torch
.
cat
((
pxy
,
pwh
),
1
)
.
to
(
device
)
# predicted box
pbox
=
torch
.
cat
((
pxy
,
pwh
),
1
)
.
to
(
device
)
# predicted box
giou
=
bbox_iou
(
pbox
.
T
,
tbox
[
i
],
x1y1x2y2
=
False
,
CIoU
=
True
)
# g
iou(prediction, target)
iou
=
bbox_iou
(
pbox
.
T
,
tbox
[
i
],
x1y1x2y2
=
False
,
CIoU
=
True
)
#
iou(prediction, target)
lbox
+=
(
1.0
-
giou
)
.
mean
()
# g
iou loss
lbox
+=
(
1.0
-
iou
)
.
mean
()
#
iou loss
# Objectness
# Objectness
tobj
[
b
,
a
,
gj
,
gi
]
=
(
1.0
-
model
.
gr
)
+
model
.
gr
*
giou
.
detach
()
.
clamp
(
0
)
.
type
(
tobj
.
dtype
)
# g
iou ratio
tobj
[
b
,
a
,
gj
,
gi
]
=
(
1.0
-
model
.
gr
)
+
model
.
gr
*
iou
.
detach
()
.
clamp
(
0
)
.
type
(
tobj
.
dtype
)
#
iou ratio
# Classification
# Classification
if
model
.
nc
>
1
:
# cls loss (only if multiple classes)
if
model
.
nc
>
1
:
# cls loss (only if multiple classes)
...
@@ -528,7 +528,7 @@ def compute_loss(p, targets, model): # predictions, targets, model
...
@@ -528,7 +528,7 @@ def compute_loss(p, targets, model): # predictions, targets, model
lobj
+=
BCEobj
(
pi
[
...
,
4
],
tobj
)
*
balance
[
i
]
# obj loss
lobj
+=
BCEobj
(
pi
[
...
,
4
],
tobj
)
*
balance
[
i
]
# obj loss
s
=
3
/
np
# output count scaling
s
=
3
/
np
# output count scaling
lbox
*=
h
[
'
giou
'
]
*
s
lbox
*=
h
[
'
box
'
]
*
s
lobj
*=
h
[
'obj'
]
*
s
*
(
1.4
if
np
==
4
else
1.
)
lobj
*=
h
[
'obj'
]
*
s
*
(
1.4
if
np
==
4
else
1.
)
lcls
*=
h
[
'cls'
]
*
s
lcls
*=
h
[
'cls'
]
*
s
bs
=
tobj
.
shape
[
0
]
# batch size
bs
=
tobj
.
shape
[
0
]
# batch size
...
@@ -1234,7 +1234,7 @@ def plot_evolution(yaml_file='data/hyp.finetune.yaml'): # from utils.general im
...
@@ -1234,7 +1234,7 @@ def plot_evolution(yaml_file='data/hyp.finetune.yaml'): # from utils.general im
def
plot_results_overlay
(
start
=
0
,
stop
=
0
):
# from utils.general import *; plot_results_overlay()
def
plot_results_overlay
(
start
=
0
,
stop
=
0
):
# from utils.general import *; plot_results_overlay()
# Plot training 'results*.txt', overlaying train and val losses
# Plot training 'results*.txt', overlaying train and val losses
s
=
[
'train'
,
'train'
,
'train'
,
'Precision'
,
'mAP@0.5'
,
'val'
,
'val'
,
'val'
,
'Recall'
,
'mAP@0.5:0.95'
]
# legends
s
=
[
'train'
,
'train'
,
'train'
,
'Precision'
,
'mAP@0.5'
,
'val'
,
'val'
,
'val'
,
'Recall'
,
'mAP@0.5:0.95'
]
# legends
t
=
[
'
GIoU
'
,
'Objectness'
,
'Classification'
,
'P-R'
,
'mAP-F1'
]
# titles
t
=
[
'
Box
'
,
'Objectness'
,
'Classification'
,
'P-R'
,
'mAP-F1'
]
# titles
for
f
in
sorted
(
glob
.
glob
(
'results*.txt'
)
+
glob
.
glob
(
'../../Downloads/results*.txt'
)):
for
f
in
sorted
(
glob
.
glob
(
'results*.txt'
)
+
glob
.
glob
(
'../../Downloads/results*.txt'
)):
results
=
np
.
loadtxt
(
f
,
usecols
=
[
2
,
3
,
4
,
8
,
9
,
12
,
13
,
14
,
10
,
11
],
ndmin
=
2
)
.
T
results
=
np
.
loadtxt
(
f
,
usecols
=
[
2
,
3
,
4
,
8
,
9
,
12
,
13
,
14
,
10
,
11
],
ndmin
=
2
)
.
T
n
=
results
.
shape
[
1
]
# number of rows
n
=
results
.
shape
[
1
]
# number of rows
...
@@ -1254,13 +1254,13 @@ def plot_results_overlay(start=0, stop=0): # from utils.general import *; plot_
...
@@ -1254,13 +1254,13 @@ def plot_results_overlay(start=0, stop=0): # from utils.general import *; plot_
fig
.
savefig
(
f
.
replace
(
'.txt'
,
'.png'
),
dpi
=
200
)
fig
.
savefig
(
f
.
replace
(
'.txt'
,
'.png'
),
dpi
=
200
)
def
plot_results
(
start
=
0
,
stop
=
0
,
bucket
=
''
,
id
=
(),
labels
=
(),
def
plot_results
(
start
=
0
,
stop
=
0
,
bucket
=
''
,
id
=
(),
labels
=
(),
save_dir
=
''
):
save_dir
=
''
):
# from utils.general import *; plot_results()
# from utils.general import *; plot_results()
# Plot training 'results*.txt' as seen in https://github.com/ultralytics/yolov5#reproduce-our-training
# Plot training 'results*.txt' as seen in https://github.com/ultralytics/yolov5#reproduce-our-training
fig
,
ax
=
plt
.
subplots
(
2
,
5
,
figsize
=
(
12
,
6
))
fig
,
ax
=
plt
.
subplots
(
2
,
5
,
figsize
=
(
12
,
6
))
ax
=
ax
.
ravel
()
ax
=
ax
.
ravel
()
s
=
[
'
GIoU
'
,
'Objectness'
,
'Classification'
,
'Precision'
,
'Recall'
,
s
=
[
'
Box
'
,
'Objectness'
,
'Classification'
,
'Precision'
,
'Recall'
,
'val
GIoU
'
,
'val Objectness'
,
'val Classification'
,
'mAP@0.5'
,
'mAP@0.5:0.95'
]
'val
Box
'
,
'val Objectness'
,
'val Classification'
,
'mAP@0.5'
,
'mAP@0.5:0.95'
]
if
bucket
:
if
bucket
:
# os.system('rm -rf storage.googleapis.com')
# os.system('rm -rf storage.googleapis.com')
# files = ['https://storage.googleapis.com/%s/results%g.txt' % (bucket, x) for x in id]
# files = ['https://storage.googleapis.com/%s/results%g.txt' % (bucket, x) for x in id]
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论