Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Y
yolov5
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
Administrator
yolov5
Commits
54a9e4f8
提交
54a9e4f8
authored
7月 09, 2020
作者:
lorenzomammana
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refactor code to reduce duplication
上级
94342acb
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
16 行增加
和
17 行删除
+16
-17
datasets.py
utils/datasets.py
+16
-17
没有找到文件。
utils/datasets.py
浏览文件 @
54a9e4f8
...
@@ -280,32 +280,31 @@ class LoadImagesAndLabels(Dataset): # for training/testing
...
@@ -280,32 +280,31 @@ 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
,
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
):
cache_images
=
False
,
single_cls
=
False
,
stride
=
32
,
pad
=
0.0
):
try
:
try
:
if
type
(
path
)
is
list
:
f
=
[]
# Multiple datasets handler
for
subpath
in
path
if
isinstance
(
path
,
list
)
else
[
path
]:
f
=
[]
subpath
=
str
(
Path
(
subpath
))
# os-agnostic
for
subpath
in
path
:
parent
=
str
(
Path
(
subpath
)
.
parent
)
+
os
.
sep
if
os
.
path
.
isfile
(
subpath
):
# file
with
open
(
subpath
,
'r'
)
as
t
:
with
open
(
subpath
,
'r'
)
as
t
:
subpath
=
str
(
Path
(
subpath
))
# os-agnostic
parent
=
str
(
Path
(
subpath
)
.
parent
)
+
os
.
sep
t
=
t
.
read
()
.
splitlines
()
t
=
t
.
read
()
.
splitlines
()
t
=
[
x
.
replace
(
'./'
,
parent
)
if
x
.
startswith
(
'./'
)
else
x
for
x
in
t
]
# local to global path
t
=
[
x
.
replace
(
'./'
,
parent
)
if
x
.
startswith
(
'./'
)
else
x
for
x
in
t
]
# local to global path
f
+=
t
f
+=
t
path
=
str
(
Path
(
path
[
0
]))
# from now on treat multiple datasets as single
elif
os
.
path
.
isdir
(
subpath
):
# folder
else
:
f
=
glob
.
iglob
(
subpath
+
os
.
sep
+
'*.*'
)
path
=
str
(
Path
(
path
))
# os-agnostic
# Maybe change this to f += glob.glob, this should allow handling also multiple folders
parent
=
str
(
Path
(
path
)
.
parent
)
+
os
.
sep
if
os
.
path
.
isfile
(
path
):
# file
with
open
(
path
,
'r'
)
as
f
:
f
=
f
.
read
()
.
splitlines
()
f
=
[
x
.
replace
(
'./'
,
parent
)
if
x
.
startswith
(
'./'
)
else
x
for
x
in
f
]
# local to global path
elif
os
.
path
.
isdir
(
path
):
# folder
f
=
glob
.
iglob
(
path
+
os
.
sep
+
'*.*'
)
else
:
else
:
raise
Exception
(
'
%
s does not exist'
%
path
)
raise
Exception
(
'
%
s does not exist'
%
sub
path
)
self
.
img_files
=
[
x
.
replace
(
'/'
,
os
.
sep
)
for
x
in
f
if
os
.
path
.
splitext
(
x
)[
-
1
]
.
lower
()
in
img_formats
]
self
.
img_files
=
[
x
.
replace
(
'/'
,
os
.
sep
)
for
x
in
f
if
os
.
path
.
splitext
(
x
)[
-
1
]
.
lower
()
in
img_formats
]
except
:
except
:
# Maybe avoid handling bare exceptions
raise
Exception
(
'Error loading data from
%
s. See
%
s'
%
(
path
,
help_url
))
raise
Exception
(
'Error loading data from
%
s. See
%
s'
%
(
path
,
help_url
))
# Still need to do this for compatibility with the .npy and shape file saves
if
isinstance
(
path
,
list
):
path
=
str
(
Path
(
path
[
0
]))
else
:
path
=
str
(
Path
(
path
))
n
=
len
(
self
.
img_files
)
n
=
len
(
self
.
img_files
)
assert
n
>
0
,
'No images found in
%
s. See
%
s'
%
(
path
,
help_url
)
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
bi
=
np
.
floor
(
np
.
arange
(
n
)
/
batch_size
)
.
astype
(
np
.
int
)
# batch index
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论