diff --git a/tests/ut/cpp/dataset/CMakeLists.txt b/tests/ut/cpp/dataset/CMakeLists.txt index 30fd39146f..ab4b307e45 100644 --- a/tests/ut/cpp/dataset/CMakeLists.txt +++ b/tests/ut/cpp/dataset/CMakeLists.txt @@ -44,6 +44,7 @@ SET(DE_UT_SRCS random_horizontal_flip_op_test.cc random_horizontal_flip_with_bbox_test.cc random_resize_op_test.cc + random_resize_with_bbox_op_test.cc random_rotation_op_test.cc random_vertical_flip_op_test.cc random_vertical_flip_with_bbox_op_test.cc @@ -53,6 +54,7 @@ SET(DE_UT_SRCS rescale_op_test.cc resize_bilinear_op_test.cc resize_op_test.cc + resize_with_bbox_op_test.cc schema_test.cc shuffle_op_test.cc stand_alone_samplers_test.cc diff --git a/tests/ut/cpp/dataset/random_resize_with_bbox_op_test.cc b/tests/ut/cpp/dataset/random_resize_with_bbox_op_test.cc new file mode 100644 index 0000000000..01e2bf3fbb --- /dev/null +++ b/tests/ut/cpp/dataset/random_resize_with_bbox_op_test.cc @@ -0,0 +1,59 @@ +/** + * 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. + */ + +#include "common/bboxop_common.h" +#include "dataset/kernels/image/random_resize_with_bbox_op.h" +#include "utils/log_adapter.h" + +#include "dataset/core/config_manager.h" +#include "dataset/core/global_context.h" + +using namespace mindspore::dataset; +using mindspore::LogStream; +using mindspore::ExceptionType::NoExceptionType; +using mindspore::MsLogLevel::INFO; + +const bool kSaveExpected = false; +const char kOpName[] = "RandomResizeWithBBox_C"; + +class MindDataTestRandomResizeWithBBoxOp : public UT::CVOP::BBOXOP::BBoxOpCommon { + protected: + MindDataTestRandomResizeWithBBoxOp() : BBoxOpCommon() {} +}; +TEST_F(MindDataTestRandomResizeWithBBoxOp, TestOp) { + MS_LOG(INFO) << "Doing testRandomResizeWithBBox."; + //setting seed here + u_int32_t curr_seed = GlobalContext::config_manager()->seed(); + GlobalContext::config_manager()->set_seed(120); + TensorTable results; + std::unique_ptr op(new RandomResizeWithBBoxOp(500)); + for (const auto &tensor_row_ : images_and_annotations_) { + // selected a tensorRow + TensorRow output_row; + Status s = op->Compute(tensor_row_, &output_row); + EXPECT_TRUE(s.IsOk()); + results.push_back(output_row); + } + if (kSaveExpected) { + SaveImagesWithAnnotations(FileType::kExpected, std::string(kOpName), results); + } + SaveImagesWithAnnotations(FileType::kActual, std::string(kOpName), results); + if (!kSaveExpected) { + CompareActualAndExpected(std::string(kOpName)); + } + GlobalContext::config_manager()->set_seed(curr_seed); + MS_LOG(INFO) << "testRandomResizeWithBBox end."; +} diff --git a/tests/ut/cpp/dataset/resize_with_bbox_op_test.cc b/tests/ut/cpp/dataset/resize_with_bbox_op_test.cc new file mode 100644 index 0000000000..b81e4f9649 --- /dev/null +++ b/tests/ut/cpp/dataset/resize_with_bbox_op_test.cc @@ -0,0 +1,54 @@ +/** + * 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. + */ + +#include "common/bboxop_common.h" +#include "dataset/kernels/image/resize_with_bbox_op.h" +#include "utils/log_adapter.h" + +using namespace mindspore::dataset; +using mindspore::LogStream; +using mindspore::ExceptionType::NoExceptionType; +using mindspore::MsLogLevel::INFO; + +const bool kSaveExpected = false; +const char kOpName[] = "ResizeWithBBox_C"; + +class MindDataTestResizeWithBBoxOp : public UT::CVOP::BBOXOP::BBoxOpCommon { + protected: + MindDataTestResizeWithBBoxOp() : BBoxOpCommon() {} +}; +TEST_F(MindDataTestResizeWithBBoxOp, TestOp) { + MS_LOG(INFO) << "Doing testResizeWithBBox."; + // resize + TensorTable results; + std::unique_ptr op(new ResizeWithBBoxOp(500)); + for (const auto &tensor_row_ : images_and_annotations_) { + // selected a tensorRow + TensorRow output_row; + Status s = op->Compute(tensor_row_, &output_row); + EXPECT_TRUE(s.IsOk()); + results.push_back(output_row); + } + if (kSaveExpected) { + SaveImagesWithAnnotations(FileType::kExpected, std::string(kOpName), results); + } + SaveImagesWithAnnotations(FileType::kActual, std::string(kOpName), results); + if (!kSaveExpected) { + CompareActualAndExpected(std::string(kOpName)); + } + + MS_LOG(INFO) << "testResizeWithBBox end."; +} diff --git a/tests/ut/data/dataset/imagefolder/ExpectedRandomResizeWithBBox_C0.jpg b/tests/ut/data/dataset/imagefolder/ExpectedRandomResizeWithBBox_C0.jpg new file mode 100644 index 0000000000..235516d75f Binary files /dev/null and b/tests/ut/data/dataset/imagefolder/ExpectedRandomResizeWithBBox_C0.jpg differ diff --git a/tests/ut/data/dataset/imagefolder/ExpectedResizeWithBBox_C0.jpg b/tests/ut/data/dataset/imagefolder/ExpectedResizeWithBBox_C0.jpg new file mode 100644 index 0000000000..f6dfd85547 Binary files /dev/null and b/tests/ut/data/dataset/imagefolder/ExpectedResizeWithBBox_C0.jpg differ