Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Y
yolov5
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
Administrator
yolov5
Commits
3e560e2f
Unverified
提交
3e560e2f
authored
2月 12, 2021
作者:
Daniel Khromov
提交者:
GitHub
2月 12, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
YOLOv5 PyTorch Hub results.save() method retains filenames (#2194)
* save results with name * debug * save original imgs names * Update common.py Co-authored-by:
Glenn Jocher
<
glenn.jocher@ultralytics.com
>
上级
17ac94b7
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
9 行增加
和
6 行删除
+9
-6
common.py
models/common.py
+9
-6
没有找到文件。
models/common.py
浏览文件 @
3e560e2f
...
@@ -196,10 +196,11 @@ class autoShape(nn.Module):
...
@@ -196,10 +196,11 @@ class autoShape(nn.Module):
# Pre-process
# Pre-process
n
,
imgs
=
(
len
(
imgs
),
imgs
)
if
isinstance
(
imgs
,
list
)
else
(
1
,
[
imgs
])
# number of images, list of images
n
,
imgs
=
(
len
(
imgs
),
imgs
)
if
isinstance
(
imgs
,
list
)
else
(
1
,
[
imgs
])
# number of images, list of images
shape0
,
shape1
=
[],
[]
# image and inference shap
es
shape0
,
shape1
,
files
=
[],
[],
[]
# image and inference shapes, filenam
es
for
i
,
im
in
enumerate
(
imgs
):
for
i
,
im
in
enumerate
(
imgs
):
if
isinstance
(
im
,
str
):
# filename or uri
if
isinstance
(
im
,
str
):
# filename or uri
im
=
Image
.
open
(
requests
.
get
(
im
,
stream
=
True
)
.
raw
if
im
.
startswith
(
'http'
)
else
im
)
# open
im
=
Image
.
open
(
requests
.
get
(
im
,
stream
=
True
)
.
raw
if
im
.
startswith
(
'http'
)
else
im
)
# open
files
.
append
(
Path
(
im
.
filename
)
.
with_suffix
(
'.jpg'
)
.
name
if
isinstance
(
im
,
Image
.
Image
)
else
f
'image{i}.jpg'
)
im
=
np
.
array
(
im
)
# to numpy
im
=
np
.
array
(
im
)
# to numpy
if
im
.
shape
[
0
]
<
5
:
# image in CHW
if
im
.
shape
[
0
]
<
5
:
# image in CHW
im
=
im
.
transpose
((
1
,
2
,
0
))
# reverse dataloader .transpose(2, 0, 1)
im
=
im
.
transpose
((
1
,
2
,
0
))
# reverse dataloader .transpose(2, 0, 1)
...
@@ -224,18 +225,19 @@ class autoShape(nn.Module):
...
@@ -224,18 +225,19 @@ class autoShape(nn.Module):
for
i
in
range
(
n
):
for
i
in
range
(
n
):
scale_coords
(
shape1
,
y
[
i
][:,
:
4
],
shape0
[
i
])
scale_coords
(
shape1
,
y
[
i
][:,
:
4
],
shape0
[
i
])
return
Detections
(
imgs
,
y
,
self
.
names
)
return
Detections
(
imgs
,
y
,
files
,
self
.
names
)
class
Detections
:
class
Detections
:
# detections class for YOLOv5 inference results
# detections class for YOLOv5 inference results
def
__init__
(
self
,
imgs
,
pred
,
names
=
None
):
def
__init__
(
self
,
imgs
,
pred
,
files
,
names
=
None
):
super
(
Detections
,
self
)
.
__init__
()
super
(
Detections
,
self
)
.
__init__
()
d
=
pred
[
0
]
.
device
# device
d
=
pred
[
0
]
.
device
# device
gn
=
[
torch
.
tensor
([
*
[
im
.
shape
[
i
]
for
i
in
[
1
,
0
,
1
,
0
]],
1.
,
1.
],
device
=
d
)
for
im
in
imgs
]
# normalizations
gn
=
[
torch
.
tensor
([
*
[
im
.
shape
[
i
]
for
i
in
[
1
,
0
,
1
,
0
]],
1.
,
1.
],
device
=
d
)
for
im
in
imgs
]
# normalizations
self
.
imgs
=
imgs
# list of images as numpy arrays
self
.
imgs
=
imgs
# list of images as numpy arrays
self
.
pred
=
pred
# list of tensors pred[0] = (xyxy, conf, cls)
self
.
pred
=
pred
# list of tensors pred[0] = (xyxy, conf, cls)
self
.
names
=
names
# class names
self
.
names
=
names
# class names
self
.
files
=
files
# image filenames
self
.
xyxy
=
pred
# xyxy pixels
self
.
xyxy
=
pred
# xyxy pixels
self
.
xywh
=
[
xyxy2xywh
(
x
)
for
x
in
pred
]
# xywh pixels
self
.
xywh
=
[
xyxy2xywh
(
x
)
for
x
in
pred
]
# xywh pixels
self
.
xyxyn
=
[
x
/
g
for
x
,
g
in
zip
(
self
.
xyxy
,
gn
)]
# xyxy normalized
self
.
xyxyn
=
[
x
/
g
for
x
,
g
in
zip
(
self
.
xyxy
,
gn
)]
# xyxy normalized
...
@@ -258,9 +260,9 @@ class Detections:
...
@@ -258,9 +260,9 @@ class Detections:
if
pprint
:
if
pprint
:
print
(
str
.
rstrip
(
', '
))
print
(
str
.
rstrip
(
', '
))
if
show
:
if
show
:
img
.
show
(
f
'image {i}'
)
# show
img
.
show
(
self
.
files
[
i
]
)
# show
if
save
:
if
save
:
f
=
Path
(
save_dir
)
/
f
'results{i}.jpg'
f
=
Path
(
save_dir
)
/
self
.
files
[
i
]
img
.
save
(
f
)
# save
img
.
save
(
f
)
# save
print
(
f
"{'Saving' * (i == 0)} {f},"
,
end
=
''
if
i
<
self
.
n
-
1
else
' done.
\n
'
)
print
(
f
"{'Saving' * (i == 0)} {f},"
,
end
=
''
if
i
<
self
.
n
-
1
else
' done.
\n
'
)
if
render
:
if
render
:
...
@@ -272,7 +274,8 @@ class Detections:
...
@@ -272,7 +274,8 @@ class Detections:
def
show
(
self
):
def
show
(
self
):
self
.
display
(
show
=
True
)
# show results
self
.
display
(
show
=
True
)
# show results
def
save
(
self
,
save_dir
=
''
):
def
save
(
self
,
save_dir
=
'results/'
):
Path
(
save_dir
)
.
mkdir
(
exist_ok
=
True
)
self
.
display
(
save
=
True
,
save_dir
=
save_dir
)
# save results
self
.
display
(
save
=
True
,
save_dir
=
save_dir
)
# save results
def
render
(
self
):
def
render
(
self
):
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论