Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
magicwindyyd
mindspore
提交
c984b0fc
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看板
提交
c984b0fc
编写于
7月 16, 2020
作者:
N
nhussain
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix size tuple
上级
863f4e4f
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
117 addition
and
2 deletion
+117
-2
mindspore/dataset/transforms/vision/c_transforms.py
mindspore/dataset/transforms/vision/c_transforms.py
+0
-2
tests/ut/data/dataset/golden/resize_01_result.npz
tests/ut/data/dataset/golden/resize_01_result.npz
+0
-0
tests/ut/data/dataset/golden/resize_02_result.npz
tests/ut/data/dataset/golden/resize_02_result.npz
+0
-0
tests/ut/python/dataset/test_resize.py
tests/ut/python/dataset/test_resize.py
+117
-0
未找到文件。
mindspore/dataset/transforms/vision/c_transforms.py
浏览文件 @
c984b0fc
...
...
@@ -319,8 +319,6 @@ class Resize(cde.ResizeOp):
@
check_resize_interpolation
def
__init__
(
self
,
size
,
interpolation
=
Inter
.
LINEAR
):
if
isinstance
(
size
,
int
):
size
=
(
size
,
size
)
self
.
size
=
size
self
.
interpolation
=
interpolation
interpoltn
=
DE_C_INTER_MODE
[
interpolation
]
...
...
tests/ut/data/dataset/golden/resize_01_result.npz
0 → 100644
浏览文件 @
c984b0fc
文件已添加
tests/ut/data/dataset/golden/resize_02_result.npz
0 → 100644
浏览文件 @
c984b0fc
文件已添加
tests/ut/python/dataset/test_resize.py
0 → 100644
浏览文件 @
c984b0fc
# Copyright 2020 Huawei Technologies Co., Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""
Testing Resize op in DE
"""
import
pytest
import
mindspore.dataset
as
ds
import
mindspore.dataset.transforms.vision.c_transforms
as
vision
from
mindspore.dataset.transforms.vision.utils
import
Inter
from
mindspore
import
log
as
logger
from
util
import
visualize_list
,
save_and_check_md5
,
\
config_get_set_seed
,
config_get_set_num_parallel_workers
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"
GENERATE_GOLDEN
=
False
def
test_resize_op
(
plot
=
False
):
def
test_resize_op_parameters
(
test_name
,
size
,
plot
):
"""
Test resize_op
"""
logger
.
info
(
"Test resize: {0}"
.
format
(
test_name
))
data1
=
ds
.
TFRecordDataset
(
DATA_DIR
,
SCHEMA_DIR
,
columns_list
=
[
"image"
],
shuffle
=
False
)
# define map operations
decode_op
=
vision
.
Decode
()
resize_op
=
vision
.
Resize
(
size
)
# apply map operations on images
data1
=
data1
.
map
(
input_columns
=
[
"image"
],
operations
=
decode_op
)
data2
=
data1
.
map
(
input_columns
=
[
"image"
],
operations
=
resize_op
)
image_original
=
[]
image_resized
=
[]
for
item1
,
item2
in
zip
(
data1
.
create_dict_iterator
(),
data2
.
create_dict_iterator
()):
image_1
=
item1
[
"image"
]
image_2
=
item2
[
"image"
]
image_original
.
append
(
image_1
)
image_resized
.
append
(
image_2
)
if
plot
:
visualize_list
(
image_original
,
image_resized
)
test_resize_op_parameters
(
"Test single int for size"
,
10
,
plot
=
False
)
test_resize_op_parameters
(
"Test tuple for size"
,
(
10
,
15
),
plot
=
False
)
def
test_resize_md5
(
plot
=
False
):
def
test_resize_md5_parameters
(
test_name
,
size
,
filename
,
seed
,
plot
):
"""
Test Resize with md5 check
"""
logger
.
info
(
"Test Resize with md5 check: {0}"
.
format
(
test_name
))
original_seed
=
config_get_set_seed
(
seed
)
original_num_parallel_workers
=
config_get_set_num_parallel_workers
(
1
)
# Generate dataset
data1
=
ds
.
TFRecordDataset
(
DATA_DIR
,
SCHEMA_DIR
,
columns_list
=
[
"image"
],
shuffle
=
False
)
decode_op
=
vision
.
Decode
()
resize_op
=
vision
.
Resize
(
size
)
data1
=
data1
.
map
(
input_columns
=
[
"image"
],
operations
=
decode_op
)
data2
=
data1
.
map
(
input_columns
=
[
"image"
],
operations
=
resize_op
)
image_original
=
[]
image_resized
=
[]
# Compare with expected md5 from images
save_and_check_md5
(
data1
,
filename
,
generate_golden
=
GENERATE_GOLDEN
)
for
item1
,
item2
in
zip
(
data1
.
create_dict_iterator
(),
data2
.
create_dict_iterator
()):
image_1
=
item1
[
"image"
]
image_2
=
item2
[
"image"
]
image_original
.
append
(
image_1
)
image_resized
.
append
(
image_2
)
if
plot
:
visualize_list
(
image_original
,
image_resized
)
# Restore configuration
ds
.
config
.
set_seed
(
original_seed
)
ds
.
config
.
set_num_parallel_workers
(
original_num_parallel_workers
)
test_resize_md5_parameters
(
"Test single int for size"
,
5
,
"resize_01_result.npz"
,
5
,
plot
)
test_resize_md5_parameters
(
"Test tuple for size"
,
(
5
,
7
),
"resize_02_result.npz"
,
7
,
plot
)
def
test_resize_op_invalid_input
():
def
test_invalid_input
(
test_name
,
size
,
interpolation
,
error
,
error_msg
):
logger
.
info
(
"Test Resize with bad input: {0}"
.
format
(
test_name
))
with
pytest
.
raises
(
error
)
as
error_info
:
vision
.
Resize
(
size
,
interpolation
)
assert
error_msg
in
str
(
error_info
.
value
)
test_invalid_input
(
"invalid size parameter type as a single number"
,
4.5
,
Inter
.
LINEAR
,
TypeError
,
"Size should be a single integer or a list/tuple (h, w) of length 2."
)
test_invalid_input
(
"invalid size parameter shape"
,
(
2
,
3
,
4
),
Inter
.
LINEAR
,
TypeError
,
"Size should be a single integer or a list/tuple (h, w) of length 2."
)
test_invalid_input
(
"invalid size parameter type in a tuple"
,
(
2.3
,
3
),
Inter
.
LINEAR
,
TypeError
,
"incompatible constructor arguments."
)
test_invalid_input
(
"invalid Interpolation value"
,
(
2.3
,
3
),
None
,
KeyError
,
"None"
)
if
__name__
==
"__main__"
:
test_resize_op
(
plot
=
True
)
test_resize_md5
(
plot
=
True
)
test_resize_op_invalid_input
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录