Merge pull request !2926 from islam_amin/object_ops_cc_ut_floatstags/v0.6.0-beta
| @@ -11,6 +11,7 @@ SET(DE_UT_SRCS | |||||
| interrupt_test.cc | interrupt_test.cc | ||||
| image_folder_op_test.cc | image_folder_op_test.cc | ||||
| buddy_test.cc | buddy_test.cc | ||||
| bounding_box_augment_op_test.cc | |||||
| arena_test.cc | arena_test.cc | ||||
| btree_test.cc | btree_test.cc | ||||
| center_crop_op_test.cc | center_crop_op_test.cc | ||||
| @@ -39,6 +40,7 @@ SET(DE_UT_SRCS | |||||
| random_crop_and_resize_op_test.cc | random_crop_and_resize_op_test.cc | ||||
| random_color_adjust_op_test.cc | random_color_adjust_op_test.cc | ||||
| random_horizontal_flip_op_test.cc | random_horizontal_flip_op_test.cc | ||||
| random_horizontal_flip_with_bbox_test.cc | |||||
| random_resize_op_test.cc | random_resize_op_test.cc | ||||
| random_rotation_op_test.cc | random_rotation_op_test.cc | ||||
| random_vertical_flip_op_test.cc | random_vertical_flip_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<BoundingBoxAugmentOp> op = | |||||
| std::make_unique<BoundingBoxAugmentOp>(std::make_shared<RandomRotationOp>(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)); | |||||
| } | |||||
| } | |||||
| @@ -66,17 +66,16 @@ void BBoxOpCommon::GetInputImagesAndAnnotations(const std::string &dir, std::siz | |||||
| MS_LOG(ERROR) << "Images folder was not found : " + images_path; | MS_LOG(ERROR) << "Images folder was not found : " + images_path; | ||||
| EXPECT_TRUE(dir_path.Exists()); | EXPECT_TRUE(dir_path.Exists()); | ||||
| } | } | ||||
| std::size_t files_fetched = 0; | |||||
| // get image file paths | // 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(); | Path image_path = image_dir_itr->next(); | ||||
| if (image_path.Extension() == std::string(kImageExt)) { | if (image_path.Extension() == std::string(kImageExt)) { | ||||
| paths_to_fetch.push_back(image_path.toString()); | paths_to_fetch.push_back(image_path.toString()); | ||||
| files_fetched++; | |||||
| } | } | ||||
| } | } | ||||
| // sort fetched files | // sort fetched files | ||||
| std::sort(paths_to_fetch.begin(), paths_to_fetch.end()); | std::sort(paths_to_fetch.begin(), paths_to_fetch.end()); | ||||
| std::size_t files_fetched = 0; | |||||
| for (const auto &image_file : paths_to_fetch) { | for (const auto &image_file : paths_to_fetch) { | ||||
| std::string image_ext = std::string(kImageExt); | std::string image_ext = std::string(kImageExt); | ||||
| std::string annot_file = image_file; | 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 | // add image and annotation to the tensor table | ||||
| TensorRow row_data({std::move(input_tensor_), std::move(annotation_tensor)}); | TensorRow row_data({std::move(input_tensor_), std::move(annotation_tensor)}); | ||||
| images_and_annotations_.push_back(row_data); | images_and_annotations_.push_back(row_data); | ||||
| files_fetched++; | |||||
| if (files_fetched == num_of_samples) { | |||||
| break; | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| @@ -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<RandomHorizontalFlipWithBBoxOp> 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)); | |||||
| } | |||||
| } | |||||