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
17 #include "common/bboxop_common.h"
18 #include "minddata/dataset/kernels/image/random_resize_with_bbox_op.h"
19 #include "utils/log_adapter.h"
20
21 #include "minddata/dataset/core/config_manager.h"
22 #include "minddata/dataset/core/global_context.h"
23
24 using namespace mindspore::dataset;
25 using mindspore::LogStream;
26 using mindspore::ExceptionType::NoExceptionType;
27 using mindspore::MsLogLevel::INFO;
28
29 const bool kSaveExpected = false;
30 const char kOpName[] = "random_resize_with_bbox_c";
31
32 class MindDataTestRandomResizeWithBBoxOp : public UT::CVOP::BBOXOP::BBoxOpCommon {
33 protected:
MindDataTestRandomResizeWithBBoxOp()34 MindDataTestRandomResizeWithBBoxOp() : BBoxOpCommon() {}
35 };
TEST_F(MindDataTestRandomResizeWithBBoxOp,TestOp)36 TEST_F(MindDataTestRandomResizeWithBBoxOp, TestOp) {
37 MS_LOG(INFO) << "Doing testRandomResizeWithBBox.";
38 //setting seed here
39 u_int32_t curr_seed = GlobalContext::config_manager()->seed();
40 GlobalContext::config_manager()->set_seed(120);
41 TensorTable results;
42 std::unique_ptr<RandomResizeWithBBoxOp> op(new RandomResizeWithBBoxOp(500));
43 for (const auto &tensor_row_ : images_and_annotations_) {
44 // selected a tensorRow
45 TensorRow output_row;
46 Status s = op->Compute(tensor_row_, &output_row);
47 EXPECT_TRUE(s.IsOk());
48 results.push_back(output_row);
49 }
50 if (kSaveExpected) {
51 SaveImagesWithAnnotations(FileType::kExpected, std::string(kOpName), results);
52 }
53 SaveImagesWithAnnotations(FileType::kActual, std::string(kOpName), results);
54 if (!kSaveExpected) {
55 CompareActualAndExpected(std::string(kOpName));
56 }
57 GlobalContext::config_manager()->set_seed(curr_seed);
58 MS_LOG(INFO) << "testRandomResizeWithBBox end.";
59 }
60