Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Y
yolov5
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
Administrator
yolov5
Commits
c6b5bfca
Unverified
提交
c6b5bfca
authored
5月 26, 2021
作者:
Glenn Jocher
提交者:
GitHub
5月 26, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Updated cache v0.2 with `hashlib` (#3350)
* Update cache v0.2 to include parent hash Possible fix for
https://github.com/ultralytics/yolov5/issues/3349
* Update datasets.py
上级
1f8d716e
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
10 行增加
和
6 行删除
+10
-6
datasets.py
utils/datasets.py
+10
-6
没有找到文件。
utils/datasets.py
浏览文件 @
c6b5bfca
# Dataset utils and dataloaders
# Dataset utils and dataloaders
import
glob
import
glob
import
hashlib
import
logging
import
logging
import
math
import
math
import
os
import
os
...
@@ -36,9 +37,12 @@ for orientation in ExifTags.TAGS.keys():
...
@@ -36,9 +37,12 @@ for orientation in ExifTags.TAGS.keys():
break
break
def
get_hash
(
files
):
def
get_hash
(
paths
):
# Returns a single hash value of a list of files
# Returns a single hash value of a list of paths (files or dirs)
return
sum
(
os
.
path
.
getsize
(
f
)
for
f
in
files
if
os
.
path
.
isfile
(
f
))
size
=
sum
(
os
.
path
.
getsize
(
p
)
for
p
in
paths
if
os
.
path
.
exists
(
p
))
# sizes
h
=
hashlib
.
md5
(
str
(
size
)
.
encode
())
# hash sizes
h
.
update
(
''
.
join
(
paths
)
.
encode
())
# hash paths
return
h
.
hexdigest
()
# return hash
def
exif_size
(
img
):
def
exif_size
(
img
):
...
@@ -383,7 +387,7 @@ class LoadImagesAndLabels(Dataset): # for training/testing
...
@@ -383,7 +387,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
cache_path
=
(
p
if
p
.
is_file
()
else
Path
(
self
.
label_files
[
0
])
.
parent
)
.
with_suffix
(
'.cache'
)
# cached labels
if
cache_path
.
is_file
():
if
cache_path
.
is_file
():
cache
,
exists
=
torch
.
load
(
cache_path
),
True
# load
cache
,
exists
=
torch
.
load
(
cache_path
),
True
# load
if
cache
[
'hash'
]
!=
get_hash
(
self
.
label_files
+
self
.
img_files
)
or
'version'
not
in
cache
:
# changed
if
cache
[
'hash'
]
!=
get_hash
(
self
.
label_files
+
self
.
img_files
):
# changed
cache
,
exists
=
self
.
cache_labels
(
cache_path
,
prefix
),
False
# re-cache
cache
,
exists
=
self
.
cache_labels
(
cache_path
,
prefix
),
False
# re-cache
else
:
else
:
cache
,
exists
=
self
.
cache_labels
(
cache_path
,
prefix
),
False
# cache
cache
,
exists
=
self
.
cache_labels
(
cache_path
,
prefix
),
False
# cache
...
@@ -501,9 +505,9 @@ class LoadImagesAndLabels(Dataset): # for training/testing
...
@@ -501,9 +505,9 @@ class LoadImagesAndLabels(Dataset): # for training/testing
x
[
'hash'
]
=
get_hash
(
self
.
label_files
+
self
.
img_files
)
x
[
'hash'
]
=
get_hash
(
self
.
label_files
+
self
.
img_files
)
x
[
'results'
]
=
nf
,
nm
,
ne
,
nc
,
i
+
1
x
[
'results'
]
=
nf
,
nm
,
ne
,
nc
,
i
+
1
x
[
'version'
]
=
0.
1
# cache version
x
[
'version'
]
=
0.
2
# cache version
try
:
try
:
torch
.
save
(
x
,
path
)
# save for next time
torch
.
save
(
x
,
path
)
# save
cache
for next time
logging
.
info
(
f
'{prefix}New cache created: {path}'
)
logging
.
info
(
f
'{prefix}New cache created: {path}'
)
except
Exception
as
e
:
except
Exception
as
e
:
logging
.
info
(
f
'{prefix}WARNING: Cache directory {path.parent} is not writeable: {e}'
)
# path not writeable
logging
.
info
(
f
'{prefix}WARNING: Cache directory {path.parent} is not writeable: {e}'
)
# path not writeable
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论