Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
magicwindyyd
mindspore
提交
5871ba8a
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看板
提交
5871ba8a
编写于
7月 15, 2020
作者:
N
nhussain
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
more validator fixes
上级
25168309
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
87 addition
and
19 deletion
+87
-19
mindspore/dataset/core/validator_helpers.py
mindspore/dataset/core/validator_helpers.py
+3
-1
mindspore/dataset/engine/validators.py
mindspore/dataset/engine/validators.py
+2
-4
mindspore/dataset/text/validators.py
mindspore/dataset/text/validators.py
+1
-2
mindspore/dataset/transforms/vision/validators.py
mindspore/dataset/transforms/vision/validators.py
+8
-5
tests/ut/python/dataset/test_from_dataset.py
tests/ut/python/dataset/test_from_dataset.py
+1
-1
tests/ut/python/dataset/test_random_crop_and_resize.py
tests/ut/python/dataset/test_random_crop_and_resize.py
+28
-1
tests/ut/python/dataset/test_random_crop_with_bbox.py
tests/ut/python/dataset/test_random_crop_with_bbox.py
+28
-2
tests/ut/python/dataset/test_resize_with_bbox.py
tests/ut/python/dataset/test_resize_with_bbox.py
+14
-1
tests/ut/python/dataset/test_uniform_augment.py
tests/ut/python/dataset/test_uniform_augment.py
+2
-2
未找到文件。
mindspore/dataset/core/validator_helpers.py
浏览文件 @
5871ba8a
...
...
@@ -189,8 +189,10 @@ def type_check_list(args, types, arg_names):
Exception: when the type is not correct, otherwise nothing.
"""
type_check
(
args
,
(
list
,
tuple
,),
arg_names
)
if
len
(
args
)
!=
len
(
arg_names
):
if
len
(
args
)
!=
len
(
arg_names
)
and
not
isinstance
(
arg_names
,
str
)
:
raise
ValueError
(
"List of arguments is not the same length as argument_names."
)
if
isinstance
(
arg_names
,
str
):
arg_names
=
[
"{0}[{1}]"
.
format
(
arg_names
,
i
)
for
i
in
range
(
len
(
args
))]
for
arg
,
arg_name
in
zip
(
args
,
arg_names
):
type_check
(
arg
,
types
,
arg_name
)
...
...
mindspore/dataset/engine/validators.py
浏览文件 @
5871ba8a
...
...
@@ -686,8 +686,7 @@ def check_concat(method):
[
ds
],
_
=
parse_user_args
(
method
,
*
args
,
**
kwargs
)
type_check
(
ds
,
(
list
,
datasets
.
Dataset
),
"datasets"
)
if
isinstance
(
ds
,
list
):
dataset_names
=
[
"dataset[{0}]"
.
format
(
i
)
for
i
in
range
(
len
(
ds
))
if
isinstance
(
ds
,
list
)]
type_check_list
(
ds
,
(
datasets
.
Dataset
,),
dataset_names
)
type_check_list
(
ds
,
(
datasets
.
Dataset
,),
"dataset"
)
return
method
(
self
,
*
args
,
**
kwargs
)
return
new_method
...
...
@@ -751,8 +750,7 @@ def check_add_column(method):
if
shape
is
not
None
:
type_check
(
shape
,
(
list
,),
"shape"
)
shape_names
=
[
"shape[{0}]"
.
format
(
i
)
for
i
in
range
(
len
(
shape
))]
type_check_list
(
shape
,
(
int
,),
shape_names
)
type_check_list
(
shape
,
(
int
,),
"shape"
)
return
method
(
self
,
*
args
,
**
kwargs
)
...
...
mindspore/dataset/text/validators.py
浏览文件 @
5871ba8a
...
...
@@ -297,8 +297,7 @@ def check_from_dataset(method):
if
columns
is
not
None
:
if
not
isinstance
(
columns
,
list
):
columns
=
[
columns
]
col_names
=
[
"col_{0}"
.
format
(
i
)
for
i
in
range
(
len
(
columns
))]
type_check_list
(
columns
,
(
str
,),
col_names
)
type_check_list
(
columns
,
(
str
,),
"col"
)
if
freq_range
is
not
None
:
type_check
(
freq_range
,
(
tuple
,),
"freq_range"
)
...
...
mindspore/dataset/transforms/vision/validators.py
浏览文件 @
5871ba8a
...
...
@@ -78,6 +78,8 @@ def check_fill_value(fill_value):
def
check_padding
(
padding
):
"""Parsing the padding arguments and check if it is legal."""
type_check
(
padding
,
(
tuple
,
list
,
numbers
.
Number
),
"padding"
)
if
isinstance
(
padding
,
numbers
.
Number
):
check_value
(
padding
,
(
0
,
INT32_MAX
),
"padding"
)
if
isinstance
(
padding
,
(
tuple
,
list
)):
if
len
(
padding
)
not
in
(
2
,
4
):
raise
ValueError
(
"The size of the padding list or tuple should be 2 or 4."
)
...
...
@@ -163,10 +165,13 @@ def check_random_resize_crop(method):
check_crop_size
(
size
)
if
scale
is
not
None
:
type_check
(
scale
,
(
tuple
,),
"scale"
)
type_check_list
(
scale
,
(
float
,
int
),
"scale"
)
check_range
(
scale
,
[
0
,
FLOAT_MAX_INTEGER
])
if
ratio
is
not
None
:
type_check
(
ratio
,
(
tuple
,),
"ratio"
)
type_check_list
(
ratio
,
(
float
,
int
),
"ratio"
)
check_range
(
ratio
,
[
0
,
FLOAT_MAX_INTEGER
])
check_positive
(
ratio
[
0
],
"ratio[0]"
)
if
interpolation
is
not
None
:
type_check
(
interpolation
,
(
Inter
,),
"interpolation"
)
if
max_attempts
is
not
None
:
...
...
@@ -450,8 +455,7 @@ def check_random_affine(method):
if
translate
is
not
None
:
if
type_check
(
translate
,
(
list
,
tuple
),
"translate"
):
translate_names
=
[
"translate_{0}"
.
format
(
i
)
for
i
in
range
(
len
(
translate
))]
type_check_list
(
translate
,
(
int
,
float
),
translate_names
)
type_check_list
(
translate
,
(
int
,
float
),
"translate"
)
if
len
(
translate
)
!=
2
:
raise
TypeError
(
"translate should be a list or tuple of length 2."
)
for
i
,
t
in
enumerate
(
translate
):
...
...
@@ -508,8 +512,7 @@ def check_uniform_augment_cpp(method):
if
num_ops
>
len
(
operations
):
raise
ValueError
(
"num_ops is greater than operations list size"
)
tensor_ops
=
[
"tensor_op_{0}"
.
format
(
i
)
for
i
in
range
(
len
(
operations
))]
type_check_list
(
operations
,
(
TensorOp
,),
tensor_ops
)
type_check_list
(
operations
,
(
TensorOp
,),
"tensor_ops"
)
return
method
(
self
,
*
args
,
**
kwargs
)
...
...
tests/ut/python/dataset/test_from_dataset.py
浏览文件 @
5871ba8a
...
...
@@ -134,7 +134,7 @@ def test_from_dataset_exceptions():
test_config
(
"text"
,
(),
1
,
"freq_range needs to be a tuple of 2 integers or an int and a None."
)
test_config
(
"text"
,
(
2
,
3
),
1.2345
,
"Argument top_k with value 1.2345 is not of type (<class 'int'>, <class 'NoneType'>)"
)
test_config
(
23
,
(
2
,
3
),
1.2345
,
"Argument col
_0
with value 23 is not of type (<class 'str'>,)"
)
test_config
(
23
,
(
2
,
3
),
1.2345
,
"Argument col
[0]
with value 23 is not of type (<class 'str'>,)"
)
test_config
(
"text"
,
(
100
,
1
),
12
,
"frequency range [a,b] should be 0 <= a <= b (a,b are inclusive)"
)
test_config
(
"text"
,
(
2
,
3
),
0
,
"top_k must be greater than 0"
)
test_config
([
123
],
(
2
,
3
),
-
1
,
"top_k must be greater than 0"
)
...
...
tests/ut/python/dataset/test_random_crop_and_resize.py
浏览文件 @
5871ba8a
...
...
@@ -332,11 +332,37 @@ def test_random_crop_and_resize_comp(plot=False):
image_c_cropped
.
append
(
c_image
)
image_py_cropped
.
append
(
py_image
)
mse
=
diff_mse
(
c_image
,
py_image
)
assert
mse
<
0.02
# rounding error
assert
mse
<
0.02
# rounding error
if
plot
:
visualize_list
(
image_c_cropped
,
image_py_cropped
,
visualize_mode
=
2
)
def
test_random_crop_and_resize_06
():
"""
Test RandomCropAndResize with c_transforms: invalid values for scale,
expected to raise ValueError
"""
logger
.
info
(
"test_random_crop_and_resize_05_c"
)
# Generate dataset
data
=
ds
.
TFRecordDataset
(
DATA_DIR
,
SCHEMA_DIR
,
columns_list
=
[
"image"
],
shuffle
=
False
)
decode_op
=
c_vision
.
Decode
()
try
:
random_crop_and_resize_op
=
c_vision
.
RandomResizedCrop
((
256
,
512
),
scale
=
""
,
ratio
=
(
1
,
0.5
))
data
=
data
.
map
(
input_columns
=
[
"image"
],
operations
=
decode_op
)
data
.
map
(
input_columns
=
[
"image"
],
operations
=
random_crop_and_resize_op
)
except
TypeError
as
e
:
logger
.
info
(
"Got an exception in DE: {}"
.
format
(
str
(
e
)))
assert
"Argument scale with value
\"\"
is not of type (<class 'tuple'>,)"
in
str
(
e
)
try
:
random_crop_and_resize_op
=
c_vision
.
RandomResizedCrop
((
256
,
512
),
scale
=
(
1
,
"2"
),
ratio
=
(
1
,
0.5
))
data
=
data
.
map
(
input_columns
=
[
"image"
],
operations
=
decode_op
)
data
.
map
(
input_columns
=
[
"image"
],
operations
=
random_crop_and_resize_op
)
except
TypeError
as
e
:
logger
.
info
(
"Got an exception in DE: {}"
.
format
(
str
(
e
)))
assert
"Argument scale[1] with value 2 is not of type (<class 'float'>, <class 'int'>)."
in
str
(
e
)
if
__name__
==
"__main__"
:
test_random_crop_and_resize_op_c
(
True
)
test_random_crop_and_resize_op_py
(
True
)
...
...
@@ -347,4 +373,5 @@ if __name__ == "__main__":
test_random_crop_and_resize_04_py
()
test_random_crop_and_resize_05_c
()
test_random_crop_and_resize_05_py
()
test_random_crop_and_resize_06
()
test_random_crop_and_resize_comp
(
True
)
tests/ut/python/dataset/test_random_crop_with_bbox.py
浏览文件 @
5871ba8a
...
...
@@ -178,13 +178,15 @@ def test_random_crop_with_bbox_op_edge_c(plot_vis=False):
dataVoc1
=
dataVoc1
.
map
(
input_columns
=
[
"image"
,
"annotation"
],
output_columns
=
[
"image"
,
"annotation"
],
columns_order
=
[
"image"
,
"annotation"
],
operations
=
[
lambda
img
,
bboxes
:
(
img
,
np
.
array
([[
0
,
0
,
img
.
shape
[
1
],
img
.
shape
[
0
]]]).
astype
(
bboxes
.
dtype
))])
operations
=
[
lambda
img
,
bboxes
:
(
img
,
np
.
array
([[
0
,
0
,
img
.
shape
[
1
],
img
.
shape
[
0
]]]).
astype
(
bboxes
.
dtype
))])
# Test Op added to list of Operations here
dataVoc2
=
dataVoc2
.
map
(
input_columns
=
[
"image"
,
"annotation"
],
output_columns
=
[
"image"
,
"annotation"
],
columns_order
=
[
"image"
,
"annotation"
],
operations
=
[
lambda
img
,
bboxes
:
(
img
,
np
.
array
([[
0
,
0
,
img
.
shape
[
1
],
img
.
shape
[
0
]]]).
astype
(
bboxes
.
dtype
)),
test_op
])
operations
=
[
lambda
img
,
bboxes
:
(
img
,
np
.
array
([[
0
,
0
,
img
.
shape
[
1
],
img
.
shape
[
0
]]]).
astype
(
bboxes
.
dtype
)),
test_op
])
unaugSamp
,
augSamp
=
[],
[]
...
...
@@ -239,6 +241,29 @@ def test_random_crop_with_bbox_op_bad_c():
check_bad_bbox
(
data_voc2
,
test_op
,
InvalidBBoxType
.
WrongShape
,
"4 features"
)
def
test_random_crop_with_bbox_op_negative_padding
():
"""
Test RandomCropWithBBox Op on invalid constructor parameters, expected to raise ValueError
"""
logger
.
info
(
"test_random_crop_with_bbox_op_invalid_c"
)
dataVoc2
=
ds
.
VOCDataset
(
DATA_DIR_VOC
,
task
=
"Detection"
,
mode
=
"train"
,
decode
=
True
,
shuffle
=
False
)
try
:
test_op
=
c_vision
.
RandomCropWithBBox
([
512
,
512
],
padding
=-
1
)
dataVoc2
=
dataVoc2
.
map
(
input_columns
=
[
"image"
,
"annotation"
],
output_columns
=
[
"image"
,
"annotation"
],
columns_order
=
[
"image"
,
"annotation"
],
operations
=
[
test_op
])
for
_
in
dataVoc2
.
create_dict_iterator
():
break
except
ValueError
as
err
:
logger
.
info
(
"Got an exception in DE: {}"
.
format
(
str
(
err
)))
assert
"Input padding is not within the required interval of (0 to 2147483647)."
in
str
(
err
)
if
__name__
==
"__main__"
:
test_random_crop_with_bbox_op_c
(
plot_vis
=
True
)
test_random_crop_with_bbox_op_coco_c
(
plot_vis
=
True
)
...
...
@@ -247,3 +272,4 @@ if __name__ == "__main__":
test_random_crop_with_bbox_op_edge_c
(
plot_vis
=
True
)
test_random_crop_with_bbox_op_invalid_c
()
test_random_crop_with_bbox_op_bad_c
()
test_random_crop_with_bbox_op_negative_padding
()
tests/ut/python/dataset/test_resize_with_bbox.py
浏览文件 @
5871ba8a
...
...
@@ -16,9 +16,10 @@
Testing the resize with bounding boxes op in DE
"""
import
numpy
as
np
import
pytest
import
mindspore.dataset
as
ds
import
mindspore.dataset.transforms.vision.c_transforms
as
c_vision
from
mindspore
import
log
as
logger
from
util
import
visualize_with_bounding_boxes
,
InvalidBBoxType
,
check_bad_bbox
,
\
save_and_check_md5
...
...
@@ -172,6 +173,18 @@ def test_resize_with_bbox_op_bad_c():
check_bad_bbox
(
data_voc2
,
test_op
,
InvalidBBoxType
.
WrongShape
,
"4 features"
)
def
test_resize_with_bbox_op_params_outside_of_interpolation_dict
():
"""
Test passing in a invalid key for interpolation
"""
logger
.
info
(
"test_resize_with_bbox_op_params_outside_of_interpolation_dict"
)
size
=
(
500
,
500
)
more_para
=
None
with
pytest
.
raises
(
KeyError
,
match
=
"None"
):
c_vision
.
ResizeWithBBox
(
size
,
more_para
)
if
__name__
==
"__main__"
:
test_resize_with_bbox_op_voc_c
(
plot_vis
=
False
)
test_resize_with_bbox_op_coco_c
(
plot_vis
=
False
)
...
...
tests/ut/python/dataset/test_uniform_augment.py
浏览文件 @
5871ba8a
...
...
@@ -166,10 +166,10 @@ def test_cpp_uniform_augment_exception_pyops(num_ops=2):
F
.
Invert
()]
with
pytest
.
raises
(
TypeError
)
as
e
:
_
=
C
.
UniformAugment
(
operations
=
transforms_ua
,
num_ops
=
num_ops
)
C
.
UniformAugment
(
operations
=
transforms_ua
,
num_ops
=
num_ops
)
logger
.
info
(
"Got an exception in DE: {}"
.
format
(
str
(
e
)))
assert
"Argument tensor_op
_5
with value"
\
assert
"Argument tensor_op
s[5]
with value"
\
" <mindspore.dataset.transforms.vision.py_transforms.Invert"
in
str
(
e
.
value
)
assert
"is not of type (<class 'mindspore._c_dataengine.TensorOp'>,)"
in
str
(
e
.
value
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录