Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Y
yolov5
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
Administrator
yolov5
Commits
95fa6533
Unverified
提交
95fa6533
authored
11月 23, 2020
作者:
Glenn Jocher
提交者:
GitHub
11月 23, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Cat apriori to autolabels (#1484)
上级
201bafc7
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
20 行增加
和
8 行删除
+20
-8
detect.py
detect.py
+2
-1
test.py
test.py
+7
-6
general.py
utils/general.py
+11
-1
没有找到文件。
detect.py
浏览文件 @
95fa6533
...
@@ -137,7 +137,8 @@ def detect(save_img=False):
...
@@ -137,7 +137,8 @@ def detect(save_img=False):
vid_writer
.
write
(
im0
)
vid_writer
.
write
(
im0
)
if
save_txt
or
save_img
:
if
save_txt
or
save_img
:
print
(
'Results saved to
%
s'
%
save_dir
)
s
=
f
"
\n
{len(list(save_dir.glob('labels/*.txt')))} labels saved to {save_dir / 'labels'}"
if
save_txt
else
''
print
(
f
"Results saved to {save_dir}{s}"
)
print
(
'Done. (
%.3
fs)'
%
(
time
.
time
()
-
t0
))
print
(
'Done. (
%.3
fs)'
%
(
time
.
time
()
-
t0
))
...
...
test.py
浏览文件 @
95fa6533
...
@@ -101,9 +101,8 @@ def test(data,
...
@@ -101,9 +101,8 @@ def test(data,
img
/=
255.0
# 0 - 255 to 0.0 - 1.0
img
/=
255.0
# 0 - 255 to 0.0 - 1.0
targets
=
targets
.
to
(
device
)
targets
=
targets
.
to
(
device
)
nb
,
_
,
height
,
width
=
img
.
shape
# batch size, channels, height, width
nb
,
_
,
height
,
width
=
img
.
shape
# batch size, channels, height, width
whwh
=
torch
.
Tensor
([
width
,
height
,
width
,
height
])
.
to
(
device
)
targets
[:,
2
:]
*
=
torch
.
Tensor
([
width
,
height
,
width
,
height
])
.
to
(
device
)
# Disable gradients
with
torch
.
no_grad
():
with
torch
.
no_grad
():
# Run model
# Run model
t
=
time_synchronized
()
t
=
time_synchronized
()
...
@@ -111,12 +110,13 @@ def test(data,
...
@@ -111,12 +110,13 @@ def test(data,
t0
+=
time_synchronized
()
-
t
t0
+=
time_synchronized
()
-
t
# Compute loss
# Compute loss
if
training
:
# if model has loss hyperparameters
if
training
:
loss
+=
compute_loss
([
x
.
float
()
for
x
in
train_out
],
targets
,
model
)[
1
][:
3
]
# box, 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
()
output
=
non_max_suppression
(
inf_out
,
conf_thres
=
conf_thres
,
iou_thres
=
iou_thres
)
lb
=
[
targets
[
targets
[:,
0
]
==
i
,
1
:]
for
i
in
range
(
nb
)]
if
save_txt
else
[]
# for autolabelling
output
=
non_max_suppression
(
inf_out
,
conf_thres
=
conf_thres
,
iou_thres
=
iou_thres
,
labels
=
lb
)
t1
+=
time_synchronized
()
-
t
t1
+=
time_synchronized
()
-
t
# Statistics per image
# Statistics per image
...
@@ -174,7 +174,7 @@ def test(data,
...
@@ -174,7 +174,7 @@ def test(data,
tcls_tensor
=
labels
[:,
0
]
tcls_tensor
=
labels
[:,
0
]
# target boxes
# target boxes
tbox
=
xywh2xyxy
(
labels
[:,
1
:
5
])
*
whwh
tbox
=
xywh2xyxy
(
labels
[:,
1
:
5
])
scale_coords
(
img
[
si
]
.
shape
[
1
:],
tbox
,
shapes
[
si
][
0
],
shapes
[
si
][
1
])
# native-space labels
scale_coords
(
img
[
si
]
.
shape
[
1
:],
tbox
,
shapes
[
si
][
0
],
shapes
[
si
][
1
])
# native-space labels
# Per target class
# Per target class
...
@@ -264,7 +264,8 @@ def test(data,
...
@@ -264,7 +264,8 @@ def test(data,
# Return results
# Return results
if
not
training
:
if
not
training
:
print
(
'Results saved to
%
s'
%
save_dir
)
s
=
f
"
\n
{len(list(save_dir.glob('labels/*.txt')))} labels saved to {save_dir / 'labels'}"
if
save_txt
else
''
print
(
f
"Results saved to {save_dir}{s}"
)
model
.
float
()
# for training
model
.
float
()
# for training
maps
=
np
.
zeros
(
nc
)
+
map
maps
=
np
.
zeros
(
nc
)
+
map
for
i
,
c
in
enumerate
(
ap_class
):
for
i
,
c
in
enumerate
(
ap_class
):
...
...
utils/general.py
浏览文件 @
95fa6533
...
@@ -263,7 +263,7 @@ def wh_iou(wh1, wh2):
...
@@ -263,7 +263,7 @@ def wh_iou(wh1, wh2):
return
inter
/
(
wh1
.
prod
(
2
)
+
wh2
.
prod
(
2
)
-
inter
)
# iou = inter / (area1 + area2 - inter)
return
inter
/
(
wh1
.
prod
(
2
)
+
wh2
.
prod
(
2
)
-
inter
)
# iou = inter / (area1 + area2 - inter)
def
non_max_suppression
(
prediction
,
conf_thres
=
0.1
,
iou_thres
=
0.6
,
merge
=
False
,
classes
=
None
,
agnostic
=
False
):
def
non_max_suppression
(
prediction
,
conf_thres
=
0.1
,
iou_thres
=
0.6
,
classes
=
None
,
agnostic
=
False
,
labels
=
()
):
"""Performs Non-Maximum Suppression (NMS) on inference results
"""Performs Non-Maximum Suppression (NMS) on inference results
Returns:
Returns:
...
@@ -279,6 +279,7 @@ def non_max_suppression(prediction, conf_thres=0.1, iou_thres=0.6, merge=False,
...
@@ -279,6 +279,7 @@ def non_max_suppression(prediction, conf_thres=0.1, iou_thres=0.6, merge=False,
time_limit
=
10.0
# seconds to quit after
time_limit
=
10.0
# seconds to quit after
redundant
=
True
# require redundant detections
redundant
=
True
# require redundant detections
multi_label
=
nc
>
1
# multiple labels per box (adds 0.5ms/img)
multi_label
=
nc
>
1
# multiple labels per box (adds 0.5ms/img)
merge
=
False
# use merge-NMS
t
=
time
.
time
()
t
=
time
.
time
()
output
=
[
torch
.
zeros
(
0
,
6
)]
*
prediction
.
shape
[
0
]
output
=
[
torch
.
zeros
(
0
,
6
)]
*
prediction
.
shape
[
0
]
...
@@ -287,6 +288,15 @@ def non_max_suppression(prediction, conf_thres=0.1, iou_thres=0.6, merge=False,
...
@@ -287,6 +288,15 @@ def non_max_suppression(prediction, conf_thres=0.1, iou_thres=0.6, merge=False,
# x[((x[..., 2:4] < min_wh) | (x[..., 2:4] > max_wh)).any(1), 4] = 0 # width-height
# x[((x[..., 2:4] < min_wh) | (x[..., 2:4] > max_wh)).any(1), 4] = 0 # width-height
x
=
x
[
xc
[
xi
]]
# confidence
x
=
x
[
xc
[
xi
]]
# confidence
# Cat apriori labels if autolabelling
if
labels
and
len
(
labels
[
xi
]):
l
=
labels
[
xi
]
v
=
torch
.
zeros
((
len
(
l
),
nc
+
5
),
device
=
x
.
device
)
v
[:,
:
4
]
=
l
[:,
1
:
5
]
# box
v
[:,
4
]
=
1.0
# conf
v
[
range
(
len
(
l
)),
l
[:,
0
]
.
long
()
+
5
]
=
1.0
# cls
x
=
torch
.
cat
((
x
,
v
),
0
)
# If none remain process next image
# If none remain process next image
if
not
x
.
shape
[
0
]:
if
not
x
.
shape
[
0
]:
continue
continue
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论