Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Y
yolov5
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
Administrator
yolov5
Commits
54043a9f
Unverified
提交
54043a9f
authored
12月 11, 2020
作者:
Glenn Jocher
提交者:
GitHub
12月 11, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Streaming --save-txt bug fix (#1672)
* Streaming --save-txt bug fix * cleanup
上级
bc52ea2d
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
11 行增加
和
11 行删除
+11
-11
detect.py
detect.py
+9
-9
datasets.py
utils/datasets.py
+2
-2
没有找到文件。
detect.py
浏览文件 @
54043a9f
...
@@ -81,12 +81,12 @@ def detect(save_img=False):
...
@@ -81,12 +81,12 @@ def detect(save_img=False):
# Process detections
# Process detections
for
i
,
det
in
enumerate
(
pred
):
# detections per image
for
i
,
det
in
enumerate
(
pred
):
# detections per image
if
webcam
:
# batch_size >= 1
if
webcam
:
# batch_size >= 1
p
,
s
,
im0
=
Path
(
path
[
i
]),
'
%
g: '
%
i
,
im0s
[
i
]
.
copy
()
p
,
s
,
im0
,
frame
=
Path
(
path
[
i
]),
'
%
g: '
%
i
,
im0s
[
i
]
.
copy
(),
dataset
.
count
else
:
else
:
p
,
s
,
im0
=
Path
(
path
),
''
,
im0s
p
,
s
,
im0
,
frame
=
Path
(
path
),
''
,
im0s
,
getattr
(
dataset
,
'frame'
,
0
)
save_path
=
str
(
save_dir
/
p
.
name
)
save_path
=
str
(
save_dir
/
p
.
name
)
txt_path
=
str
(
save_dir
/
'labels'
/
p
.
stem
)
+
(
'
_
%
g'
%
dataset
.
frame
if
dataset
.
mode
==
'video'
else
'
'
)
txt_path
=
str
(
save_dir
/
'labels'
/
p
.
stem
)
+
(
'
'
if
dataset
.
mode
==
'image'
else
f
'_{frame}
'
)
s
+=
'
%
gx
%
g '
%
img
.
shape
[
2
:]
# print string
s
+=
'
%
gx
%
g '
%
img
.
shape
[
2
:]
# print string
gn
=
torch
.
tensor
(
im0
.
shape
)[[
1
,
0
,
1
,
0
]]
# normalization gain whwh
gn
=
torch
.
tensor
(
im0
.
shape
)[[
1
,
0
,
1
,
0
]]
# normalization gain whwh
if
len
(
det
):
if
len
(
det
):
...
@@ -96,7 +96,7 @@ def detect(save_img=False):
...
@@ -96,7 +96,7 @@ def detect(save_img=False):
# Print results
# Print results
for
c
in
det
[:,
-
1
]
.
unique
():
for
c
in
det
[:,
-
1
]
.
unique
():
n
=
(
det
[:,
-
1
]
==
c
)
.
sum
()
# detections per class
n
=
(
det
[:,
-
1
]
==
c
)
.
sum
()
# detections per class
s
+=
'
%
g
%
ss, '
%
(
n
,
names
[
int
(
c
)])
# add to string
s
+=
f
'{n} {names[int(c)]}s, '
# add to string
# Write results
# Write results
for
*
xyxy
,
conf
,
cls
in
reversed
(
det
):
for
*
xyxy
,
conf
,
cls
in
reversed
(
det
):
...
@@ -107,11 +107,11 @@ def detect(save_img=False):
...
@@ -107,11 +107,11 @@ def detect(save_img=False):
f
.
write
((
'
%
g '
*
len
(
line
))
.
rstrip
()
%
line
+
'
\n
'
)
f
.
write
((
'
%
g '
*
len
(
line
))
.
rstrip
()
%
line
+
'
\n
'
)
if
save_img
or
view_img
:
# Add bbox to image
if
save_img
or
view_img
:
# Add bbox to image
label
=
'
%
s
%.2
f'
%
(
names
[
int
(
cls
)],
conf
)
label
=
f
'{names[int(cls)]} {conf:.2f}'
plot_one_box
(
xyxy
,
im0
,
label
=
label
,
color
=
colors
[
int
(
cls
)],
line_thickness
=
3
)
plot_one_box
(
xyxy
,
im0
,
label
=
label
,
color
=
colors
[
int
(
cls
)],
line_thickness
=
3
)
# Print time (inference + NMS)
# Print time (inference + NMS)
print
(
'
%
sDone. (
%.3
fs)'
%
(
s
,
t2
-
t1
)
)
print
(
f
'{s}Done. ({t2 - t1:.3f}s)'
)
# Stream results
# Stream results
if
view_img
:
if
view_img
:
...
@@ -121,9 +121,9 @@ def detect(save_img=False):
...
@@ -121,9 +121,9 @@ def detect(save_img=False):
# Save results (image with detections)
# Save results (image with detections)
if
save_img
:
if
save_img
:
if
dataset
.
mode
==
'image
s
'
:
if
dataset
.
mode
==
'image'
:
cv2
.
imwrite
(
save_path
,
im0
)
cv2
.
imwrite
(
save_path
,
im0
)
else
:
else
:
# 'video'
if
vid_path
!=
save_path
:
# new video
if
vid_path
!=
save_path
:
# new video
vid_path
=
save_path
vid_path
=
save_path
if
isinstance
(
vid_writer
,
cv2
.
VideoWriter
):
if
isinstance
(
vid_writer
,
cv2
.
VideoWriter
):
...
@@ -140,7 +140,7 @@ def detect(save_img=False):
...
@@ -140,7 +140,7 @@ def detect(save_img=False):
s
=
f
"
\n
{len(list(save_dir.glob('labels/*.txt')))} labels saved to {save_dir / 'labels'}"
if
save_txt
else
''
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
(
f
"Results saved to {save_dir}{s}"
)
print
(
'Done. (
%.3
fs)'
%
(
time
.
time
()
-
t0
)
)
print
(
f
'Done. ({time.time() - t0:.3f}s)'
)
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
...
...
utils/datasets.py
浏览文件 @
54043a9f
...
@@ -138,7 +138,7 @@ class LoadImages: # for inference
...
@@ -138,7 +138,7 @@ class LoadImages: # for inference
self
.
files
=
images
+
videos
self
.
files
=
images
+
videos
self
.
nf
=
ni
+
nv
# number of files
self
.
nf
=
ni
+
nv
# number of files
self
.
video_flag
=
[
False
]
*
ni
+
[
True
]
*
nv
self
.
video_flag
=
[
False
]
*
ni
+
[
True
]
*
nv
self
.
mode
=
'image
s
'
self
.
mode
=
'image'
if
any
(
videos
):
if
any
(
videos
):
self
.
new_video
(
videos
[
0
])
# new video
self
.
new_video
(
videos
[
0
])
# new video
else
:
else
:
...
@@ -256,7 +256,7 @@ class LoadWebcam: # for inference
...
@@ -256,7 +256,7 @@ class LoadWebcam: # for inference
class
LoadStreams
:
# multiple IP or RTSP cameras
class
LoadStreams
:
# multiple IP or RTSP cameras
def
__init__
(
self
,
sources
=
'streams.txt'
,
img_size
=
640
):
def
__init__
(
self
,
sources
=
'streams.txt'
,
img_size
=
640
):
self
.
mode
=
'
images
'
self
.
mode
=
'
stream
'
self
.
img_size
=
img_size
self
.
img_size
=
img_size
if
os
.
path
.
isfile
(
sources
):
if
os
.
path
.
isfile
(
sources
):
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论