diff --git a/tests/ut/cpp/dataset/CMakeLists.txt b/tests/ut/cpp/dataset/CMakeLists.txt index 129864ca0f7e56c1d5928c60c5d7e040950d6b3d..496afe1ae9c779334d890d729620e394a550b3ec 100644 --- a/tests/ut/cpp/dataset/CMakeLists.txt +++ b/tests/ut/cpp/dataset/CMakeLists.txt @@ -11,6 +11,7 @@ SET(DE_UT_SRCS interrupt_test.cc image_folder_op_test.cc buddy_test.cc + bounding_box_augment_op_test.cc arena_test.cc btree_test.cc center_crop_op_test.cc @@ -39,6 +40,7 @@ SET(DE_UT_SRCS random_crop_and_resize_op_test.cc random_color_adjust_op_test.cc random_horizontal_flip_op_test.cc + random_horizontal_flip_with_bbox_test.cc random_resize_op_test.cc random_rotation_op_test.cc random_vertical_flip_op_test.cc diff --git a/tests/ut/cpp/dataset/bounding_box_augment_op_test.cc b/tests/ut/cpp/dataset/bounding_box_augment_op_test.cc new file mode 100644 index 0000000000000000000000000000000000000000..4633eefe350ff38b735d857a2069afee7852a330 --- /dev/null +++ b/tests/ut/cpp/dataset/bounding_box_augment_op_test.cc @@ -0,0 +1,52 @@ +/** + * 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/bounding_box_augment_op.h" +#include "dataset/kernels/image/random_rotation_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[] = "BoundingBoxAugmentOp"; + +class MindDataTestBoundingBoxAugmentOp : public UT::CVOP::BBOXOP::BBoxOpCommon { + protected: + MindDataTestBoundingBoxAugmentOp() : UT::CVOP::BBOXOP::BBoxOpCommon() {} +}; + +TEST_F(MindDataTestBoundingBoxAugmentOp, TestOp) { + MS_LOG(INFO) << "Doing testBoundingBoxAugment."; + TensorTable results; + std::unique_ptr op = + std::make_unique(std::make_shared(90, 90), 1); + for (const auto &row : images_and_annotations_) { + TensorRow output_row; + Status s = op->Compute(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)); + } +} diff --git a/tests/ut/cpp/dataset/common/bboxop_common.cc b/tests/ut/cpp/dataset/common/bboxop_common.cc index edd457a82dc58877d342b0a8855532546d7a6dd0..e4be1fbbe675f1f16c4e1963077e4a2813ee67ec 100644 --- a/tests/ut/cpp/dataset/common/bboxop_common.cc +++ b/tests/ut/cpp/dataset/common/bboxop_common.cc @@ -66,17 +66,16 @@ void BBoxOpCommon::GetInputImagesAndAnnotations(const std::string &dir, std::siz MS_LOG(ERROR) << "Images folder was not found : " + images_path; EXPECT_TRUE(dir_path.Exists()); } - std::size_t files_fetched = 0; // get image file paths - while (image_dir_itr->hasNext() && files_fetched < num_of_samples) { + while (image_dir_itr->hasNext()) { Path image_path = image_dir_itr->next(); if (image_path.Extension() == std::string(kImageExt)) { paths_to_fetch.push_back(image_path.toString()); - files_fetched++; } } // sort fetched files std::sort(paths_to_fetch.begin(), paths_to_fetch.end()); + std::size_t files_fetched = 0; for (const auto &image_file : paths_to_fetch) { std::string image_ext = std::string(kImageExt); std::string annot_file = image_file; @@ -100,6 +99,10 @@ void BBoxOpCommon::GetInputImagesAndAnnotations(const std::string &dir, std::siz // add image and annotation to the tensor table TensorRow row_data({std::move(input_tensor_), std::move(annotation_tensor)}); images_and_annotations_.push_back(row_data); + files_fetched++; + if (files_fetched == num_of_samples) { + break; + } } } diff --git a/tests/ut/cpp/dataset/random_horizontal_flip_with_bbox_test.cc b/tests/ut/cpp/dataset/random_horizontal_flip_with_bbox_test.cc new file mode 100644 index 0000000000000000000000000000000000000000..7bdd547918475042087a1085040c391d679f9790 --- /dev/null +++ b/tests/ut/cpp/dataset/random_horizontal_flip_with_bbox_test.cc @@ -0,0 +1,50 @@ +/** + * 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_horizontal_flip_with_bbox_op.h" +#include "utils/log_adapter.h" + +using namespace mindspore::dataset; +using mindspore::MsLogLevel::INFO; +using mindspore::ExceptionType::NoExceptionType; +using mindspore::LogStream; + +const bool kSaveExpected = false; +const char kOpName[] = "RandomHorizontalFlipWithBBox"; + +class MindDataTestRandomHorizontalFlipWithBBoxOp : public UT::CVOP::BBOXOP::BBoxOpCommon { + protected: + MindDataTestRandomHorizontalFlipWithBBoxOp() : UT::CVOP::BBOXOP::BBoxOpCommon() {} +}; + +TEST_F(MindDataTestRandomHorizontalFlipWithBBoxOp, TestOp) { + MS_LOG(INFO) << "Doing testRandomHorizontalFlipWithBBox."; + TensorTable results; + std::unique_ptr op(new RandomHorizontalFlipWithBBoxOp(1)); + for (const auto &row: images_and_annotations_) { + TensorRow output_row; + Status s = op->Compute(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)); + } +} diff --git a/tests/ut/data/dataset/imagefolder/ExpectedBoundingBoxAugmentOp0.jpg b/tests/ut/data/dataset/imagefolder/ExpectedBoundingBoxAugmentOp0.jpg new file mode 100644 index 0000000000000000000000000000000000000000..242559f2763eadf38eb221d9f377fae7e4e24ce8 Binary files /dev/null and b/tests/ut/data/dataset/imagefolder/ExpectedBoundingBoxAugmentOp0.jpg differ diff --git a/tests/ut/data/dataset/imagefolder/ExpectedRandomHorizontalFlipWithBBox0.jpg b/tests/ut/data/dataset/imagefolder/ExpectedRandomHorizontalFlipWithBBox0.jpg new file mode 100644 index 0000000000000000000000000000000000000000..3210a7b1feb6f0418a9bf505611c30f2e8374fb9 Binary files /dev/null and b/tests/ut/data/dataset/imagefolder/ExpectedRandomHorizontalFlipWithBBox0.jpg differ