Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
magicwindyyd
mindspore
提交
b064cbab
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看板
提交
b064cbab
编写于
7月 20, 2020
作者:
N
nhussain
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix upper bound
上级
57252dee
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
71 addition
and
7 deletion
+71
-7
mindspore/ccsrc/minddata/dataset/kernels/image/center_crop_op.cc
...re/ccsrc/minddata/dataset/kernels/image/center_crop_op.cc
+4
-0
mindspore/ccsrc/minddata/dataset/kernels/image/random_crop_op.cc
...re/ccsrc/minddata/dataset/kernels/image/random_crop_op.cc
+4
-0
tests/ut/cpp/dataset/center_crop_op_test.cc
tests/ut/cpp/dataset/center_crop_op_test.cc
+17
-4
tests/ut/cpp/dataset/random_crop_with_bbox_op_test.cc
tests/ut/cpp/dataset/random_crop_with_bbox_op_test.cc
+19
-1
tests/ut/python/dataset/test_center_crop.py
tests/ut/python/dataset/test_center_crop.py
+11
-0
tests/ut/python/dataset/test_random_crop_with_bbox.py
tests/ut/python/dataset/test_random_crop_with_bbox.py
+16
-2
未找到文件。
mindspore/ccsrc/minddata/dataset/kernels/image/center_crop_op.cc
浏览文件 @
b064cbab
...
...
@@ -36,6 +36,10 @@ Status CenterCropOp::Compute(const std::shared_ptr<Tensor> &input, std::shared_p
int32_t
top
=
crop_het_
-
input
->
shape
()[
0
];
// number of pixels to pad (top and bottom)
int32_t
left
=
crop_wid_
-
input
->
shape
()[
1
];
std
::
shared_ptr
<
Tensor
>
pad_image
;
CHECK_FAIL_RETURN_UNEXPECTED
((
top
<
input
->
shape
()[
0
]
*
10
&&
left
<
input
->
shape
()[
1
]
*
10
),
"CenterCropOp padding size is too big, it's more than 10 times the original size."
);
if
(
top
>
0
&&
left
>
0
)
{
// padding only
return
Pad
(
input
,
output
,
top
/
2
+
top
%
2
,
top
/
2
,
left
/
2
+
left
%
2
,
left
/
2
,
BorderType
::
kConstant
);
}
else
if
(
top
>
0
)
{
...
...
mindspore/ccsrc/minddata/dataset/kernels/image/random_crop_op.cc
浏览文件 @
b064cbab
...
...
@@ -56,6 +56,10 @@ Status RandomCropOp::ImagePadding(const std::shared_ptr<Tensor> &input, std::sha
*
t_pad_left
=
pad_left_
;
*
t_pad_right
=
pad_right_
;
CHECK_FAIL_RETURN_UNEXPECTED
(
pad_top_
<
input
->
shape
()[
0
]
*
3
&&
pad_bottom_
<
input
->
shape
()[
0
]
*
3
&&
pad_left_
<
input
->
shape
()[
1
]
*
3
&&
pad_right_
<
input
->
shape
()[
1
]
*
3
,
"RandomCropBBoxOp padding size is too big, it's more than 3 times the original size."
);
RETURN_IF_NOT_OK
(
Pad
(
input
,
pad_image
,
pad_top_
,
pad_bottom_
,
pad_left_
,
pad_right_
,
border_type_
,
fill_r_
,
fill_g_
,
fill_b_
));
CHECK_FAIL_RETURN_UNEXPECTED
((
*
pad_image
)
->
shape
().
Size
()
>=
2
,
"Abnormal shape"
);
...
...
tests/ut/cpp/dataset/center_crop_op_test.cc
浏览文件 @
b064cbab
...
...
@@ -20,17 +20,17 @@
#include "utils/log_adapter.h"
using
namespace
mindspore
::
dataset
;
using
mindspore
::
MsLogLevel
::
INFO
;
using
mindspore
::
ExceptionType
::
NoExceptionType
;
using
mindspore
::
LogStream
;
using
mindspore
::
ExceptionType
::
NoExceptionType
;
using
mindspore
::
MsLogLevel
::
INFO
;
class
MindDataTestCenterCropOp
:
public
UT
::
CVOP
::
CVOpCommon
{
public:
MindDataTestCenterCropOp
()
:
CVOpCommon
()
{}
};
TEST_F
(
MindDataTestCenterCropOp
,
TestOp
)
{
MS_LOG
(
INFO
)
<<
"Doing MindDataTestCenterCropOp::TestOp."
;
TEST_F
(
MindDataTestCenterCropOp
,
TestOp
1
)
{
MS_LOG
(
INFO
)
<<
"Doing MindDataTestCenterCropOp::TestOp
1
."
;
std
::
shared_ptr
<
Tensor
>
output_tensor
;
int
het
=
256
;
int
wid
=
128
;
...
...
@@ -42,3 +42,16 @@ TEST_F(MindDataTestCenterCropOp, TestOp) {
EXPECT_EQ
(
wid
,
output_tensor
->
shape
()[
1
]);
std
::
shared_ptr
<
CVTensor
>
p
=
CVTensor
::
AsCVTensor
(
output_tensor
);
}
TEST_F
(
MindDataTestCenterCropOp
,
TestOp2
)
{
MS_LOG
(
INFO
)
<<
"MindDataTestCenterCropOp::TestOp2. Cap valid crop size at 10 times the input size"
;
std
::
shared_ptr
<
Tensor
>
output_tensor
;
int64_t
wid
=
input_tensor_
->
shape
()[
0
]
*
10
+
1
;
int64_t
het
=
input_tensor_
->
shape
()[
1
]
*
10
+
1
;
std
::
unique_ptr
<
CenterCropOp
>
op
(
new
CenterCropOp
(
het
,
wid
));
Status
s
=
op
->
Compute
(
input_tensor_
,
&
output_tensor
);
EXPECT_TRUE
(
s
.
IsError
());
ASSERT_TRUE
(
s
.
get_code
()
==
StatusCode
::
kUnexpectedError
);
}
tests/ut/cpp/dataset/random_crop_with_bbox_op_test.cc
浏览文件 @
b064cbab
...
...
@@ -66,6 +66,7 @@ TEST_F(MindDataTestRandomCropWithBBoxOp, TestOp1) {
}
GlobalContext
::
config_manager
()
->
set_seed
(
current_seed
);
}
MS_LOG
(
INFO
)
<<
"testRandomCropWithBBoxOp1 end."
;
}
TEST_F
(
MindDataTestRandomCropWithBBoxOp
,
TestOp2
)
{
...
...
@@ -87,5 +88,22 @@ TEST_F(MindDataTestRandomCropWithBBoxOp, TestOp2) {
EXPECT_EQ
(
s
,
Status
::
OK
());
EXPECT_EQ
(
4
,
output_tensor_row_
[
1
]
->
shape
()[
1
]);
// check for existence of 4 columns
}
MS_LOG
(
INFO
)
<<
"testRandomCropWithBBoxOp end."
;
MS_LOG
(
INFO
)
<<
"testRandomCropWithBBoxOp
2
end."
;
}
TEST_F
(
MindDataTestRandomCropWithBBoxOp
,
TestOp3
)
{
MS_LOG
(
INFO
)
<<
"Doing testRandomCropWithBBoxOp3."
;
// Crop params
unsigned
int
crop_height
=
1280
;
unsigned
int
crop_width
=
1280
;
std
::
unique_ptr
<
RandomCropWithBBoxOp
>
op
(
new
RandomCropWithBBoxOp
(
crop_height
,
crop_width
,
crop_height
*
3
+
1
,
crop_height
*
3
+
1
,
crop_width
*
3
+
1
,
crop_width
*
3
+
1
,
BorderType
::
kConstant
,
false
));
for
(
auto
tensor_row_
:
images_and_annotations_
)
{
Status
s
=
op
->
Compute
(
tensor_row_
,
&
output_tensor_row_
);
EXPECT_TRUE
(
s
.
IsError
());
ASSERT_TRUE
(
s
.
get_code
()
==
StatusCode
::
kUnexpectedError
);
}
MS_LOG
(
INFO
)
<<
"testRandomCropWithBBoxOp3 end."
;
}
\ No newline at end of file
tests/ut/python/dataset/test_center_crop.py
浏览文件 @
b064cbab
...
...
@@ -138,6 +138,17 @@ def test_crop_grayscale(height=375, width=375):
assert
(
c_image
.
ndim
==
3
and
c_image
.
shape
[
2
]
==
1
)
def
test_center_crop_errors
():
"""
Test that CenterCropOp errors with bad input
"""
try
:
test_center_crop_op
(
16777216
,
16777216
)
except
RuntimeError
as
e
:
assert
"Unexpected error. CenterCropOp padding size is too big, it's more than 10 times the original size."
in
\
str
(
e
)
if
__name__
==
"__main__"
:
test_center_crop_op
(
600
,
600
,
plot
=
True
)
test_center_crop_op
(
300
,
600
)
...
...
tests/ut/python/dataset/test_random_crop_with_bbox.py
浏览文件 @
b064cbab
...
...
@@ -241,7 +241,7 @@ 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
():
def
test_random_crop_with_bbox_op_
bad
_padding
():
"""
Test RandomCropWithBBox Op on invalid constructor parameters, expected to raise ValueError
"""
...
...
@@ -263,6 +263,20 @@ def test_random_crop_with_bbox_op_negative_padding():
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
)
try
:
test_op
=
c_vision
.
RandomCropWithBBox
([
512
,
512
],
padding
=
[
16777216
,
16777216
,
16777216
,
16777216
])
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
RuntimeError
as
err
:
logger
.
info
(
"Got an exception in DE: {}"
.
format
(
str
(
err
)))
assert
"RandomCropBBoxOp padding size is too big, it
\'
s more than 3 times the original size."
in
str
(
err
)
if
__name__
==
"__main__"
:
test_random_crop_with_bbox_op_c
(
plot_vis
=
True
)
...
...
@@ -272,4 +286,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
()
test_random_crop_with_bbox_op_
bad
_padding
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录