Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Y
yolov5
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
Administrator
yolov5
Commits
f527704c
Unverified
提交
f527704c
authored
6月 18, 2021
作者:
Glenn Jocher
提交者:
GitHub
6月 18, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Cache v0.3: improved corrupt image/label reporting (#3676)
* Cache v0.3: improved corrupt image/label reporting Fix for
https://github.com/ultralytics/yolov5/issues/3656#issuecomment-863660899
* cleanup
上级
2296f154
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
15 行增加
和
9 行删除
+15
-9
datasets.py
utils/datasets.py
+15
-9
没有找到文件。
utils/datasets.py
浏览文件 @
f527704c
...
...
@@ -390,7 +390,7 @@ class LoadImagesAndLabels(Dataset): # for training/testing
cache_path
=
(
p
if
p
.
is_file
()
else
Path
(
self
.
label_files
[
0
])
.
parent
)
.
with_suffix
(
'.cache'
)
# cached labels
if
cache_path
.
is_file
():
cache
,
exists
=
torch
.
load
(
cache_path
),
True
# load
if
cache
[
'hash'
]
!=
get_hash
(
self
.
label_files
+
self
.
img_files
)
:
# changed
if
cache
[
'hash'
]
!=
get_hash
(
self
.
label_files
+
self
.
img_files
)
or
cache
[
'version'
]
!=
0.3
:
cache
,
exists
=
self
.
cache_labels
(
cache_path
,
prefix
),
False
# re-cache
else
:
cache
,
exists
=
self
.
cache_labels
(
cache_path
,
prefix
),
False
# cache
...
...
@@ -400,11 +400,12 @@ class LoadImagesAndLabels(Dataset): # for training/testing
if
exists
:
d
=
f
"Scanning '{cache_path}' images and labels... {nf} found, {nm} missing, {ne} empty, {nc} corrupted"
tqdm
(
None
,
desc
=
prefix
+
d
,
total
=
n
,
initial
=
n
)
# display cache results
if
cache
[
'msgs'
]:
logging
.
info
(
'
\n
'
.
join
(
cache
[
'msgs'
]))
# display warnings
assert
nf
>
0
or
not
augment
,
f
'{prefix}No labels in {cache_path}. Can not train without labels. See {help_url}'
# Read cache
cache
.
pop
(
'hash'
)
# remove hash
cache
.
pop
(
'version'
)
# remove version
[
cache
.
pop
(
k
)
for
k
in
(
'hash'
,
'version'
,
'msgs'
)]
# remove items
labels
,
shapes
,
self
.
segments
=
zip
(
*
cache
.
values
())
self
.
labels
=
list
(
labels
)
self
.
shapes
=
np
.
array
(
shapes
,
dtype
=
np
.
float64
)
...
...
@@ -461,26 +462,31 @@ class LoadImagesAndLabels(Dataset): # for training/testing
def
cache_labels
(
self
,
path
=
Path
(
'./labels.cache'
),
prefix
=
''
):
# Cache dataset labels, check images and read shapes
x
=
{}
# dict
nm
,
nf
,
ne
,
nc
=
0
,
0
,
0
,
0
# number missing, found, empty, corrupt
nm
,
nf
,
ne
,
nc
,
msgs
=
0
,
0
,
0
,
0
,
[]
# number missing, found, empty, corrupt, messages
desc
=
f
"{prefix}Scanning '{path.parent / path.stem}' images and labels..."
with
Pool
(
num_threads
)
as
pool
:
pbar
=
tqdm
(
pool
.
imap_unordered
(
verify_image_label
,
zip
(
self
.
img_files
,
self
.
label_files
,
repeat
(
prefix
))),
desc
=
desc
,
total
=
len
(
self
.
img_files
))
for
im_file
,
l
,
shape
,
segments
,
nm_f
,
nf_f
,
ne_f
,
nc_f
in
pbar
:
for
im_file
,
l
,
shape
,
segments
,
nm_f
,
nf_f
,
ne_f
,
nc_f
,
msg
in
pbar
:
nm
+=
nm_f
nf
+=
nf_f
ne
+=
ne_f
nc
+=
nc_f
if
im_file
:
x
[
im_file
]
=
[
l
,
shape
,
segments
]
if
msg
:
msgs
.
append
(
msg
)
pbar
.
desc
=
f
"{desc}{nf} found, {nm} missing, {ne} empty, {nc} corrupted"
pbar
.
close
()
if
msgs
:
logging
.
info
(
'
\n
'
.
join
(
msgs
))
if
nf
==
0
:
logging
.
info
(
f
'{prefix}WARNING: No labels found in {path}. See {help_url}'
)
x
[
'hash'
]
=
get_hash
(
self
.
label_files
+
self
.
img_files
)
x
[
'results'
]
=
nf
,
nm
,
ne
,
nc
,
len
(
self
.
img_files
)
x
[
'version'
]
=
0.2
# cache version
x
[
'msgs'
]
=
msgs
# warnings
x
[
'version'
]
=
0.3
# cache version
try
:
torch
.
save
(
x
,
path
)
# save cache for next time
logging
.
info
(
f
'{prefix}New cache created: {path}'
)
...
...
@@ -1084,11 +1090,11 @@ def verify_image_label(args):
else
:
nm
=
1
# label missing
l
=
np
.
zeros
((
0
,
5
),
dtype
=
np
.
float32
)
return
im_file
,
l
,
shape
,
segments
,
nm
,
nf
,
ne
,
nc
return
im_file
,
l
,
shape
,
segments
,
nm
,
nf
,
ne
,
nc
,
''
except
Exception
as
e
:
nc
=
1
logging
.
info
(
f
'{prefix}WARNING: Ignoring corrupted image and/or label {im_file}: {e}'
)
return
[
None
,
None
,
None
,
None
,
nm
,
nf
,
ne
,
nc
]
msg
=
f
'{prefix}WARNING: Ignoring corrupted image and/or label {im_file}: {e}'
return
[
None
,
None
,
None
,
None
,
nm
,
nf
,
ne
,
nc
,
msg
]
def
dataset_stats
(
path
=
'coco128.yaml'
,
autodownload
=
False
,
verbose
=
False
):
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论