Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
magicwindyyd
mindspore
提交
6a1b865c
M
mindspore
项目概览
magicwindyyd
/
mindspore
与 Fork 源项目一致
Fork自
MindSpore / mindspore
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
mindspore
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
6a1b865c
编写于
3月 31, 2020
作者:
A
anzhengqi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
check num_samples
上级
569e5b05
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
30 addition
and
3 deletion
+30
-3
mindspore/dataset/engine/validators.py
mindspore/dataset/engine/validators.py
+8
-0
tests/ut/python/dataset/test_datasets_sharding.py
tests/ut/python/dataset/test_datasets_sharding.py
+3
-3
tests/ut/python/dataset/test_exceptions.py
tests/ut/python/dataset/test_exceptions.py
+19
-0
未找到文件。
mindspore/dataset/engine/validators.py
浏览文件 @
6a1b865c
...
...
@@ -243,6 +243,8 @@ def check_param_type(param_list, param_dict, param_type):
if
param_dict
.
get
(
param_name
)
is
not
None
:
if
param_name
==
'num_parallel_workers'
:
check_num_parallel_workers
(
param_dict
.
get
(
param_name
))
if
param_name
==
'num_samples'
:
check_num_samples
(
param_dict
.
get
(
param_name
))
else
:
check_type
(
param_dict
.
get
(
param_name
),
param_name
,
param_type
)
...
...
@@ -262,6 +264,12 @@ def check_num_parallel_workers(value):
raise
ValueError
(
"num_parallel_workers exceeds the boundary between 0 and {}!"
.
format
(
cpu_count
()))
def
check_num_samples
(
value
):
check_type
(
value
,
'num_samples'
,
int
)
if
value
<=
0
:
raise
ValueError
(
"num_samples must be greater than 0!"
)
def
check_dataset_dir
(
dataset_dir
):
if
not
os
.
path
.
isdir
(
dataset_dir
)
or
not
os
.
access
(
dataset_dir
,
os
.
R_OK
):
raise
ValueError
(
"The folder {} does not exist or permission denied!"
.
format
(
dataset_dir
))
...
...
tests/ut/python/dataset/test_datasets_sharding.py
浏览文件 @
6a1b865c
...
...
@@ -33,14 +33,14 @@ def test_imagefolder_shardings(print_res=False):
# total 44 rows in dataset
assert
(
sharding_config
(
4
,
0
,
5
,
False
,
dict
())
==
[
0
,
0
,
0
,
1
,
1
])
# 5 rows
assert
(
sharding_config
(
4
,
0
,
12
,
False
,
dict
())
==
[
0
,
0
,
0
,
1
,
1
,
1
,
2
,
2
,
2
,
3
,
3
])
# 11 rows
assert
(
sharding_config
(
4
,
3
,
0
,
False
,
dict
())
==
[
0
,
0
,
1
,
1
,
1
,
2
,
2
,
2
,
3
,
3
,
3
])
# 11 rows
assert
(
sharding_config
(
4
,
3
,
None
,
False
,
dict
())
==
[
0
,
0
,
1
,
1
,
1
,
2
,
2
,
2
,
3
,
3
,
3
])
# 11 rows
# total 22 in dataset rows because of class indexing which takes only 2 folders
assert
(
len
(
sharding_config
(
4
,
0
,
0
,
True
,
{
"class1"
:
111
,
"class2"
:
999
}))
==
6
)
assert
(
len
(
sharding_config
(
4
,
0
,
None
,
True
,
{
"class1"
:
111
,
"class2"
:
999
}))
==
6
)
assert
(
len
(
sharding_config
(
4
,
2
,
3
,
True
,
{
"class1"
:
111
,
"class2"
:
999
}))
==
3
)
# test with repeat
assert
(
sharding_config
(
4
,
0
,
12
,
False
,
dict
(),
3
)
==
[
0
,
0
,
0
,
1
,
1
,
1
,
2
,
2
,
2
,
3
,
3
]
*
3
)
assert
(
sharding_config
(
4
,
0
,
5
,
False
,
dict
(),
5
)
==
[
0
,
0
,
0
,
1
,
1
]
*
5
)
assert
(
len
(
sharding_config
(
5
,
1
,
0
,
True
,
{
"class1"
:
111
,
"class2"
:
999
},
4
))
==
20
)
assert
(
len
(
sharding_config
(
5
,
1
,
None
,
True
,
{
"class1"
:
111
,
"class2"
:
999
},
4
))
==
20
)
def
test_manifest_shardings
(
print_res
=
False
):
...
...
tests/ut/python/dataset/test_exceptions.py
浏览文件 @
6a1b865c
...
...
@@ -18,6 +18,7 @@ import pytest
import
mindspore.dataset
as
ds
DATA_DIR
=
[
"../data/dataset/test_tf_file_3_images/train-0000-of-0001.data"
]
SCHEMA_DIR
=
"../data/dataset/test_tf_file_3_images/datasetSchema.json"
def
skip_test_exception
():
...
...
@@ -29,5 +30,23 @@ def skip_test_exception():
assert
"The shape size 1 of input tensor is invalid"
in
str
(
info
.
value
)
def
test_sample_exception
():
num_samples
=
0
with
pytest
.
raises
(
ValueError
)
as
info
:
data
=
ds
.
TFRecordDataset
(
DATA_DIR
,
SCHEMA_DIR
,
columns_list
=
[
"image"
],
num_samples
=
num_samples
)
assert
"num_samples must be greater than 0"
in
str
(
info
.
value
)
num_samples
=
-
1
with
pytest
.
raises
(
ValueError
)
as
info
:
data
=
ds
.
TFRecordDataset
(
DATA_DIR
,
SCHEMA_DIR
,
columns_list
=
[
"image"
],
num_samples
=
num_samples
)
assert
"num_samples must be greater than 0"
in
str
(
info
.
value
)
num_samples
=
1
data
=
ds
.
TFRecordDataset
(
DATA_DIR
,
SCHEMA_DIR
,
columns_list
=
[
"image"
],
num_samples
=
num_samples
)
data
=
data
.
map
(
input_columns
=
[
"image"
],
operations
=
vision
.
Decode
())
data
=
data
.
map
(
input_columns
=
[
"image"
],
operations
=
vision
.
Resize
((
100
,
100
)))
num_iters
=
0
for
item
in
data
.
create_dict_iterator
():
num_iters
+=
1
assert
num_iters
==
1
if
__name__
==
'__main__'
:
test_exception
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录