1 /**
2 * Copyright 2020 Huawei Technologies Co., Ltd
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 #include "common/common.h"
17 #include "common/cvop_common.h"
18 #include "minddata/dataset/kernels/image/normalize_pad_op.h"
19 #include "minddata/dataset/core/cv_tensor.h"
20 #include "utils/log_adapter.h"
21 #include <opencv2/opencv.hpp>
22
23 using namespace mindspore::dataset;
24 using mindspore::MsLogLevel::INFO;
25 using mindspore::ExceptionType::NoExceptionType;
26 using mindspore::LogStream;
27
28 class MindDataTestNormalizePadOP : public UT::CVOP::CVOpCommon {
29 public:
MindDataTestNormalizePadOP()30 MindDataTestNormalizePadOP() : CVOpCommon() {}
31 };
32
TEST_F(MindDataTestNormalizePadOP,TestFloat32)33 TEST_F(MindDataTestNormalizePadOP, TestFloat32) {
34 MS_LOG(INFO) << "Doing TestNormalizePadOp::TestFloat32.";
35 std::shared_ptr<Tensor> output_tensor;
36
37 // Numbers are from the resnet50 model implementation
38 float mean[3] = {121.0, 115.0, 100.0};
39 float std[3] = {70.0, 68.0, 71.0};
40
41 // NormalizePad Op
42 std::unique_ptr<NormalizePadOp> op(new NormalizePadOp(mean[0], mean[1], mean[2], std[0], std[1], std[2], "float32"));
43 EXPECT_TRUE(op->OneToOne());
44 Status s = op->Compute(input_tensor_, &output_tensor);
45 EXPECT_TRUE(s.IsOk());
46 }
47
TEST_F(MindDataTestNormalizePadOP,TestFloat16)48 TEST_F(MindDataTestNormalizePadOP, TestFloat16) {
49 MS_LOG(INFO) << "Doing TestNormalizePadOp::TestFloat16.";
50 std::shared_ptr<Tensor> output_tensor;
51
52 // Numbers are from the resnet50 model implementation
53 float mean[3] = {121.0, 115.0, 100.0};
54 float std[3] = {70.0, 68.0, 71.0};
55
56 // NormalizePad Op
57 std::unique_ptr<NormalizePadOp> op(new NormalizePadOp(mean[0], mean[1], mean[2], std[0], std[1], std[2], "float16"));
58 EXPECT_TRUE(op->OneToOne());
59 Status s = op->Compute(input_tensor_, &output_tensor);
60 EXPECT_TRUE(s.IsOk());
61 }