Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Y
yolov5
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
Administrator
yolov5
Commits
b6ed1104
Unverified
提交
b6ed1104
authored
11月 30, 2020
作者:
Glenn Jocher
提交者:
GitHub
11月 30, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Daemon thread plotting (#1561)
* Daemon thread plotting * remove process_batch * plot after print
上级
68211f72
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
25 行增加
和
19 行删除
+25
-19
test.py
test.py
+12
-11
train.py
train.py
+5
-5
plots.py
utils/plots.py
+8
-3
没有找到文件。
test.py
浏览文件 @
b6ed1104
...
...
@@ -3,6 +3,7 @@ import glob
import
json
import
os
from
pathlib
import
Path
from
threading
import
Thread
import
numpy
as
np
import
torch
...
...
@@ -206,10 +207,10 @@ def test(data,
# Plot images
if
plots
and
batch_i
<
3
:
f
=
save_dir
/
f
'test_batch{batch_i}_labels.jpg'
#
filename
plot_images
(
img
,
targets
,
paths
,
f
,
names
)
# labels
f
=
save_dir
/
f
'test_batch{batch_i}_pred.jpg'
plot_images
(
img
,
output_to_target
(
output
),
paths
,
f
,
names
)
# predictions
f
=
save_dir
/
f
'test_batch{batch_i}_labels.jpg'
#
labels
Thread
(
target
=
plot_images
,
args
=
(
img
,
targets
,
paths
,
f
,
names
),
daemon
=
True
)
.
start
()
f
=
save_dir
/
f
'test_batch{batch_i}_pred.jpg'
# predictions
Thread
(
target
=
plot_images
,
args
=
(
img
,
output_to_target
(
output
),
paths
,
f
,
names
),
daemon
=
True
)
.
start
()
# Compute statistics
stats
=
[
np
.
concatenate
(
x
,
0
)
for
x
in
zip
(
*
stats
)]
# to numpy
...
...
@@ -221,13 +222,6 @@ def test(data,
else
:
nt
=
torch
.
zeros
(
1
)
# Plots
if
plots
:
confusion_matrix
.
plot
(
save_dir
=
save_dir
,
names
=
list
(
names
.
values
()))
if
wandb
and
wandb
.
run
:
wandb
.
log
({
"Images"
:
wandb_images
})
wandb
.
log
({
"Validation"
:
[
wandb
.
Image
(
str
(
f
),
caption
=
f
.
name
)
for
f
in
sorted
(
save_dir
.
glob
(
'test*.jpg'
))]})
# Print results
pf
=
'
%20
s'
+
'
%12.3
g'
*
6
# print format
print
(
pf
%
(
'all'
,
seen
,
nt
.
sum
(),
mp
,
mr
,
map50
,
map
))
...
...
@@ -242,6 +236,13 @@ def test(data,
if
not
training
:
print
(
'Speed:
%.1
f/
%.1
f/
%.1
f ms inference/NMS/total per
%
gx
%
g image at batch-size
%
g'
%
t
)
# Plots
if
plots
:
confusion_matrix
.
plot
(
save_dir
=
save_dir
,
names
=
list
(
names
.
values
()))
if
wandb
and
wandb
.
run
:
wandb
.
log
({
"Images"
:
wandb_images
})
wandb
.
log
({
"Validation"
:
[
wandb
.
Image
(
str
(
f
),
caption
=
f
.
name
)
for
f
in
sorted
(
save_dir
.
glob
(
'test*.jpg'
))]})
# Save JSON
if
save_json
and
len
(
jdict
):
w
=
Path
(
weights
[
0
]
if
isinstance
(
weights
,
list
)
else
weights
)
.
stem
if
weights
is
not
None
else
''
# weights
...
...
train.py
浏览文件 @
b6ed1104
import
argparse
import
logging
import
math
import
os
import
random
import
time
from
pathlib
import
Path
from
threading
import
Thread
from
warnings
import
warn
import
math
import
numpy
as
np
import
torch.distributed
as
dist
import
torch.nn
as
nn
...
...
@@ -134,6 +135,7 @@ def train(hyp, opt, device, tb_writer=None, wandb=None):
project
=
'YOLOv5'
if
opt
.
project
==
'runs/train'
else
Path
(
opt
.
project
)
.
stem
,
name
=
save_dir
.
stem
,
id
=
ckpt
.
get
(
'wandb_id'
)
if
'ckpt'
in
locals
()
else
None
)
loggers
=
{
'wandb'
:
wandb
}
# loggers dict
# Resume
start_epoch
,
best_fitness
=
0
,
0.0
...
...
@@ -201,11 +203,9 @@ def train(hyp, opt, device, tb_writer=None, wandb=None):
# cf = torch.bincount(c.long(), minlength=nc) + 1. # frequency
# model._initialize_biases(cf.to(device))
if
plots
:
plot_labels
(
labels
,
save_dir
=
save_dir
)
Thread
(
target
=
plot_labels
,
args
=
(
labels
,
save_dir
,
loggers
),
daemon
=
True
)
.
start
(
)
if
tb_writer
:
tb_writer
.
add_histogram
(
'classes'
,
c
,
0
)
if
wandb
:
wandb
.
log
({
"Labels"
:
[
wandb
.
Image
(
str
(
x
),
caption
=
x
.
name
)
for
x
in
save_dir
.
glob
(
'*labels*.png'
)]})
# Anchors
if
not
opt
.
noautoanchor
:
...
...
@@ -311,7 +311,7 @@ def train(hyp, opt, device, tb_writer=None, wandb=None):
# Plot
if
plots
and
ni
<
3
:
f
=
save_dir
/
f
'train_batch{ni}.jpg'
# filename
plot_images
(
images
=
imgs
,
targets
=
targets
,
paths
=
paths
,
fname
=
f
)
Thread
(
target
=
plot_images
,
args
=
(
imgs
,
targets
,
paths
,
f
),
daemon
=
True
)
.
start
(
)
# if tb_writer:
# tb_writer.add_image(f, result, dataformats='HWC', global_step=epoch)
# tb_writer.add_graph(model, imgs) # add model to tensorboard
...
...
utils/plots.py
浏览文件 @
b6ed1104
...
...
@@ -250,7 +250,7 @@ def plot_study_txt(path='', x=None): # from utils.plots import *; plot_study_tx
plt
.
savefig
(
'test_study.png'
,
dpi
=
300
)
def
plot_labels
(
labels
,
save_dir
=
''
):
def
plot_labels
(
labels
,
save_dir
=
Path
(
''
),
loggers
=
None
):
# plot dataset labels
c
,
b
=
labels
[:,
0
],
labels
[:,
1
:]
.
transpose
()
# classes, boxes
nc
=
int
(
c
.
max
()
+
1
)
# number of classes
...
...
@@ -264,7 +264,7 @@ def plot_labels(labels, save_dir=''):
sns
.
pairplot
(
x
,
corner
=
True
,
diag_kind
=
'hist'
,
kind
=
'scatter'
,
markers
=
'o'
,
plot_kws
=
dict
(
s
=
3
,
edgecolor
=
None
,
linewidth
=
1
,
alpha
=
0.02
),
diag_kws
=
dict
(
bins
=
50
))
plt
.
savefig
(
Path
(
save_dir
)
/
'labels_correlogram.png'
,
dpi
=
200
)
plt
.
savefig
(
save_dir
/
'labels_correlogram.png'
,
dpi
=
200
)
plt
.
close
()
except
Exception
as
e
:
pass
...
...
@@ -292,9 +292,14 @@ def plot_labels(labels, save_dir=''):
for
a
in
[
0
,
1
,
2
,
3
]:
for
s
in
[
'top'
,
'right'
,
'left'
,
'bottom'
]:
ax
[
a
]
.
spines
[
s
]
.
set_visible
(
False
)
plt
.
savefig
(
Path
(
save_dir
)
/
'labels.png'
,
dpi
=
200
)
plt
.
savefig
(
save_dir
/
'labels.png'
,
dpi
=
200
)
plt
.
close
()
# loggers
for
k
,
v
in
loggers
.
items
()
or
{}:
if
k
==
'wandb'
and
v
:
v
.
log
({
"Labels"
:
[
v
.
Image
(
str
(
x
),
caption
=
x
.
name
)
for
x
in
save_dir
.
glob
(
'*labels*.png'
)]})
def
plot_evolution
(
yaml_file
=
'data/hyp.finetune.yaml'
):
# from utils.plots import *; plot_evolution()
# Plot hyperparameter evolution results in evolve.txt
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论