Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
hapi
提交
31766e3a
H
hapi
项目概览
PaddlePaddle
/
hapi
通知
11
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
4
列表
看板
标记
里程碑
合并请求
7
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
hapi
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
4
Issue
4
列表
看板
标记
里程碑
合并请求
7
合并请求
7
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
31766e3a
编写于
4月 29, 2020
作者:
L
LielinJiang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refine datasets
上级
c42caaaa
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
36 addition
and
14 deletion
+36
-14
hapi/datasets/folder.py
hapi/datasets/folder.py
+3
-9
hapi/datasets/utils.py
hapi/datasets/utils.py
+2
-2
hapi/tests/test_datasets.py
hapi/tests/test_datasets.py
+31
-3
未找到文件。
hapi/datasets/folder.py
浏览文件 @
31766e3a
...
@@ -34,13 +34,10 @@ def has_valid_extension(filename, extensions):
...
@@ -34,13 +34,10 @@ def has_valid_extension(filename, extensions):
return
filename
.
lower
().
endswith
(
extensions
)
return
filename
.
lower
().
endswith
(
extensions
)
def
make_dataset
(
dir
,
class_to_idx
,
extensions
=
None
,
is_valid_file
=
None
):
def
make_dataset
(
dir
,
class_to_idx
,
extensions
,
is_valid_file
=
None
):
images
=
[]
images
=
[]
dir
=
os
.
path
.
expanduser
(
dir
)
dir
=
os
.
path
.
expanduser
(
dir
)
if
not
((
extensions
is
None
)
^
(
is_valid_file
is
None
)):
raise
ValueError
(
"Both extensions and is_valid_file cannot be None or not None at the same time"
)
if
extensions
is
not
None
:
if
extensions
is
not
None
:
def
is_valid_file
(
x
):
def
is_valid_file
(
x
):
...
@@ -200,10 +197,7 @@ class ImageFolder(Dataset):
...
@@ -200,10 +197,7 @@ class ImageFolder(Dataset):
samples
=
[]
samples
=
[]
path
=
os
.
path
.
expanduser
(
root
)
path
=
os
.
path
.
expanduser
(
root
)
if
not
((
extensions
is
None
)
^
(
is_valid_file
is
None
)):
raise
ValueError
(
"Both extensions and is_valid_file cannot be None or not None at the same time"
)
if
extensions
is
not
None
:
if
extensions
is
not
None
:
def
is_valid_file
(
x
):
def
is_valid_file
(
x
):
...
...
hapi/datasets/utils.py
浏览文件 @
31766e3a
...
@@ -25,5 +25,5 @@ def _check_exists_and_download(path, url, md5, module_name, download=True):
...
@@ -25,5 +25,5 @@ def _check_exists_and_download(path, url, md5, module_name, download=True):
if
download
:
if
download
:
return
paddle
.
dataset
.
common
.
download
(
url
,
module_name
,
md5
)
return
paddle
.
dataset
.
common
.
download
(
url
,
module_name
,
md5
)
else
:
else
:
raise
FileNotFoundError
(
raise
ValueError
(
'{} not exists and auto download disabled'
.
format
(
'{} not exists and auto download disabled'
.
format
(
path
))
path
))
hapi/tests/test_datasets.py
浏览文件 @
31766e3a
...
@@ -20,11 +20,14 @@ import shutil
...
@@ -20,11 +20,14 @@ import shutil
import
cv2
import
cv2
from
hapi.datasets
import
*
from
hapi.datasets
import
*
from
hapi.datasets.utils
import
_check_exists_and_download
from
hapi.vision.transforms
import
Compose
class
TestFolderDatasets
(
unittest
.
TestCase
):
class
TestFolderDatasets
(
unittest
.
TestCase
):
def
makedata
(
self
):
def
setUp
(
self
):
self
.
data_dir
=
tempfile
.
mkdtemp
()
self
.
data_dir
=
tempfile
.
mkdtemp
()
self
.
empty_dir
=
tempfile
.
mkdtemp
()
for
i
in
range
(
2
):
for
i
in
range
(
2
):
sub_dir
=
os
.
path
.
join
(
self
.
data_dir
,
'class_'
+
str
(
i
))
sub_dir
=
os
.
path
.
join
(
self
.
data_dir
,
'class_'
+
str
(
i
))
if
not
os
.
path
.
exists
(
sub_dir
):
if
not
os
.
path
.
exists
(
sub_dir
):
...
@@ -34,8 +37,10 @@ class TestFolderDatasets(unittest.TestCase):
...
@@ -34,8 +37,10 @@ class TestFolderDatasets(unittest.TestCase):
(
32
,
32
,
3
))
*
255
).
astype
(
'uint8'
)
(
32
,
32
,
3
))
*
255
).
astype
(
'uint8'
)
cv2
.
imwrite
(
os
.
path
.
join
(
sub_dir
,
str
(
j
)
+
'.jpg'
),
fake_img
)
cv2
.
imwrite
(
os
.
path
.
join
(
sub_dir
,
str
(
j
)
+
'.jpg'
),
fake_img
)
def
tearDown
(
self
):
shutil
.
rmtree
(
self
.
data_dir
)
def
test_dataset
(
self
):
def
test_dataset
(
self
):
self
.
makedata
()
dataset_folder
=
DatasetFolder
(
self
.
data_dir
)
dataset_folder
=
DatasetFolder
(
self
.
data_dir
)
for
_
in
dataset_folder
:
for
_
in
dataset_folder
:
...
@@ -44,7 +49,30 @@ class TestFolderDatasets(unittest.TestCase):
...
@@ -44,7 +49,30 @@ class TestFolderDatasets(unittest.TestCase):
assert
len
(
dataset_folder
)
==
4
assert
len
(
dataset_folder
)
==
4
assert
len
(
dataset_folder
.
classes
)
==
2
assert
len
(
dataset_folder
.
classes
)
==
2
shutil
.
rmtree
(
self
.
data_dir
)
transform
=
Compose
([])
dataset_folder
=
DatasetFolder
(
self
.
data_dir
,
transform
=
transform
)
for
_
in
dataset_folder
:
pass
def
test_folder
(
self
):
loader
=
ImageFolder
(
self
.
data_dir
)
for
_
in
loader
:
pass
transform
=
Compose
([])
loader
=
ImageFolder
(
self
.
data_dir
,
transform
=
transform
)
for
_
in
loader
:
pass
def
test_errors
(
self
):
with
self
.
assertRaises
(
RuntimeError
):
ImageFolder
(
self
.
empty_dir
)
with
self
.
assertRaises
(
RuntimeError
):
DatasetFolder
(
self
.
empty_dir
)
with
self
.
assertRaises
(
ValueError
):
_check_exists_and_download
(
'temp_paddle'
,
None
,
None
,
None
,
False
)
class
TestMNISTTest
(
unittest
.
TestCase
):
class
TestMNISTTest
(
unittest
.
TestCase
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录