Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Y
yolov5
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
Administrator
yolov5
Commits
481d46cf
提交
481d46cf
authored
10月 24, 2020
作者:
Glenn Jocher
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Improved corruption handling during scan and cache (#999)
上级
d61930e0
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
16 行增加
和
17 行删除
+16
-17
datasets.py
utils/datasets.py
+16
-17
没有找到文件。
utils/datasets.py
浏览文件 @
481d46cf
...
...
@@ -328,6 +328,14 @@ class LoadStreams: # multiple IP or RTSP cameras
class
LoadImagesAndLabels
(
Dataset
):
# for training/testing
def
__init__
(
self
,
path
,
img_size
=
640
,
batch_size
=
16
,
augment
=
False
,
hyp
=
None
,
rect
=
False
,
image_weights
=
False
,
cache_images
=
False
,
single_cls
=
False
,
stride
=
32
,
pad
=
0.0
,
rank
=-
1
):
self
.
img_size
=
img_size
self
.
augment
=
augment
self
.
hyp
=
hyp
self
.
image_weights
=
image_weights
self
.
rect
=
False
if
image_weights
else
rect
self
.
mosaic
=
self
.
augment
and
not
self
.
rect
# load 4 images at a time into a mosaic (only during training)
self
.
mosaic_border
=
[
-
img_size
//
2
,
-
img_size
//
2
]
self
.
stride
=
stride
def
img2label_paths
(
img_paths
):
# Define label paths as a function of image paths
...
...
@@ -349,25 +357,10 @@ class LoadImagesAndLabels(Dataset): # for training/testing
raise
Exception
(
'
%
s does not exist'
%
p
)
self
.
img_files
=
sorted
(
[
x
.
replace
(
'/'
,
os
.
sep
)
for
x
in
f
if
os
.
path
.
splitext
(
x
)[
-
1
]
.
lower
()
in
img_formats
])
assert
len
(
self
.
img_files
)
>
0
,
'No images found'
except
Exception
as
e
:
raise
Exception
(
'Error loading data from
%
s:
%
s
\n
See
%
s'
%
(
path
,
e
,
help_url
))
n
=
len
(
self
.
img_files
)
assert
n
>
0
,
'No images found in
%
s. See
%
s'
%
(
path
,
help_url
)
bi
=
np
.
floor
(
np
.
arange
(
n
)
/
batch_size
)
.
astype
(
np
.
int
)
# batch index
nb
=
bi
[
-
1
]
+
1
# number of batches
self
.
n
=
n
# number of images
self
.
batch
=
bi
# batch index of image
self
.
img_size
=
img_size
self
.
augment
=
augment
self
.
hyp
=
hyp
self
.
image_weights
=
image_weights
self
.
rect
=
False
if
image_weights
else
rect
self
.
mosaic
=
self
.
augment
and
not
self
.
rect
# load 4 images at a time into a mosaic (only during training)
self
.
mosaic_border
=
[
-
img_size
//
2
,
-
img_size
//
2
]
self
.
stride
=
stride
# Check cache
self
.
label_files
=
img2label_paths
(
self
.
img_files
)
# labels
cache_path
=
str
(
Path
(
self
.
label_files
[
0
])
.
parent
)
+
'.cache'
# cached labels
...
...
@@ -386,6 +379,12 @@ class LoadImagesAndLabels(Dataset): # for training/testing
self
.
img_files
=
list
(
cache
.
keys
())
# update
self
.
label_files
=
img2label_paths
(
cache
.
keys
())
# update
n
=
len
(
shapes
)
# number of images
bi
=
np
.
floor
(
np
.
arange
(
n
)
/
batch_size
)
.
astype
(
np
.
int
)
# batch index
nb
=
bi
[
-
1
]
+
1
# number of batches
self
.
batch
=
bi
# batch index of image
self
.
n
=
n
# Rectangular Training
if
self
.
rect
:
# Sort by aspect ratio
...
...
@@ -500,7 +499,7 @@ class LoadImagesAndLabels(Dataset): # for training/testing
l
=
np
.
zeros
((
0
,
5
),
dtype
=
np
.
float32
)
x
[
img
]
=
[
l
,
shape
]
except
Exception
as
e
:
print
(
'WARNING: Ignoring corrupted image and/or label
:
%
s:
%
s'
%
(
img
,
e
))
print
(
'WARNING: Ignoring corrupted image and/or label
%
s:
%
s'
%
(
img
,
e
))
x
[
'hash'
]
=
get_hash
(
self
.
label_files
+
self
.
img_files
)
torch
.
save
(
x
,
path
)
# save for next time
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论