Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
magicwindyyd
mindspore
提交
b9701db8
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看板
提交
b9701db8
编写于
4月 02, 2020
作者:
A
Alexey Shevlyakov
提交者:
高东海
4月 10, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix RandomCropDecodeResize test
上级
22578e98
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
62 addition
and
81 deletion
+62
-81
tests/ut/cpp/dataset/CMakeLists.txt
tests/ut/cpp/dataset/CMakeLists.txt
+1
-1
tests/ut/cpp/dataset/random_crop_and_resize_op_test.cc
tests/ut/cpp/dataset/random_crop_and_resize_op_test.cc
+9
-27
tests/ut/cpp/dataset/random_crop_decode_resize_op_test.cc
tests/ut/cpp/dataset/random_crop_decode_resize_op_test.cc
+52
-53
未找到文件。
tests/ut/cpp/dataset/CMakeLists.txt
浏览文件 @
b9701db8
...
...
@@ -32,7 +32,7 @@ SET(DE_UT_SRCS
project_op_test.cc
queue_test.cc
random_crop_op_test.cc
random_crop_decode_resize
O
p_test.cc
random_crop_decode_resize
_o
p_test.cc
random_crop_and_resize_op_test.cc
random_color_adjust_op_test.cc
random_horizontal_flip_op_test.cc
...
...
tests/ut/cpp/dataset/random_crop_and_resize_op_test.cc
浏览文件 @
b9701db8
...
...
@@ -20,35 +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
MindDataTestRandomCropAndResizeOp
:
public
UT
::
CVOP
::
CVOpCommon
{
public:
MindDataTestRandomCropAndResizeOp
()
:
CVOpCommon
()
{}
};
TEST_F
(
MindDataTestRandomCropAndResizeOp
,
TestOpDefault
)
{
MS_LOG
(
INFO
)
<<
"Doing testRandomCropAndResize."
;
TensorShape
s_in
=
input_tensor_
->
shape
();
std
::
shared_ptr
<
Tensor
>
output_tensor
;
int
h_out
=
512
;
int
w_out
=
512
;
TensorShape
s_out
({(
uint32_t
)
h_out
,
(
uint32_t
)
w_out
,
(
uint32_t
)
s_in
[
2
]});
std
::
unique_ptr
<
RandomCropAndResizeOp
>
op
(
new
RandomCropAndResizeOp
(
h_out
,
w_out
));
Status
s
;
for
(
auto
i
=
0
;
i
<
100
;
i
++
)
{
s
=
op
->
Compute
(
input_tensor_
,
&
output_tensor
);
}
EXPECT_TRUE
(
s
.
IsOk
());
MS_LOG
(
INFO
)
<<
"testRandomCropAndResize end."
;
}
TEST_F
(
MindDataTestRandomCropAndResizeOp
,
TestOpExtended
)
{
MS_LOG
(
INFO
)
<<
"Doing testRandomCropAndResize."
;
TEST_F
(
MindDataTestRandomCropAndResizeOp
,
TestOpSimpleTest
)
{
MS_LOG
(
INFO
)
<<
" starting RandomCropAndResizeOp simple test"
;
TensorShape
s_in
=
input_tensor_
->
shape
();
std
::
shared_ptr
<
Tensor
>
output_tensor
;
int
h_out
=
1024
;
...
...
@@ -58,14 +40,14 @@ TEST_F(MindDataTestRandomCropAndResizeOp, TestOpExtended) {
float
scale_lb
=
0.0001
;
float
scale_ub
=
1.0
;
TensorShape
s_out
({
(
uint32_t
)
h_out
,
(
uint32_t
)
w_out
,
(
uint32_t
)
s_in
[
2
]});
TensorShape
s_out
({
h_out
,
w_out
,
s_in
[
2
]});
std
::
unique_ptr
<
RandomCropAndResizeOp
>
op
(
new
RandomCropAndResizeOp
(
h_out
,
w_out
,
scale_lb
,
scale_ub
,
aspect_lb
,
aspect_ub
));
auto
op
=
std
::
make_unique
<
RandomCropAndResizeOp
>
(
h_out
,
w_out
,
scale_lb
,
scale_ub
,
aspect_lb
,
aspect_ub
);
Status
s
;
for
(
auto
i
=
0
;
i
<
100
;
i
++
)
{
s
=
op
->
Compute
(
input_tensor_
,
&
output_tensor
);
EXPECT_TRUE
(
s
.
IsOk
());
}
EXPECT_TRUE
(
s
.
IsOk
());
MS_LOG
(
INFO
)
<<
"
testRandomCropAndResize end.
"
;
MS_LOG
(
INFO
)
<<
"
RandomCropAndResizeOp simple test finished
"
;
}
tests/ut/cpp/dataset/random_crop_decode_resize
O
p_test.cc
→
tests/ut/cpp/dataset/random_crop_decode_resize
_o
p_test.cc
浏览文件 @
b9701db8
...
...
@@ -23,9 +23,10 @@
#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
;
constexpr
double
kMseThreshold
=
2.0
;
class
MindDataTestRandomCropDecodeResizeOp
:
public
UT
::
CVOP
::
CVOpCommon
{
public:
...
...
@@ -33,39 +34,38 @@ class MindDataTestRandomCropDecodeResizeOp : public UT::CVOP::CVOpCommon {
};
TEST_F
(
MindDataTestRandomCropDecodeResizeOp
,
TestOp2
)
{
MS_LOG
(
INFO
)
<<
"
Doing testRandomCropDecodeResizeOp Test
"
;
MS_LOG
(
INFO
)
<<
"
starting RandomCropDecodeResizeOp test 1
"
;
std
::
shared_ptr
<
Tensor
>
output_tensor1
;
std
::
shared_ptr
<
Tensor
>
output_tensor2
;
std
::
shared_ptr
<
Tensor
>
decode_and_crop_output
;
std
::
shared_ptr
<
Tensor
>
crop_and_decode_output
;
int
target_height
=
884
;
int
target_width
=
718
;
float
scale_lb
=
0.08
;
float
scale_ub
=
1.0
;
float
aspect_lb
=
0.75
;
float
aspect_ub
=
1.333333
;
InterpolationMode
interpolation
=
InterpolationMode
::
kLinear
;
uint32_t
max_iter
=
10
;
std
::
unique_ptr
<
RandomCropAndResizeOp
>
op1
(
new
RandomCropAndResizeOp
(
target_height
,
target_width
,
scale_lb
,
scale_ub
,
aspect_lb
,
aspect_ub
,
interpolation
,
max_iter
));
EXPECT_TRUE
(
op1
->
OneToOne
());
std
::
unique_ptr
<
RandomCropDecodeResizeOp
>
op2
(
new
RandomCropDecodeResizeOp
(
target_height
,
target_width
,
scale_lb
,
scale_ub
,
aspect_lb
,
aspect_ub
,
interpolation
,
max_iter
));
EXPECT_TRUE
(
op2
->
OneToOne
());
Status
s1
,
s2
;
constexpr
int
target_height
=
884
;
constexpr
int
target_width
=
718
;
constexpr
float
scale_lb
=
0.08
;
constexpr
float
scale_ub
=
1.0
;
constexpr
float
aspect_lb
=
0.75
;
constexpr
float
aspect_ub
=
1.333333
;
const
InterpolationMode
interpolation
=
InterpolationMode
::
kLinear
;
constexpr
uint32_t
max_iter
=
10
;
auto
crop_and_decode
=
RandomCropDecodeResizeOp
(
target_height
,
target_width
,
scale_lb
,
scale_ub
,
aspect_lb
,
aspect_ub
,
interpolation
,
max_iter
);
auto
crop_and_decode_copy
=
crop_and_decode
;
auto
decode_and_crop
=
static_cast
<
RandomCropAndResizeOp
>
(
crop_and_decode_copy
);
EXPECT_TRUE
(
crop_and_decode
.
OneToOne
());
GlobalContext
::
config_manager
()
->
set_seed
(
42
);
for
(
int
i
=
0
;
i
<
100
;
i
++
)
{
s1
=
op1
->
Compute
(
input_tensor_
,
&
output_tensor1
);
s2
=
op2
->
Compute
(
raw_input_tensor_
,
&
output_tensor2
);
cv
::
Mat
output1
(
target_height
,
target_width
,
CV_8UC3
,
output_tensor1
->
StartAddr
());
cv
::
Mat
output2
(
target_height
,
target_width
,
CV_8UC3
,
output_tensor2
->
StartAddr
());
(
void
)
crop_and_decode
.
Compute
(
raw_input_tensor_
,
&
crop_and_decode_output
);
(
void
)
decode_and_crop
.
Compute
(
input_tensor_
,
&
decode_and_crop_output
);
cv
::
Mat
output1
(
target_height
,
target_width
,
CV_8UC3
,
crop_and_decode_output
->
StartAddr
());
cv
::
Mat
output2
(
target_height
,
target_width
,
CV_8UC3
,
decode_and_crop_output
->
StartAddr
());
long
int
mse_sum
=
0
;
long
int
count
=
0
;
int
a
,
b
;
for
(
int
i
=
0
;
i
<
target_height
;
i
++
)
{
for
(
int
j
=
0
;
j
<
target_width
;
j
++
)
{
a
=
(
int
)
output1
.
at
<
cv
::
Vec3b
>
(
i
,
j
)[
1
]
;
b
=
(
int
)
output2
.
at
<
cv
::
Vec3b
>
(
i
,
j
)[
1
]
;
for
(
int
j
=
0
;
j
<
target_height
;
j
++
)
{
for
(
int
k
=
0
;
k
<
target_width
;
k
++
)
{
a
=
static_cast
<
int
>
(
output1
.
at
<
cv
::
Vec3b
>
(
i
,
j
)[
1
])
;
b
=
static_cast
<
int
>
(
output2
.
at
<
cv
::
Vec3b
>
(
i
,
j
)[
1
])
;
mse_sum
+=
sqrt
((
a
-
b
)
*
(
a
-
b
));
if
(
a
!=
b
)
{
count
++
;
...
...
@@ -73,24 +73,22 @@ TEST_F(MindDataTestRandomCropDecodeResizeOp, TestOp2) {
}
}
double
mse
;
if
(
count
>
0
)
{
mse
=
(
double
)
mse_sum
/
count
;
}
else
{
mse
=
mse_sum
;
}
MS_LOG
(
DEBUG
)
<<
"mse: "
<<
mse
<<
std
::
endl
;
mse
=
count
>
0
?
static_cast
<
double
>
(
mse_sum
)
/
count
:
mse_sum
;
MS_LOG
(
INFO
)
<<
"mse: "
<<
mse
<<
std
::
endl
;
EXPECT_LT
(
mse
,
kMseThreshold
);
}
MS_LOG
(
INFO
)
<<
"MindDataTestRandomCropDecodeResizeOp end!"
;
MS_LOG
(
INFO
)
<<
"RandomCropDecodeResizeOp test 1 finished"
;
}
TEST_F
(
MindDataTestRandomCropDecodeResizeOp
,
TestOp1
)
{
MS_LOG
(
INFO
)
<<
"
Doing MindDataTestRandomCropDecodeResizeOp
"
;
const
unsigned
int
h
=
884
;
const
unsigned
int
w
=
718
;
const
float
scale_lb
=
0.1
;
const
float
scale_ub
=
1
;
const
float
aspect_lb
=
0.1
;
const
float
aspect_ub
=
10
;
MS_LOG
(
INFO
)
<<
"
starting RandomCropDecodeResizeOp test 2
"
;
const
expr
int
h
=
884
;
const
expr
int
w
=
718
;
const
expr
float
scale_lb
=
0.1
;
const
expr
float
scale_ub
=
1
;
const
expr
float
aspect_lb
=
0.1
;
const
expr
float
aspect_ub
=
10
;
std
::
shared_ptr
<
Tensor
>
decoded
,
decoded_and_cropped
,
cropped_and_decoded
;
std
::
mt19937
rd
;
...
...
@@ -98,14 +96,14 @@ TEST_F(MindDataTestRandomCropDecodeResizeOp, TestOp1) {
std
::
uniform_real_distribution
<
float
>
rd_aspect
(
aspect_lb
,
aspect_ub
);
DecodeOp
op
(
true
);
op
.
Compute
(
raw_input_tensor_
,
&
decoded
);
Status
s1
,
s2
;
Status
crop_and_decode_status
,
decode_and_crop_status
;
float
scale
,
aspect
;
int
crop_width
,
crop_height
;
bool
crop_success
=
false
;
unsigned
int
mse_sum
,
m1
,
m2
,
count
;
float
mse
;
int
mse_sum
,
m1
,
m2
,
count
;
double
mse
;
for
(
unsigned
int
k
=
0
;
k
<
100
;
++
k
)
{
for
(
int
k
=
0
;
k
<
100
;
++
k
)
{
mse_sum
=
0
;
count
=
0
;
for
(
auto
i
=
0
;
i
<
100
;
i
++
)
{
...
...
@@ -132,13 +130,13 @@ TEST_F(MindDataTestRandomCropDecodeResizeOp, TestOp1) {
int
y
=
rd_y
(
rd
);
op
.
Compute
(
raw_input_tensor_
,
&
decoded
);
s1
=
Crop
(
decoded
,
&
decoded_and_cropped
,
x
,
y
,
crop_width
,
crop_height
);
s2
=
JpegCropAndDecode
(
raw_input_tensor_
,
&
cropped_and_decoded
,
x
,
y
,
crop_width
,
crop_height
);
crop_and_decode_status
=
Crop
(
decoded
,
&
decoded_and_cropped
,
x
,
y
,
crop_width
,
crop_height
);
decode_and_crop_status
=
JpegCropAndDecode
(
raw_input_tensor_
,
&
cropped_and_decoded
,
x
,
y
,
crop_width
,
crop_height
);
{
cv
::
Mat
M1
(
crop_height
,
crop_width
,
CV_8UC3
,
decoded_and_cropped
->
StartAddr
());
cv
::
Mat
M2
(
crop_height
,
crop_width
,
CV_8UC3
,
cropped_and_decoded
->
StartAddr
());
for
(
unsigned
int
i
=
0
;
i
<
crop_height
;
++
i
)
{
for
(
unsigned
int
j
=
0
;
j
<
crop_width
;
++
j
)
{
for
(
int
i
=
0
;
i
<
crop_height
;
++
i
)
{
for
(
int
j
=
0
;
j
<
crop_width
;
++
j
)
{
m1
=
M1
.
at
<
cv
::
Vec3b
>
(
i
,
j
)[
1
];
m2
=
M2
.
at
<
cv
::
Vec3b
>
(
i
,
j
)[
1
];
mse_sum
+=
sqrt
((
m1
-
m2
)
*
(
m1
-
m2
));
...
...
@@ -149,8 +147,9 @@ TEST_F(MindDataTestRandomCropDecodeResizeOp, TestOp1) {
}
}
mse
=
(
count
==
0
)
?
mse_sum
:
static_cast
<
float
>
(
mse_sum
)
/
count
;
MS_LOG
(
DEBUG
)
<<
"mse: "
<<
mse
<<
std
::
endl
;
mse
=
count
>
0
?
static_cast
<
double
>
(
mse_sum
)
/
count
:
mse_sum
;
MS_LOG
(
INFO
)
<<
"mse: "
<<
mse
<<
std
::
endl
;
EXPECT_LT
(
mse
,
kMseThreshold
);
}
MS_LOG
(
INFO
)
<<
"
MindDataTestRandomCropDecodeResizeOp end!
"
;
MS_LOG
(
INFO
)
<<
"
RandomCropDecodeResizeOp test 2 finished
"
;
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录