diff --git a/mindspore/ccsrc/minddata/dataset/api/vision.cc b/mindspore/ccsrc/minddata/dataset/api/vision.cc index 83a68c726a..c400604d4a 100644 --- a/mindspore/ccsrc/minddata/dataset/api/vision.cc +++ b/mindspore/ccsrc/minddata/dataset/api/vision.cc @@ -148,6 +148,22 @@ std::shared_ptr Pad(std::vector padding, std::vector RandomAffine(const std::vector °rees, + const std::vector &translate_range, + const std::vector &scale_range, + const std::vector &shear_ranges, + InterpolationMode interpolation, + const std::vector &fill_value) { + auto op = std::make_shared(degrees, translate_range, scale_range, shear_ranges, interpolation, + fill_value); + // Input validation + if (!op->ValidateParams()) { + return nullptr; + } + return op; +} + // Function to create RandomColorOperation. std::shared_ptr RandomColor(float t_lb, float t_ub) { auto op = std::make_shared(t_lb, t_ub); @@ -175,22 +191,6 @@ std::shared_ptr RandomColorAdjust(std::vector return op; } -// Function to create RandomAffineOperation. -std::shared_ptr RandomAffine(const std::vector °rees, - const std::vector &translate_range, - const std::vector &scale_range, - const std::vector &shear_ranges, - InterpolationMode interpolation, - const std::vector &fill_value) { - auto op = std::make_shared(degrees, translate_range, scale_range, shear_ranges, interpolation, - fill_value); - // Input validation - if (!op->ValidateParams()) { - return nullptr; - } - return op; -} - // Function to create RandomCropOperation. std::shared_ptr RandomCrop(std::vector size, std::vector padding, bool pad_if_needed, std::vector fill_value, @@ -261,9 +261,9 @@ std::shared_ptr RandomRotation(std::vector degre return op; } -// Function to create RandomSolarizeOperation. -std::shared_ptr RandomSolarize(std::vector threshold) { - auto op = std::make_shared(threshold); +// Function to create RandomSharpnessOperation. +std::shared_ptr RandomSharpness(std::vector degrees) { + auto op = std::make_shared(degrees); // Input validation if (!op->ValidateParams()) { return nullptr; @@ -271,9 +271,9 @@ std::shared_ptr RandomSolarize(std::vector thr return op; } -// Function to create RandomSharpnessOperation. -std::shared_ptr RandomSharpness(std::vector degrees) { - auto op = std::make_shared(degrees); +// Function to create RandomSolarizeOperation. +std::shared_ptr RandomSolarize(std::vector threshold) { + auto op = std::make_shared(threshold); // Input validation if (!op->ValidateParams()) { return nullptr; @@ -598,72 +598,6 @@ std::shared_ptr PadOperation::Build() { return tensor_op; } -// RandomColorOperation. -RandomColorOperation::RandomColorOperation(float t_lb, float t_ub) : t_lb_(t_lb), t_ub_(t_ub) {} - -bool RandomColorOperation::ValidateParams() { - // Do some input validation. - if (t_lb_ > t_ub_) { - MS_LOG(ERROR) << "RandomColor: lower bound must be less or equal to upper bound"; - return false; - } - return true; -} - -// RandomColorAdjustOperation. -RandomColorAdjustOperation::RandomColorAdjustOperation(std::vector brightness, std::vector contrast, - std::vector saturation, std::vector hue) - : brightness_(brightness), contrast_(contrast), saturation_(saturation), hue_(hue) {} - -bool RandomColorAdjustOperation::ValidateParams() { - // Do some input validation. - if (brightness_.empty() || brightness_.size() > 2) { - MS_LOG(ERROR) << "RandomColorAdjust: brightness must be a vector of one or two values"; - return false; - } - if (contrast_.empty() || contrast_.size() > 2) { - MS_LOG(ERROR) << "RandomColorAdjust: contrast must be a vector of one or two values"; - return false; - } - if (saturation_.empty() || saturation_.size() > 2) { - MS_LOG(ERROR) << "RandomColorAdjust: saturation must be a vector of one or two values"; - return false; - } - if (hue_.empty() || hue_.size() > 2) { - MS_LOG(ERROR) << "RandomColorAdjust: hue must be a vector of one or two values"; - return false; - } - return true; -} - -std::shared_ptr RandomColorAdjustOperation::Build() { - float brightness_lb, brightness_ub, contrast_lb, contrast_ub, saturation_lb, saturation_ub, hue_lb, hue_ub; - - brightness_lb = brightness_[0]; - brightness_ub = brightness_[0]; - - if (brightness_.size() == 2) brightness_ub = brightness_[1]; - - contrast_lb = contrast_[0]; - contrast_ub = contrast_[0]; - - if (contrast_.size() == 2) contrast_ub = contrast_[1]; - - saturation_lb = saturation_[0]; - saturation_ub = saturation_[0]; - - if (saturation_.size() == 2) saturation_ub = saturation_[1]; - - hue_lb = hue_[0]; - hue_ub = hue_[0]; - - if (hue_.size() == 2) hue_ub = hue_[1]; - - std::shared_ptr tensor_op = std::make_shared( - brightness_lb, brightness_ub, contrast_lb, contrast_ub, saturation_lb, saturation_ub, hue_lb, hue_ub); - return tensor_op; -} - // RandomAffineOperation RandomAffineOperation::RandomAffineOperation(const std::vector °rees, const std::vector &translate_range, @@ -773,6 +707,72 @@ std::shared_ptr RandomAffineOperation::Build() { return tensor_op; } +// RandomColorOperation. +RandomColorOperation::RandomColorOperation(float t_lb, float t_ub) : t_lb_(t_lb), t_ub_(t_ub) {} + +bool RandomColorOperation::ValidateParams() { + // Do some input validation. + if (t_lb_ > t_ub_) { + MS_LOG(ERROR) << "RandomColor: lower bound must be less or equal to upper bound"; + return false; + } + return true; +} + +// RandomColorAdjustOperation. +RandomColorAdjustOperation::RandomColorAdjustOperation(std::vector brightness, std::vector contrast, + std::vector saturation, std::vector hue) + : brightness_(brightness), contrast_(contrast), saturation_(saturation), hue_(hue) {} + +bool RandomColorAdjustOperation::ValidateParams() { + // Do some input validation. + if (brightness_.empty() || brightness_.size() > 2) { + MS_LOG(ERROR) << "RandomColorAdjust: brightness must be a vector of one or two values"; + return false; + } + if (contrast_.empty() || contrast_.size() > 2) { + MS_LOG(ERROR) << "RandomColorAdjust: contrast must be a vector of one or two values"; + return false; + } + if (saturation_.empty() || saturation_.size() > 2) { + MS_LOG(ERROR) << "RandomColorAdjust: saturation must be a vector of one or two values"; + return false; + } + if (hue_.empty() || hue_.size() > 2) { + MS_LOG(ERROR) << "RandomColorAdjust: hue must be a vector of one or two values"; + return false; + } + return true; +} + +std::shared_ptr RandomColorAdjustOperation::Build() { + float brightness_lb, brightness_ub, contrast_lb, contrast_ub, saturation_lb, saturation_ub, hue_lb, hue_ub; + + brightness_lb = brightness_[0]; + brightness_ub = brightness_[0]; + + if (brightness_.size() == 2) brightness_ub = brightness_[1]; + + contrast_lb = contrast_[0]; + contrast_ub = contrast_[0]; + + if (contrast_.size() == 2) contrast_ub = contrast_[1]; + + saturation_lb = saturation_[0]; + saturation_ub = saturation_[0]; + + if (saturation_.size() == 2) saturation_ub = saturation_[1]; + + hue_lb = hue_[0]; + hue_ub = hue_[0]; + + if (hue_.size() == 2) hue_ub = hue_[1]; + + std::shared_ptr tensor_op = std::make_shared( + brightness_lb, brightness_ub, contrast_lb, contrast_ub, saturation_lb, saturation_ub, hue_lb, hue_ub); + return tensor_op; +} + // RandomCropOperation RandomCropOperation::RandomCropOperation(std::vector size, std::vector padding, bool pad_if_needed, std::vector fill_value, BorderType padding_mode) diff --git a/mindspore/ccsrc/minddata/dataset/include/vision.h b/mindspore/ccsrc/minddata/dataset/include/vision.h index db84ac92bb..e3d1cd81f6 100644 --- a/mindspore/ccsrc/minddata/dataset/include/vision.h +++ b/mindspore/ccsrc/minddata/dataset/include/vision.h @@ -60,7 +60,7 @@ class UniformAugOperation; /// \brief Function to create a CenterCrop TensorOperation. /// \notes Crops the input image at the center to the given size. -/// \param[in] size - a vector representing the output size of the cropped image. +/// \param[in] size A vector representing the output size of the cropped image. /// If size is a single value, a square crop of size (size, size) is returned. /// If size has 2 values, it should be (height, width). /// \return Shared pointer to the current TensorOperation. @@ -92,7 +92,7 @@ std::shared_ptr CutOut(int32_t length, int32_t num_patches = 1) /// \brief Function to create a Decode TensorOperation. /// \notes Decode the input image in RGB mode. -/// \param[in] rgb - a boolean of whether to decode in RGB mode or not. +/// \param[in] rgb A boolean of whether to decode in RGB mode or not. /// \return Shared pointer to the current TensorOperation. std::shared_ptr Decode(bool rgb = true); @@ -139,18 +139,18 @@ std::shared_ptr Pad(std::vector padding, std::vector RandomAffine( @@ -162,8 +162,8 @@ std::shared_ptr RandomAffine( /// \brief Blends an image with its grayscale version with random weights /// t and 1 - t generated from a given range. If the range is trivial /// then the weights are determinate and t equals the bound of the interval -/// \param[in] t_lb lower bound on the range of random weights -/// \param[in] t_lb upper bound on the range of random weights +/// \param[in] t_lb Lower bound on the range of random weights +/// \param[in] t_lb Upper bound on the range of random weights /// \return Shared pointer to the current TensorOp std::shared_ptr RandomColor(float t_lb, float t_ub); @@ -185,14 +185,14 @@ std::shared_ptr RandomColorAdjust(std::vector /// \brief Function to create a RandomCrop TensorOperation. /// \notes Crop the input image at a random location. -/// \param[in] size - a vector representing the output size of the cropped image. +/// \param[in] size A vector representing the output size of the cropped image. /// If size is a single value, a square crop of size (size, size) is returned. /// If size has 2 values, it should be (height, width). -/// \param[in] padding - a vector with the value of pixels to pad the image. If 4 values are provided, +/// \param[in] padding A vector with the value of pixels to pad the image. If 4 values are provided, /// it pads the left, top, right and bottom respectively. -/// \param[in] pad_if_needed - a boolean whether to pad the image if either side is smaller than +/// \param[in] pad_if_needed A boolean whether to pad the image if either side is smaller than /// the given output size. -/// \param[in] fill_value - a vector representing the pixel intensity of the borders, it is used to +/// \param[in] fill_value A vector representing the pixel intensity of the borders, it is used to /// fill R, G, B channels respectively. /// \return Shared pointer to the current TensorOperation. std::shared_ptr RandomCrop(std::vector size, std::vector padding = {0, 0, 0, 0}, @@ -218,7 +218,7 @@ std::shared_ptr RandomCropDecodeResize( /// \brief Function to create a RandomHorizontalFlip TensorOperation. /// \notes Tensor operation to perform random horizontal flip. -/// \param[in] prob - float representing the probability of flip. +/// \param[in] prob A float representing the probability of flip. /// \return Shared pointer to the current TensorOperation. std::shared_ptr RandomHorizontalFlip(float prob = 0.5); @@ -247,11 +247,11 @@ std::shared_ptr RandomResizedCrop( /// \brief Function to create a RandomRotation TensorOp /// \notes Rotates the image according to parameters -/// \param[in] degrees A float vector size 2, representing the starting and ending degree +/// \param[in] degrees A float vector of size 2, representing the starting and ending degree /// \param[in] resample An enum for the mode of interpolation /// \param[in] expand A boolean representing whether the image is expanded after rotation -/// \param[in] center A float vector size 2, representing the x and y center of rotation. -/// \param[in] fill_value A uint8_t vector size 3, representing the rgb value of the fill color +/// \param[in] center A float vector of size 2, representing the x and y center of rotation. +/// \param[in] fill_value A uint8_t vector of size 3, representing the rgb value of the fill color /// \return Shared pointer to the current TensorOp std::shared_ptr RandomRotation( std::vector degrees, InterpolationMode resample = InterpolationMode::kNearestNeighbour, bool expand = false, @@ -259,14 +259,14 @@ std::shared_ptr RandomRotation( /// \brief Function to create a RandomSharpness TensorOperation. /// \notes Tensor operation to perform random sharpness. -/// \param[in] start_degree - float representing the start of the range to uniformly sample the factor from it. -/// \param[in] end_degree - float representing the end of the range. +/// \param[in] degrees A float vector of size 2, representing the starting and ending degree to uniformly +/// sample from, to select a degree to adjust sharpness. /// \return Shared pointer to the current TensorOperation. std::shared_ptr RandomSharpness(std::vector degrees = {0.1, 1.9}); /// \brief Function to create a RandomSolarize TensorOperation. /// \notes Invert pixels within specified range. If min=max, then it inverts all pixel above that threshold -/// \param[in] threshold - a vector with two elements specifying the pixel range to invert. +/// \param[in] threshold A vector with two elements specifying the pixel range to invert. /// \return Shared pointer to the current TensorOperation. std::shared_ptr RandomSolarize(std::vector threshold = {0, 255}); @@ -285,7 +285,7 @@ std::shared_ptr Rescale(float rescale, float shift); /// \brief Function to create a Resize TensorOperation. /// \notes Resize the input image to the given size. -/// \param[in] size - a vector representing the output size of the resized image. +/// \param[in] size A vector representing the output size of the resized image. /// If size is a single value, the image will be resized to this value with /// the same image aspect ratio. If size has 2 values, it should be (height, width). /// \param[in] interpolation An enum for the mode of interpolation @@ -310,8 +310,8 @@ std::shared_ptr SwapRedBlue(); /// \brief Function to create a UniformAugment TensorOperation. /// \notes Tensor operation to perform randomly selected augmentation. -/// \param[in] transforms - a vector of TensorOperation transforms. -/// \param[in] num_ops - integer representing the number of OPs to be selected and applied. +/// \param[in] transforms A vector of TensorOperation transforms. +/// \param[in] num_ops An integer representing the number of OPs to be selected and applied. /// \return Shared pointer to the current TensorOperation. std::shared_ptr UniformAugment(std::vector> transforms, int32_t num_ops = 2); diff --git a/mindspore/ccsrc/minddata/dataset/text/sentence_piece_vocab.h b/mindspore/ccsrc/minddata/dataset/text/sentence_piece_vocab.h index efe4981af7..49fdd038a0 100644 --- a/mindspore/ccsrc/minddata/dataset/text/sentence_piece_vocab.h +++ b/mindspore/ccsrc/minddata/dataset/text/sentence_piece_vocab.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef DATASET_TEXT_SENTENCE_PIECE_VOCAB_H_ -#define DATASET_TEXT_SENTENCE_PIECE_VOCAB_H_ +#ifndef MINDSPORE_CCSRC_MINDDATA_DATASET_TEXT_SENTENCE_PIECE_VOCAB_H_ +#define MINDSPORE_CCSRC_MINDDATA_DATASET_TEXT_SENTENCE_PIECE_VOCAB_H_ #include #include @@ -46,4 +46,4 @@ class SentencePieceVocab { }; } // namespace dataset } // namespace mindspore -#endif // DATASET_TEXT_SENTENCE_PIECE_VOCAB_H_ +#endif // MINDSPORE_CCSRC_MINDDATA_DATASET_TEXT_SENTENCE_PIECE_VOCAB_H_ diff --git a/tests/ut/cpp/dataset/CMakeLists.txt b/tests/ut/cpp/dataset/CMakeLists.txt index 1072324ea1..43c97a2fee 100644 --- a/tests/ut/cpp/dataset/CMakeLists.txt +++ b/tests/ut/cpp/dataset/CMakeLists.txt @@ -116,7 +116,7 @@ SET(DE_UT_SRCS c_api_dataset_voc_test.cc c_api_datasets_test.cc c_api_dataset_iterator_test.cc - c_api_dataset_vocab.cc + c_api_text_vocab_test.cc tensor_op_fusion_pass_test.cc sliding_window_op_test.cc epoch_ctrl_op_test.cc diff --git a/tests/ut/cpp/dataset/c_api_datasets_test.cc b/tests/ut/cpp/dataset/c_api_datasets_test.cc index 5597398ee1..7868cb0c6f 100644 --- a/tests/ut/cpp/dataset/c_api_datasets_test.cc +++ b/tests/ut/cpp/dataset/c_api_datasets_test.cc @@ -24,6 +24,8 @@ class MindDataTestPipeline : public UT::DatasetOpTesting { protected: }; +// Tests for datasets (in alphabetical order) + TEST_F(MindDataTestPipeline, TestCelebADataset) { MS_LOG(INFO) << "Doing MindDataTestPipeline-TestCelebADataset."; @@ -129,24 +131,6 @@ TEST_F(MindDataTestPipeline, TestCelebADatasetWithNullSampler) { EXPECT_EQ(ds, nullptr); } -TEST_F(MindDataTestPipeline, TestMnistFailWithWrongDatasetDir) { - MS_LOG(INFO) << "Doing MindDataTestPipeline-TestMnistFailWithWrongDatasetDir."; - - // Create a Mnist Dataset - std::shared_ptr ds = Mnist("", "all", RandomSampler(false, 10)); - EXPECT_EQ(ds, nullptr); -} - -TEST_F(MindDataTestPipeline, TestMnistFailWithNullSampler) { - MS_LOG(INFO) << "Doing MindDataTestPipeline-TestMnistFailWithNullSampler."; - - // Create a Mnist Dataset - std::string folder_path = datasets_root_path_ + "/testMnistData/"; - std::shared_ptr ds = Mnist(folder_path, "all", nullptr); - // Expect failure: sampler can not be nullptr - EXPECT_EQ(ds, nullptr); -} - TEST_F(MindDataTestPipeline, TestImageFolderWithWrongDatasetDir) { MS_LOG(INFO) << "Doing MindDataTestPipeline-TestImageFolderWithWrongDatasetDir."; @@ -197,3 +181,21 @@ TEST_F(MindDataTestPipeline, TestImageFolderFailWithWrongSampler) { // Expect failure: sampler is not construnced correctly EXPECT_EQ(ds, nullptr); } + +TEST_F(MindDataTestPipeline, TestMnistFailWithWrongDatasetDir) { +MS_LOG(INFO) << "Doing MindDataTestPipeline-TestMnistFailWithWrongDatasetDir."; + +// Create a Mnist Dataset +std::shared_ptr ds = Mnist("", "all", RandomSampler(false, 10)); +EXPECT_EQ(ds, nullptr); +} + +TEST_F(MindDataTestPipeline, TestMnistFailWithNullSampler) { +MS_LOG(INFO) << "Doing MindDataTestPipeline-TestMnistFailWithNullSampler."; + +// Create a Mnist Dataset +std::string folder_path = datasets_root_path_ + "/testMnistData/"; +std::shared_ptr ds = Mnist(folder_path, "all", nullptr); +// Expect failure: sampler can not be nullptr +EXPECT_EQ(ds, nullptr); +} \ No newline at end of file diff --git a/tests/ut/cpp/dataset/c_api_dataset_vocab.cc b/tests/ut/cpp/dataset/c_api_text_vocab_test.cc similarity index 100% rename from tests/ut/cpp/dataset/c_api_dataset_vocab.cc rename to tests/ut/cpp/dataset/c_api_text_vocab_test.cc diff --git a/tests/ut/cpp/dataset/c_api_transforms_test.cc b/tests/ut/cpp/dataset/c_api_transforms_test.cc index 33278fbeb6..c7aa3730f7 100644 --- a/tests/ut/cpp/dataset/c_api_transforms_test.cc +++ b/tests/ut/cpp/dataset/c_api_transforms_test.cc @@ -26,6 +26,8 @@ class MindDataTestPipeline : public UT::DatasetOpTesting { protected: }; +// Tests for data transforms ops (in alphabetical order) + TEST_F(MindDataTestPipeline, TestOneHotSuccess1) { // Testing CutMixBatch on a batch of CHW images // Create a Cifar10 Dataset diff --git a/tests/ut/cpp/dataset/c_api_vision_test.cc b/tests/ut/cpp/dataset/c_api_vision_test.cc index e771463fd0..4ba980e289 100644 --- a/tests/ut/cpp/dataset/c_api_vision_test.cc +++ b/tests/ut/cpp/dataset/c_api_vision_test.cc @@ -26,8 +26,92 @@ class MindDataTestPipeline : public UT::DatasetOpTesting { protected: }; +// Tests for vision ops (in alphabetical order) + +TEST_F(MindDataTestPipeline, TestCenterCrop) { + MS_LOG(INFO) << "Doing MindDataTestPipeline-TestCenterCrop with single integer input."; + + // Create an ImageFolder Dataset + std::string folder_path = datasets_root_path_ + "/testPK/data/"; + std::shared_ptr ds = ImageFolder(folder_path, true, RandomSampler(false, 5)); + EXPECT_NE(ds, nullptr); + + // Create a Repeat operation on ds + int32_t repeat_num = 3; + ds = ds->Repeat(repeat_num); + EXPECT_NE(ds, nullptr); + + // Create centre crop object with square crop + std::shared_ptr centre_out1 = vision::CenterCrop({30}); + EXPECT_NE(centre_out1, nullptr); + + // Create a Map operation on ds + ds = ds->Map({centre_out1}); + EXPECT_NE(ds, nullptr); + + // Create a Batch operation on ds + int32_t batch_size = 1; + ds = ds->Batch(batch_size); + EXPECT_NE(ds, nullptr); + + // Create an iterator over the result of the above dataset + // This will trigger the creation of the Execution Tree and launch it. + std::shared_ptr iter = ds->CreateIterator(); + EXPECT_NE(iter, nullptr); + + // Iterate the dataset and get each row + std::unordered_map> row; + iter->GetNextRow(&row); + + uint64_t i = 0; + while (row.size() != 0) { + i++; + auto image = row["image"]; + MS_LOG(INFO) << "Tensor image shape: " << image->shape(); + iter->GetNextRow(&row); + } + + EXPECT_EQ(i, 15); + + // Manually terminate the pipeline + iter->Stop(); +} + +TEST_F(MindDataTestPipeline, TestCenterCropFail) { + MS_LOG(INFO) << "Doing MindDataTestPipeline-TestCenterCrop with invalid parameters."; + + // center crop height value negative + std::shared_ptr center_crop = mindspore::dataset::api::vision::CenterCrop({-32, 32}); + EXPECT_EQ(center_crop, nullptr); + // center crop width value negative + center_crop = mindspore::dataset::api::vision::CenterCrop({32, -32}); + EXPECT_EQ(center_crop, nullptr); + // 0 value would result in nullptr + center_crop = mindspore::dataset::api::vision::CenterCrop({0, 32}); + EXPECT_EQ(center_crop, nullptr); + // center crop with 3 values + center_crop = mindspore::dataset::api::vision::CenterCrop({10, 20, 30}); + EXPECT_EQ(center_crop, nullptr); +} + +TEST_F(MindDataTestPipeline, TestCropFail) { + MS_LOG(INFO) << "Doing MindDataTestPipeline-TestCrop with invalid parameters."; + + // wrong width + std::shared_ptr crop = mindspore::dataset::api::vision::Crop({0, 0}, {32, -32}); + EXPECT_EQ(crop, nullptr); + // wrong height + crop = mindspore::dataset::api::vision::Crop({0, 0}, {-32, -32}); + EXPECT_EQ(crop, nullptr); + // zero height + crop = mindspore::dataset::api::vision::Crop({0, 0}, {0, 32}); + EXPECT_EQ(crop, nullptr); +} + TEST_F(MindDataTestPipeline, TestCutMixBatchSuccess1) { + MS_LOG(INFO) << "Doing MindDataTestPipeline-TestCutMixBatchSuccess1."; // Testing CutMixBatch on a batch of CHW images + // Create a Cifar10 Dataset std::string folder_path = datasets_root_path_ + "/testCifar10Data/"; int number_of_classes = 10; @@ -95,7 +179,9 @@ TEST_F(MindDataTestPipeline, TestCutMixBatchSuccess1) { } TEST_F(MindDataTestPipeline, TestCutMixBatchSuccess2) { + MS_LOG(INFO) << "Doing MindDataTestPipeline-TestCutMixBatchSuccess2."; // Calling CutMixBatch on a batch of HWC images with default values of alpha and prob + // Create a Cifar10 Dataset std::string folder_path = datasets_root_path_ + "/testCifar10Data/"; int number_of_classes = 10; @@ -154,7 +240,8 @@ TEST_F(MindDataTestPipeline, TestCutMixBatchSuccess2) { } TEST_F(MindDataTestPipeline, TestCutMixBatchFail1) { - // Must fail because alpha can't be negative + MS_LOG(INFO) << "Doing MindDataTestPipeline-TestCutMixBatchFail1 with invalid negative alpha parameter."; + // Create a Cifar10 Dataset std::string folder_path = datasets_root_path_ + "/testCifar10Data/"; std::shared_ptr ds = Cifar10(folder_path, "all", RandomSampler(false, 10)); @@ -179,7 +266,8 @@ TEST_F(MindDataTestPipeline, TestCutMixBatchFail1) { } TEST_F(MindDataTestPipeline, TestCutMixBatchFail2) { - // Must fail because prob can't be negative + MS_LOG(INFO) << "Doing MindDataTestPipeline-TestCutMixBatchFail2 with invalid negative prob parameter."; + // Create a Cifar10 Dataset std::string folder_path = datasets_root_path_ + "/testCifar10Data/"; std::shared_ptr ds = Cifar10(folder_path, "all", RandomSampler(false, 10)); @@ -204,7 +292,8 @@ TEST_F(MindDataTestPipeline, TestCutMixBatchFail2) { } TEST_F(MindDataTestPipeline, TestCutMixBatchFail3) { - // Must fail because alpha can't be zero + MS_LOG(INFO) << "Doing MindDataTestPipeline-TestCutMixBatchFail3 with invalid zero alpha parameter."; + // Create a Cifar10 Dataset std::string folder_path = datasets_root_path_ + "/testCifar10Data/"; std::shared_ptr ds = Cifar10(folder_path, "all", RandomSampler(false, 10)); @@ -228,134 +317,59 @@ TEST_F(MindDataTestPipeline, TestCutMixBatchFail3) { EXPECT_EQ(cutmix_batch_op, nullptr); } -TEST_F(MindDataTestPipeline, TestRandomResizedCropSuccess1) { - // Testing RandomResizedCrop with default values - // Create a Cifar10 Dataset - std::string folder_path = datasets_root_path_ + "/testCifar10Data/"; - std::shared_ptr ds = Cifar10(folder_path, "all", RandomSampler(false, 10)); - EXPECT_NE(ds, nullptr); - - // Create objects for the tensor ops - std::shared_ptr random_resized_crop = vision::RandomResizedCrop({5}); - EXPECT_NE(random_resized_crop, nullptr); - - // Create a Map operation on ds - ds = ds->Map({random_resized_crop}, {"image"}); - EXPECT_NE(ds, nullptr); - - // Create an iterator over the result of the above dataset - // This will trigger the creation of the Execution Tree and launch it. - std::shared_ptr iter = ds->CreateIterator(); - EXPECT_NE(iter, nullptr); - - // Iterate the dataset and get each row - std::unordered_map> row; - iter->GetNextRow(&row); - - uint64_t i = 0; - while (row.size() != 0) { - i++; - auto image = row["image"]; - MS_LOG(INFO) << "Tensor image shape: " << image->shape(); - EXPECT_EQ(image->shape()[0] == 5 && image->shape()[1] == 5, true); - iter->GetNextRow(&row); - } - - EXPECT_EQ(i, 10); - - // Manually terminate the pipeline - iter->Stop(); -} +TEST_F(MindDataTestPipeline, TestCutMixBatchFail4) { + MS_LOG(INFO) << "Doing MindDataTestPipeline-TestCutMixBatchFail4 with invalid greater than 1 prob parameter."; -TEST_F(MindDataTestPipeline, TestRandomResizedCropSuccess2) { - // Testing RandomResizedCrop with non-default values // Create a Cifar10 Dataset std::string folder_path = datasets_root_path_ + "/testCifar10Data/"; std::shared_ptr ds = Cifar10(folder_path, "all", RandomSampler(false, 10)); EXPECT_NE(ds, nullptr); - // Create objects for the tensor ops - std::shared_ptr random_resized_crop = - vision::RandomResizedCrop({5, 10}, {0.25, 0.75}, {0.5, 1.25}, mindspore::dataset::InterpolationMode::kArea, 20); - EXPECT_NE(random_resized_crop, nullptr); - - // Create a Map operation on ds - ds = ds->Map({random_resized_crop}, {"image"}); - EXPECT_NE(ds, nullptr); - - // Create an iterator over the result of the above dataset - // This will trigger the creation of the Execution Tree and launch it. - std::shared_ptr iter = ds->CreateIterator(); - EXPECT_NE(iter, nullptr); - - // Iterate the dataset and get each row - std::unordered_map> row; - iter->GetNextRow(&row); - - uint64_t i = 0; - while (row.size() != 0) { - i++; - auto image = row["image"]; - MS_LOG(INFO) << "Tensor image shape: " << image->shape(); - EXPECT_EQ(image->shape()[0] == 5 && image->shape()[1] == 10, true); - iter->GetNextRow(&row); - } - - EXPECT_EQ(i, 10); - - // Manually terminate the pipeline - iter->Stop(); -} - -TEST_F(MindDataTestPipeline, TestRandomResizedCropFail1) { - // This should fail because size has negative value - // Create a Cifar10 Dataset - std::string folder_path = datasets_root_path_ + "/testCifar10Data/"; - std::shared_ptr ds = Cifar10(folder_path, "all", RandomSampler(false, 10)); + // Create a Batch operation on ds + int32_t batch_size = 10; + ds = ds->Batch(batch_size); EXPECT_NE(ds, nullptr); // Create objects for the tensor ops - std::shared_ptr random_resized_crop = vision::RandomResizedCrop({5, -10}); - EXPECT_EQ(random_resized_crop, nullptr); -} + std::shared_ptr one_hot_op = transforms::OneHot(10); + EXPECT_NE(one_hot_op, nullptr); -TEST_F(MindDataTestPipeline, TestRandomResizedCropFail2) { - // This should fail because scale isn't in {min, max} format - // Create a Cifar10 Dataset - std::string folder_path = datasets_root_path_ + "/testCifar10Data/"; - std::shared_ptr ds = Cifar10(folder_path, "all", RandomSampler(false, 10)); + // Create a Map operation on ds + ds = ds->Map({one_hot_op}, {"label"}); EXPECT_NE(ds, nullptr); - // Create objects for the tensor ops - std::shared_ptr random_resized_crop = vision::RandomResizedCrop({5, 10}, {4, 3}); - EXPECT_EQ(random_resized_crop, nullptr); + std::shared_ptr cutmix_batch_op = + vision::CutMixBatch(mindspore::dataset::ImageBatchFormat::kNHWC, 1, 1.5); + EXPECT_EQ(cutmix_batch_op, nullptr); } -TEST_F(MindDataTestPipeline, TestRandomResizedCropFail3) { - // This should fail because ratio isn't in {min, max} format - // Create a Cifar10 Dataset - std::string folder_path = datasets_root_path_ + "/testCifar10Data/"; - std::shared_ptr ds = Cifar10(folder_path, "all", RandomSampler(false, 10)); - EXPECT_NE(ds, nullptr); +TEST_F(MindDataTestPipeline, TestCutOutFail1) { + MS_LOG(INFO) << "Doing MindDataTestPipeline-TestCutOutFail1 with invalid parameters."; - // Create objects for the tensor ops - std::shared_ptr random_resized_crop = vision::RandomResizedCrop({5, 10}, {4, 5}, {7, 6}); - EXPECT_EQ(random_resized_crop, nullptr); + // Create object for the tensor op + // Invalid negative length + std::shared_ptr cutout_op = vision::CutOut(-10); + EXPECT_EQ(cutout_op, nullptr); + // Invalid negative number of patches + cutout_op = vision::CutOut(10, -1); + EXPECT_EQ(cutout_op, nullptr); } -TEST_F(MindDataTestPipeline, TestRandomResizedCropFail4) { - // This should fail because scale has a size of more than 2 - // Create a Cifar10 Dataset - std::string folder_path = datasets_root_path_ + "/testCifar10Data/"; - std::shared_ptr ds = Cifar10(folder_path, "all", RandomSampler(false, 10)); - EXPECT_NE(ds, nullptr); +TEST_F(MindDataTestPipeline, DISABLED_TestCutOutFail2) { + MS_LOG(INFO) << "Doing MindDataTestPipeline-TestCutOutFail2 with invalid params, boundary cases."; - // Create objects for the tensor ops - std::shared_ptr random_resized_crop = vision::RandomResizedCrop({5, 10, 20}, {4, 5}, {7, 6}); - EXPECT_EQ(random_resized_crop, nullptr); + // Create object for the tensor op + // Invalid zero length + std::shared_ptr cutout_op = vision::CutOut(0); + EXPECT_EQ(cutout_op, nullptr); + // Invalid zero number of patches + cutout_op = vision::CutOut(10, 0); + EXPECT_EQ(cutout_op, nullptr); } TEST_F(MindDataTestPipeline, TestCutOut) { + MS_LOG(INFO) << "Doing MindDataTestPipeline-TestCutOut."; + // Create an ImageFolder Dataset std::string folder_path = datasets_root_path_ + "/testPK/data/"; std::shared_ptr ds = ImageFolder(folder_path, true, RandomSampler(false, 10)); @@ -406,6 +420,8 @@ TEST_F(MindDataTestPipeline, TestCutOut) { } TEST_F(MindDataTestPipeline, TestDecode) { + MS_LOG(INFO) << "Doing MindDataTestPipeline-TestDecode."; + // Create an ImageFolder Dataset std::string folder_path = datasets_root_path_ + "/testPK/data/"; std::shared_ptr ds = ImageFolder(folder_path, false, RandomSampler(false, 10)); @@ -452,6 +468,8 @@ TEST_F(MindDataTestPipeline, TestDecode) { } TEST_F(MindDataTestPipeline, TestHwcToChw) { + MS_LOG(INFO) << "Doing MindDataTestPipeline-TestHwcToChw."; + // Create an ImageFolder Dataset std::string folder_path = datasets_root_path_ + "/testPK/data/"; std::shared_ptr ds = ImageFolder(folder_path, true, RandomSampler(false, 10)); @@ -502,6 +520,8 @@ TEST_F(MindDataTestPipeline, TestHwcToChw) { } TEST_F(MindDataTestPipeline, TestMixUpBatchFail1) { + MS_LOG(INFO) << "Doing MindDataTestPipeline-TestMixUpBatchFail1 with negative alpha parameter."; + // Create a Cifar10 Dataset std::string folder_path = datasets_root_path_ + "/testCifar10Data/"; std::shared_ptr ds = Cifar10(folder_path, "all", RandomSampler(false, 10)); @@ -525,7 +545,8 @@ TEST_F(MindDataTestPipeline, TestMixUpBatchFail1) { } TEST_F(MindDataTestPipeline, TestMixUpBatchFail2) { - // This should fail because alpha can't be zero + MS_LOG(INFO) << "Doing MindDataTestPipeline-TestMixUpBatchFail2 with zero alpha parameter."; + // Create a Cifar10 Dataset std::string folder_path = datasets_root_path_ + "/testCifar10Data/"; std::shared_ptr ds = Cifar10(folder_path, "all", RandomSampler(false, 10)); @@ -549,6 +570,8 @@ TEST_F(MindDataTestPipeline, TestMixUpBatchFail2) { } TEST_F(MindDataTestPipeline, TestMixUpBatchSuccess1) { + MS_LOG(INFO) << "Doing MindDataTestPipeline-TestMixUpBatchSuccess1 with explicit alpha parameter."; + // Create a Cifar10 Dataset std::string folder_path = datasets_root_path_ + "/testCifar10Data/"; std::shared_ptr ds = Cifar10(folder_path, "all", RandomSampler(false, 10)); @@ -598,6 +621,8 @@ TEST_F(MindDataTestPipeline, TestMixUpBatchSuccess1) { } TEST_F(MindDataTestPipeline, TestMixUpBatchSuccess2) { + MS_LOG(INFO) << "Doing MindDataTestPipeline-TestMixUpBatchSuccess1 with default alpha parameter."; + // Create a Cifar10 Dataset std::string folder_path = datasets_root_path_ + "/testCifar10Data/"; std::shared_ptr ds = Cifar10(folder_path, "all", RandomSampler(false, 10)); @@ -647,6 +672,8 @@ TEST_F(MindDataTestPipeline, TestMixUpBatchSuccess2) { } TEST_F(MindDataTestPipeline, TestNormalize) { + MS_LOG(INFO) << "Doing MindDataTestPipeline-TestNormalize."; + // Create an ImageFolder Dataset std::string folder_path = datasets_root_path_ + "/testPK/data/"; std::shared_ptr ds = ImageFolder(folder_path, true, RandomSampler(false, 10)); @@ -693,7 +720,30 @@ TEST_F(MindDataTestPipeline, TestNormalize) { iter->Stop(); } +TEST_F(MindDataTestPipeline, TestNormalizeFail) { + MS_LOG(INFO) << "Doing MindDataTestPipeline-TestNormalizeFail with invalid parameters."; + + // mean value 0.0 + std::shared_ptr normalize = + mindspore::dataset::api::vision::Normalize({0.0, 115.0, 100.0}, {70.0, 68.0, 71.0}); + EXPECT_EQ(normalize, nullptr); + // std value at 0.0 + normalize = mindspore::dataset::api::vision::Normalize({121.0, 115.0, 100.0}, {0.0, 68.0, 71.0}); + EXPECT_EQ(normalize, nullptr); + // mean value 300.0 greater than 255.0 + normalize = mindspore::dataset::api::vision::Normalize({300.0, 115.0, 100.0}, {70.0, 68.0, 71.0}); + EXPECT_EQ(normalize, nullptr); + // normalize with 2 values (not 3 values) for mean + normalize = mindspore::dataset::api::vision::Normalize({121.0, 115.0}, {70.0, 68.0, 71.0}); + EXPECT_EQ(normalize, nullptr); + // normalize with 2 values (not 3 values) for standard deviation + normalize = mindspore::dataset::api::vision::Normalize({121.0, 115.0, 100.0}, {68.0, 71.0}); + EXPECT_EQ(normalize, nullptr); +} + TEST_F(MindDataTestPipeline, TestPad) { + MS_LOG(INFO) << "Doing MindDataTestPipeline-TestPad."; + // Create an ImageFolder Dataset std::string folder_path = datasets_root_path_ + "/testPK/data/"; std::shared_ptr ds = ImageFolder(folder_path, true, RandomSampler(false, 10)); @@ -747,7 +797,7 @@ TEST_F(MindDataTestPipeline, TestPad) { } TEST_F(MindDataTestPipeline, TestRandomAffineFail) { - MS_LOG(INFO) << "Doing MindDataTestPipeline-TestRandomAffineFail with invalid params."; + MS_LOG(INFO) << "Doing MindDataTestPipeline-TestRandomAffineFail with invalid parameters."; // Create objects for the tensor ops std::shared_ptr affine = vision::RandomAffine({0.0, 0.0}, {}); @@ -761,7 +811,7 @@ TEST_F(MindDataTestPipeline, TestRandomAffineFail) { } TEST_F(MindDataTestPipeline, TestRandomAffineSuccess1) { - MS_LOG(INFO) << "Doing MindDataTestPipeline-TestRandomAffineSuccess1 with non-default params."; + MS_LOG(INFO) << "Doing MindDataTestPipeline-TestRandomAffineSuccess1 with non-default parameters."; // Create an ImageFolder Dataset std::string folder_path = datasets_root_path_ + "/testPK/data/"; @@ -811,7 +861,7 @@ TEST_F(MindDataTestPipeline, TestRandomAffineSuccess1) { } TEST_F(MindDataTestPipeline, TestRandomAffineSuccess2) { - MS_LOG(INFO) << "Doing MindDataTestPipeline-TestRandomAffineSuccess2 with default params."; + MS_LOG(INFO) << "Doing MindDataTestPipeline-TestRandomAffineSuccess2 with default parameters."; // Create an ImageFolder Dataset std::string folder_path = datasets_root_path_ + "/testPK/data/"; @@ -860,7 +910,7 @@ TEST_F(MindDataTestPipeline, TestRandomAffineSuccess2) { } TEST_F(MindDataTestPipeline, TestRandomColor) { - MS_LOG(INFO) << "Doing MindDataTestPipeline-TestRandomColor with non-default params."; + MS_LOG(INFO) << "Doing MindDataTestPipeline-TestRandomColor with non-default parameters."; // Create an ImageFolder Dataset std::string folder_path = datasets_root_path_ + "/testPK/data/"; @@ -873,15 +923,22 @@ TEST_F(MindDataTestPipeline, TestRandomColor) { EXPECT_NE(ds, nullptr); // Create objects for the tensor ops + // Valid case: Set lower bound and upper bound to be the same value zero std::shared_ptr random_color_op_1 = vision::RandomColor(0.0, 0.0); EXPECT_NE(random_color_op_1, nullptr); + // Failure case: Set invalid lower bound greater than upper bound std::shared_ptr random_color_op_2 = vision::RandomColor(1.0, 0.1); EXPECT_EQ(random_color_op_2, nullptr); + // Valid case: Set lower bound as zero and less than upper bound std::shared_ptr random_color_op_3 = vision::RandomColor(0.0, 1.1); EXPECT_NE(random_color_op_3, nullptr); + // Failure case: Set invalid negative lower bound + std::shared_ptr random_color_op_4 = vision::RandomColor(-0.5, 0.5); + EXPECT_EQ(random_color_op_2, nullptr); + // Create a Map operation on ds ds = ds->Map({random_color_op_1, random_color_op_3}); EXPECT_NE(ds, nullptr); @@ -915,6 +972,8 @@ TEST_F(MindDataTestPipeline, TestRandomColor) { } TEST_F(MindDataTestPipeline, TestRandomColorAdjust) { + MS_LOG(INFO) << "Doing MindDataTestPipeline-TestRandomColorAdjust."; + // Create an ImageFolder Dataset std::string folder_path = datasets_root_path_ + "/testPK/data/"; std::shared_ptr ds = ImageFolder(folder_path, true, RandomSampler(false, 10)); @@ -926,22 +985,31 @@ TEST_F(MindDataTestPipeline, TestRandomColorAdjust) { EXPECT_NE(ds, nullptr); // Create objects for the tensor ops + // Use single value for vectors std::shared_ptr random_color_adjust1 = vision::RandomColorAdjust({1.0}, {0.0}, {0.5}, {0.5}); EXPECT_NE(random_color_adjust1, nullptr); + // Use same 2 values for vectors std::shared_ptr random_color_adjust2 = vision::RandomColorAdjust({1.0, 1.0}, {0.0, 0.0}, {0.5, 0.5}, {0.5, 0.5}); EXPECT_NE(random_color_adjust2, nullptr); + // Use different 2 value for vectors std::shared_ptr random_color_adjust3 = vision::RandomColorAdjust({0.5, 1.0}, {0.0, 0.5}, {0.25, 0.5}, {0.25, 0.5}); EXPECT_NE(random_color_adjust3, nullptr); + // Use default input values std::shared_ptr random_color_adjust4 = vision::RandomColorAdjust(); EXPECT_NE(random_color_adjust4, nullptr); + // Use subset of explictly set parameters + std::shared_ptr random_color_adjust5 = vision::RandomColorAdjust({0.0, 0.5}, {0.25}); + EXPECT_NE(random_color_adjust5, nullptr); + // Create a Map operation on ds - ds = ds->Map({random_color_adjust1, random_color_adjust2, random_color_adjust3, random_color_adjust4}); + ds = ds->Map( + {random_color_adjust1, random_color_adjust2, random_color_adjust3, random_color_adjust4, random_color_adjust5}); EXPECT_NE(ds, nullptr); // Create a Batch operation on ds @@ -972,26 +1040,20 @@ TEST_F(MindDataTestPipeline, TestRandomColorAdjust) { iter->Stop(); } -TEST_F(MindDataTestPipeline, TestRandomPosterizeFail) { - MS_LOG(INFO) << "Doing MindDataTestPipeline-TestRandomPosterize with invalid params."; +TEST_F(MindDataTestPipeline, DISABLED_TestRandomHorizontalFlipFail) { + MS_LOG(INFO) << "Doing MindDataTestPipeline-TestRandomHorizontalFlipFail with invalid parameters."; - // Create objects for the tensor ops - // Invalid max > 8 - std::shared_ptr posterize = vision::RandomPosterize({1, 9}); - EXPECT_EQ(posterize, nullptr); - // Invalid min < 1 - posterize = vision::RandomPosterize({0, 8}); - EXPECT_EQ(posterize, nullptr); - // min > max - posterize = vision::RandomPosterize({8, 1}); - EXPECT_EQ(posterize, nullptr); - // empty - posterize = vision::RandomPosterize({}); - EXPECT_EQ(posterize, nullptr); + // Create object for the tensor op + // Invalid zero input + std::shared_ptr random_horizontal_flip_op = vision::RandomHorizontalFlip(0); + EXPECT_EQ(random_horizontal_flip_op, nullptr); + // Invalid >1 input + random_horizontal_flip_op = vision::RandomHorizontalFlip(2); + EXPECT_EQ(random_horizontal_flip_op, nullptr); } -TEST_F(MindDataTestPipeline, TestRandomPosterizeSuccess1) { - MS_LOG(INFO) << "Doing MindDataTestPipeline-TestRandomPosterizeSuccess1 with non-default params."; +TEST_F(MindDataTestPipeline, TestRandomHorizontalAndVerticalFlip) { + MS_LOG(INFO) << "Doing MindDataTestPipeline-TestRandomHorizontalAndVerticalFlip for horizontal and vertical flips."; // Create an ImageFolder Dataset std::string folder_path = datasets_root_path_ + "/testPK/data/"; @@ -1004,11 +1066,14 @@ TEST_F(MindDataTestPipeline, TestRandomPosterizeSuccess1) { EXPECT_NE(ds, nullptr); // Create objects for the tensor ops - std::shared_ptr posterize = vision::RandomPosterize({1, 4}); - EXPECT_NE(posterize, nullptr); + std::shared_ptr random_vertical_flip_op = vision::RandomVerticalFlip(0.75); + EXPECT_NE(random_vertical_flip_op, nullptr); + + std::shared_ptr random_horizontal_flip_op = vision::RandomHorizontalFlip(0.5); + EXPECT_NE(random_horizontal_flip_op, nullptr); // Create a Map operation on ds - ds = ds->Map({posterize}); + ds = ds->Map({random_vertical_flip_op, random_horizontal_flip_op}); EXPECT_NE(ds, nullptr); // Create a Batch operation on ds @@ -1039,24 +1104,42 @@ TEST_F(MindDataTestPipeline, TestRandomPosterizeSuccess1) { iter->Stop(); } -TEST_F(MindDataTestPipeline, TestRandomPosterizeSuccess2) { - MS_LOG(INFO) << "Doing MindDataTestPipeline-TestRandomPosterizeSuccess2 with default params."; - - // Create an ImageFolder Dataset - std::string folder_path = datasets_root_path_ + "/testPK/data/"; - std::shared_ptr ds = ImageFolder(folder_path, true, RandomSampler(false, 10)); - EXPECT_NE(ds, nullptr); - - // Create a Repeat operation on ds - int32_t repeat_num = 2; - ds = ds->Repeat(repeat_num); - EXPECT_NE(ds, nullptr); +TEST_F(MindDataTestPipeline, TestRandomPosterizeFail) { + MS_LOG(INFO) << "Doing MindDataTestPipeline-TestRandomPosterizeFail with invalid parameters."; // Create objects for the tensor ops - std::shared_ptr posterize = vision::RandomPosterize(); - EXPECT_NE(posterize, nullptr); - - // Create a Map operation on ds + // Invalid max > 8 + std::shared_ptr posterize = vision::RandomPosterize({1, 9}); + EXPECT_EQ(posterize, nullptr); + // Invalid min < 1 + posterize = vision::RandomPosterize({0, 8}); + EXPECT_EQ(posterize, nullptr); + // min > max + posterize = vision::RandomPosterize({8, 1}); + EXPECT_EQ(posterize, nullptr); + // empty + posterize = vision::RandomPosterize({}); + EXPECT_EQ(posterize, nullptr); +} + +TEST_F(MindDataTestPipeline, TestRandomPosterizeSuccess1) { + MS_LOG(INFO) << "Doing MindDataTestPipeline-TestRandomPosterizeSuccess1 with non-default parameters."; + + // Create an ImageFolder Dataset + std::string folder_path = datasets_root_path_ + "/testPK/data/"; + std::shared_ptr ds = ImageFolder(folder_path, true, RandomSampler(false, 10)); + EXPECT_NE(ds, nullptr); + + // Create a Repeat operation on ds + int32_t repeat_num = 2; + ds = ds->Repeat(repeat_num); + EXPECT_NE(ds, nullptr); + + // Create objects for the tensor ops + std::shared_ptr posterize = vision::RandomPosterize({1, 4}); + EXPECT_NE(posterize, nullptr); + + // Create a Map operation on ds ds = ds->Map({posterize}); EXPECT_NE(ds, nullptr); @@ -1088,8 +1171,8 @@ TEST_F(MindDataTestPipeline, TestRandomPosterizeSuccess2) { iter->Stop(); } -TEST_F(MindDataTestPipeline, TestRandomSharpness) { - MS_LOG(INFO) << "Doing MindDataTestPipeline-TestRandomSharpness."; +TEST_F(MindDataTestPipeline, TestRandomPosterizeSuccess2) { + MS_LOG(INFO) << "Doing MindDataTestPipeline-TestRandomPosterizeSuccess2 with default parameters."; // Create an ImageFolder Dataset std::string folder_path = datasets_root_path_ + "/testPK/data/"; @@ -1102,20 +1185,11 @@ TEST_F(MindDataTestPipeline, TestRandomSharpness) { EXPECT_NE(ds, nullptr); // Create objects for the tensor ops - std::shared_ptr random_sharpness_op_1 = vision::RandomSharpness({0.4, 2.3}); - EXPECT_NE(random_sharpness_op_1, nullptr); - - std::shared_ptr random_sharpness_op_2 = vision::RandomSharpness({}); - EXPECT_EQ(random_sharpness_op_2, nullptr); - - std::shared_ptr random_sharpness_op_3 = vision::RandomSharpness(); - EXPECT_NE(random_sharpness_op_3, nullptr); - - std::shared_ptr random_sharpness_op_4 = vision::RandomSharpness({0.1}); - EXPECT_EQ(random_sharpness_op_4, nullptr); + std::shared_ptr posterize = vision::RandomPosterize(); + EXPECT_NE(posterize, nullptr); // Create a Map operation on ds - ds = ds->Map({random_sharpness_op_1, random_sharpness_op_3}); + ds = ds->Map({posterize}); EXPECT_NE(ds, nullptr); // Create a Batch operation on ds @@ -1146,31 +1220,59 @@ TEST_F(MindDataTestPipeline, TestRandomSharpness) { iter->Stop(); } -TEST_F(MindDataTestPipeline, TestRandomFlip) { - // Create an ImageFolder Dataset - std::string folder_path = datasets_root_path_ + "/testPK/data/"; - std::shared_ptr ds = ImageFolder(folder_path, true, RandomSampler(false, 10)); +TEST_F(MindDataTestPipeline, TestRandomResizedCropSuccess1) { + // Testing RandomResizedCrop with default values + // Create a Cifar10 Dataset + std::string folder_path = datasets_root_path_ + "/testCifar10Data/"; + std::shared_ptr ds = Cifar10(folder_path, "all", RandomSampler(false, 10)); EXPECT_NE(ds, nullptr); - // Create a Repeat operation on ds - int32_t repeat_num = 2; - ds = ds->Repeat(repeat_num); + // Create objects for the tensor ops + std::shared_ptr random_resized_crop = vision::RandomResizedCrop({5}); + EXPECT_NE(random_resized_crop, nullptr); + + // Create a Map operation on ds + ds = ds->Map({random_resized_crop}, {"image"}); EXPECT_NE(ds, nullptr); - // Create objects for the tensor ops - std::shared_ptr random_vertical_flip_op = vision::RandomVerticalFlip(0.5); - EXPECT_NE(random_vertical_flip_op, nullptr); + // Create an iterator over the result of the above dataset + // This will trigger the creation of the Execution Tree and launch it. + std::shared_ptr iter = ds->CreateIterator(); + EXPECT_NE(iter, nullptr); - std::shared_ptr random_horizontal_flip_op = vision::RandomHorizontalFlip(0.5); - EXPECT_NE(random_horizontal_flip_op, nullptr); + // Iterate the dataset and get each row + std::unordered_map> row; + iter->GetNextRow(&row); - // Create a Map operation on ds - ds = ds->Map({random_vertical_flip_op, random_horizontal_flip_op}); + uint64_t i = 0; + while (row.size() != 0) { + i++; + auto image = row["image"]; + MS_LOG(INFO) << "Tensor image shape: " << image->shape(); + EXPECT_EQ(image->shape()[0] == 5 && image->shape()[1] == 5, true); + iter->GetNextRow(&row); + } + + EXPECT_EQ(i, 10); + + // Manually terminate the pipeline + iter->Stop(); +} + +TEST_F(MindDataTestPipeline, TestRandomResizedCropSuccess2) { + // Testing RandomResizedCrop with non-default values + // Create a Cifar10 Dataset + std::string folder_path = datasets_root_path_ + "/testCifar10Data/"; + std::shared_ptr ds = Cifar10(folder_path, "all", RandomSampler(false, 10)); EXPECT_NE(ds, nullptr); - // Create a Batch operation on ds - int32_t batch_size = 1; - ds = ds->Batch(batch_size); + // Create objects for the tensor ops + std::shared_ptr random_resized_crop = + vision::RandomResizedCrop({5, 10}, {0.25, 0.75}, {0.5, 1.25}, mindspore::dataset::InterpolationMode::kArea, 20); + EXPECT_NE(random_resized_crop, nullptr); + + // Create a Map operation on ds + ds = ds->Map({random_resized_crop}, {"image"}); EXPECT_NE(ds, nullptr); // Create an iterator over the result of the above dataset @@ -1187,16 +1289,67 @@ TEST_F(MindDataTestPipeline, TestRandomFlip) { i++; auto image = row["image"]; MS_LOG(INFO) << "Tensor image shape: " << image->shape(); + EXPECT_EQ(image->shape()[0] == 5 && image->shape()[1] == 10, true); iter->GetNextRow(&row); } - EXPECT_EQ(i, 20); + EXPECT_EQ(i, 10); // Manually terminate the pipeline iter->Stop(); } +TEST_F(MindDataTestPipeline, TestRandomResizedCropFail1) { + // This should fail because size has negative value + // Create a Cifar10 Dataset + std::string folder_path = datasets_root_path_ + "/testCifar10Data/"; + std::shared_ptr ds = Cifar10(folder_path, "all", RandomSampler(false, 10)); + EXPECT_NE(ds, nullptr); + + // Create objects for the tensor ops + std::shared_ptr random_resized_crop = vision::RandomResizedCrop({5, -10}); + EXPECT_EQ(random_resized_crop, nullptr); +} + +TEST_F(MindDataTestPipeline, TestRandomResizedCropFail2) { + // This should fail because scale isn't in {min, max} format + // Create a Cifar10 Dataset + std::string folder_path = datasets_root_path_ + "/testCifar10Data/"; + std::shared_ptr ds = Cifar10(folder_path, "all", RandomSampler(false, 10)); + EXPECT_NE(ds, nullptr); + + // Create objects for the tensor ops + std::shared_ptr random_resized_crop = vision::RandomResizedCrop({5, 10}, {4, 3}); + EXPECT_EQ(random_resized_crop, nullptr); +} + +TEST_F(MindDataTestPipeline, TestRandomResizedCropFail3) { + // This should fail because ratio isn't in {min, max} format + // Create a Cifar10 Dataset + std::string folder_path = datasets_root_path_ + "/testCifar10Data/"; + std::shared_ptr ds = Cifar10(folder_path, "all", RandomSampler(false, 10)); + EXPECT_NE(ds, nullptr); + + // Create objects for the tensor ops + std::shared_ptr random_resized_crop = vision::RandomResizedCrop({5, 10}, {4, 5}, {7, 6}); + EXPECT_EQ(random_resized_crop, nullptr); +} + +TEST_F(MindDataTestPipeline, TestRandomResizedCropFail4) { + // This should fail because scale has a size of more than 2 + // Create a Cifar10 Dataset + std::string folder_path = datasets_root_path_ + "/testCifar10Data/"; + std::shared_ptr ds = Cifar10(folder_path, "all", RandomSampler(false, 10)); + EXPECT_NE(ds, nullptr); + + // Create objects for the tensor ops + std::shared_ptr random_resized_crop = vision::RandomResizedCrop({5, 10, 20}, {4, 5}, {7, 6}); + EXPECT_EQ(random_resized_crop, nullptr); +} + TEST_F(MindDataTestPipeline, TestRandomRotation) { + MS_LOG(INFO) << "Doing MindDataTestPipeline-TestRandomRotation."; + // Create an ImageFolder Dataset std::string folder_path = datasets_root_path_ + "/testPK/data/"; std::shared_ptr ds = ImageFolder(folder_path, true, RandomSampler(false, 10)); @@ -1243,32 +1396,43 @@ TEST_F(MindDataTestPipeline, TestRandomRotation) { iter->Stop(); } -TEST_F(MindDataTestPipeline, TestUniformAugWithOps) { - // Create a Mnist Dataset - std::string folder_path = datasets_root_path_ + "/testMnistData/"; - std::shared_ptr ds = Mnist(folder_path, "all", RandomSampler(false, 20)); +TEST_F(MindDataTestPipeline, TestRandomSharpness) { + MS_LOG(INFO) << "Doing MindDataTestPipeline-TestRandomSharpness."; + + // Create an ImageFolder Dataset + std::string folder_path = datasets_root_path_ + "/testPK/data/"; + std::shared_ptr ds = ImageFolder(folder_path, true, RandomSampler(false, 10)); EXPECT_NE(ds, nullptr); // Create a Repeat operation on ds - int32_t repeat_num = 1; + int32_t repeat_num = 2; ds = ds->Repeat(repeat_num); EXPECT_NE(ds, nullptr); // Create objects for the tensor ops - std::shared_ptr resize_op = vision::Resize({30, 30}); - EXPECT_NE(resize_op, nullptr); + // Valid case: Input start degree and end degree + std::shared_ptr random_sharpness_op_1 = vision::RandomSharpness({0.4, 2.3}); + EXPECT_NE(random_sharpness_op_1, nullptr); - std::shared_ptr random_crop_op = vision::RandomCrop({28, 28}); - EXPECT_NE(random_crop_op, nullptr); + // Failure case: Empty degrees vector + std::shared_ptr random_sharpness_op_2 = vision::RandomSharpness({}); + EXPECT_EQ(random_sharpness_op_2, nullptr); - std::shared_ptr center_crop_op = vision::CenterCrop({16, 16}); - EXPECT_NE(center_crop_op, nullptr); + // Valid case: Use default input values + std::shared_ptr random_sharpness_op_3 = vision::RandomSharpness(); + EXPECT_NE(random_sharpness_op_3, nullptr); - std::shared_ptr uniform_aug_op = vision::UniformAugment({random_crop_op, center_crop_op}, 2); - EXPECT_NE(uniform_aug_op, nullptr); + // Failure case: Single degree value + std::shared_ptr random_sharpness_op_4 = vision::RandomSharpness({0.1}); + EXPECT_EQ(random_sharpness_op_4, nullptr); // Create a Map operation on ds - ds = ds->Map({resize_op, uniform_aug_op}); + ds = ds->Map({random_sharpness_op_1, random_sharpness_op_3}); + EXPECT_NE(ds, nullptr); + + // Create a Batch operation on ds + int32_t batch_size = 1; + ds = ds->Batch(batch_size); EXPECT_NE(ds, nullptr); // Create an iterator over the result of the above dataset @@ -1295,7 +1459,7 @@ TEST_F(MindDataTestPipeline, TestUniformAugWithOps) { } TEST_F(MindDataTestPipeline, TestRandomSolarizeSucess1) { - MS_LOG(INFO) << "Doing MindDataTestPipeline-TestRandomSolarize."; + MS_LOG(INFO) << "Doing MindDataTestPipeline-TestRandomSolarizeSucess1."; // Create an ImageFolder Dataset std::string folder_path = datasets_root_path_ + "/testPK/data/"; @@ -1335,7 +1499,8 @@ TEST_F(MindDataTestPipeline, TestRandomSolarizeSucess1) { } TEST_F(MindDataTestPipeline, TestRandomSolarizeSucess2) { - MS_LOG(INFO) << "Doing MindDataTestPipeline-TestRandomSolarize with default params."; + MS_LOG(INFO) << "Doing MindDataTestPipeline-TestRandomSolarizeSuccess2 with default parameters."; + // Create an ImageFolder Dataset std::string folder_path = datasets_root_path_ + "/testPK/data/"; std::shared_ptr ds = ImageFolder(folder_path, true, RandomSampler(false, 10)); @@ -1373,7 +1538,8 @@ TEST_F(MindDataTestPipeline, TestRandomSolarizeSucess2) { } TEST_F(MindDataTestPipeline, TestRandomSolarizeFail) { - MS_LOG(INFO) << "Doing MindDataTestPipeline-TestRandomSolarize with invalid params."; + MS_LOG(INFO) << "Doing MindDataTestPipeline-TestRandomSolarizeFail with invalid parameters."; + std::vector threshold = {13, 1}; std::shared_ptr random_solarize = mindspore::dataset::api::vision::RandomSolarize(threshold); EXPECT_EQ(random_solarize, nullptr); @@ -1391,111 +1557,54 @@ TEST_F(MindDataTestPipeline, TestRandomSolarizeFail) { EXPECT_EQ(random_solarize, nullptr); } -TEST_F(MindDataTestPipeline, TestResizeFail) { - MS_LOG(INFO) << "Doing MindDataTestPipeline-TestResize with invalid params."; - // negative resize value - std::shared_ptr resize = mindspore::dataset::api::vision::Resize({30, -30}); - EXPECT_EQ(resize, nullptr); - // zero resize value - resize = mindspore::dataset::api::vision::Resize({0, 30}); - EXPECT_EQ(resize, nullptr); -} - -TEST_F(MindDataTestPipeline, TestCropFail) { - MS_LOG(INFO) << "Doing MindDataTestPipeline-TestCrop with invalid params."; - // wrong width - std::shared_ptr crop = mindspore::dataset::api::vision::Crop({0, 0}, {32, -32}); - EXPECT_EQ(crop, nullptr); - // wrong height - crop = mindspore::dataset::api::vision::Crop({0, 0}, {-32, -32}); - EXPECT_EQ(crop, nullptr); - // zero height - crop = mindspore::dataset::api::vision::Crop({0, 0}, {0, 32}); - EXPECT_EQ(crop, nullptr); -} +TEST_F(MindDataTestPipeline, DISABLED_TestRandomVerticalFlipFail) { + MS_LOG(INFO) << "Doing MindDataTestPipeline-TestRandomVerticalFlipFail with invalid parameters."; -TEST_F(MindDataTestPipeline, TestCenterCropFail) { - MS_LOG(INFO) << "Doing MindDataTestPipeline-TestCenterCrop with invalid params."; - // center crop height value negative - std::shared_ptr center_crop = mindspore::dataset::api::vision::CenterCrop({-32, 32}); - EXPECT_EQ(center_crop, nullptr); - // center crop width value negative - center_crop = mindspore::dataset::api::vision::CenterCrop({32, -32}); - EXPECT_EQ(center_crop, nullptr); - // 0 value would result in nullptr - center_crop = mindspore::dataset::api::vision::CenterCrop({0, 32}); - EXPECT_EQ(center_crop, nullptr); + // Create object for the tensor op + // Invalid zero input + std::shared_ptr random_vertical_flip_op = vision::RandomVerticalFlip(0); + EXPECT_EQ(random_vertical_flip_op, nullptr); + // Invalid >1 input + random_vertical_flip_op = vision::RandomVerticalFlip(1.1); + EXPECT_EQ(random_vertical_flip_op, nullptr); } -TEST_F(MindDataTestPipeline, TestNormalizeFail) { - MS_LOG(INFO) << "Doing MindDataTestPipeline-TestNormalize with invalid params."; - // mean value 0.0 - std::shared_ptr normalize = - mindspore::dataset::api::vision::Normalize({0.0, 115.0, 100.0}, {70.0, 68.0, 71.0}); - EXPECT_EQ(normalize, nullptr); - // std value at 0.0 - normalize = mindspore::dataset::api::vision::Normalize({121.0, 115.0, 100.0}, {0.0, 68.0, 71.0}); - EXPECT_EQ(normalize, nullptr); - // mean value 300.0 greater than 255.0 - normalize = mindspore::dataset::api::vision::Normalize({300.0, 115.0, 100.0}, {70.0, 68.0, 71.0}); - EXPECT_EQ(normalize, nullptr); +TEST_F(MindDataTestPipeline, TestResizeFail) { + MS_LOG(INFO) << "Doing MindDataTestPipeline-TestResize with invalid parameters."; + // negative resize value + std::shared_ptr resize_op = mindspore::dataset::api::vision::Resize({30, -30}); + EXPECT_EQ(resize_op, nullptr); + // zero resize value + resize_op = mindspore::dataset::api::vision::Resize({0, 30}); + EXPECT_EQ(resize_op, nullptr); + // resize with 3 values + resize_op = mindspore::dataset::api::vision::Resize({30, 20, 10}); + EXPECT_EQ(resize_op, nullptr); } -TEST_F(MindDataTestPipeline, TestRandomCropDecodeResizeSucess1) { - MS_LOG(INFO) << "Doing MindDataTestPipeline-TestRandomCropDecodeResize with default params."; +TEST_F(MindDataTestPipeline, TestResize1) { + MS_LOG(INFO) << "Doing MindDataTestPipeline-TestResize1 with single integer input."; // Create an ImageFolder Dataset std::string folder_path = datasets_root_path_ + "/testPK/data/"; - std::shared_ptr ds = ImageFolder(folder_path, false, SequentialSampler(0, 2)); + std::shared_ptr ds = ImageFolder(folder_path, true, RandomSampler(false, 6)); EXPECT_NE(ds, nullptr); - // Create objects for the tensor ops - std::shared_ptr random_crop_decode_resize = - mindspore::dataset::api::vision::RandomCropDecodeResize({50, 60}); - EXPECT_NE(random_crop_decode_resize, nullptr); - - // Create a Map operation on ds - ds = ds->Map({random_crop_decode_resize}); + // Create a Repeat operation on ds + int32_t repeat_num = 4; + ds = ds->Repeat(repeat_num); EXPECT_NE(ds, nullptr); - // Create an iterator over the result of the above dataset - // This will trigger the creation of the Execution Tree and launch it. - std::shared_ptr iter = ds->CreateIterator(); - EXPECT_NE(iter, nullptr); - - // Iterate the dataset and get each row - std::unordered_map> row; - iter->GetNextRow(&row); - - uint64_t i = 0; - while (row.size() != 0) { - i++; - auto image = row["image"]; - MS_LOG(INFO) << "Tensor image shape: " << image->shape(); - iter->GetNextRow(&row); - EXPECT_EQ(image->shape()[0], 50); - EXPECT_EQ(image->shape()[1], 60); - } - - EXPECT_EQ(i, 2); - - // Manually terminate the pipeline - iter->Stop(); -} + // Create resize object with single integer input + std::shared_ptr resize_op = vision::Resize({30}); + EXPECT_NE(resize_op, nullptr); -TEST_F(MindDataTestPipeline, TestRandomCropDecodeResizeSucess2) { - MS_LOG(INFO) << "Doing MindDataTestPipeline-TestRandomCropDecodeResize with single size."; - // Create an ImageFolder Dataset - std::string folder_path = datasets_root_path_ + "/testPK/data/"; - std::shared_ptr ds = ImageFolder(folder_path, false, RandomSampler(false, 3)); + // Create a Map operation on ds + ds = ds->Map({resize_op}); EXPECT_NE(ds, nullptr); - // Create objects for the tensor ops - std::shared_ptr random_crop_decode_resize = - mindspore::dataset::api::vision::RandomCropDecodeResize({100}); - EXPECT_NE(random_crop_decode_resize, nullptr); - - // Create a Map operation on ds - ds = ds->Map({random_crop_decode_resize}); + // Create a Batch operation on ds + int32_t batch_size = 1; + ds = ds->Batch(batch_size); EXPECT_NE(ds, nullptr); // Create an iterator over the result of the above dataset @@ -1513,106 +1622,82 @@ TEST_F(MindDataTestPipeline, TestRandomCropDecodeResizeSucess2) { auto image = row["image"]; MS_LOG(INFO) << "Tensor image shape: " << image->shape(); iter->GetNextRow(&row); - EXPECT_EQ(image->shape()[0], 100); - EXPECT_EQ(image->shape()[1], 100); } - EXPECT_EQ(i, 3); + EXPECT_EQ(i, 24); // Manually terminate the pipeline iter->Stop(); } -TEST_F(MindDataTestPipeline, TestRandomCropDecodeResizeFail) { - MS_LOG(INFO) << "Doing MindDataTestPipeline-TestRandomCropDecodeResize with invalid params."; - // size of size vector is not 1 or 2 - std::shared_ptr random_crop_decode_resize_1 = - mindspore::dataset::api::vision::RandomCropDecodeResize({50, 100, 150}); - EXPECT_EQ(random_crop_decode_resize_1, nullptr); - - // incorrect scale vector - std::shared_ptr random_crop_decode_resize_2 = - mindspore::dataset::api::vision::RandomCropDecodeResize({50, 50}, {0.5}); - EXPECT_EQ(random_crop_decode_resize_2, nullptr); - - std::shared_ptr random_crop_decode_resize_3 = - mindspore::dataset::api::vision::RandomCropDecodeResize({50, 50}, {0.5, 0.1}); - EXPECT_EQ(random_crop_decode_resize_3, nullptr); - - // incorrect ratio vector - std::shared_ptr random_crop_decode_resize_4 = - mindspore::dataset::api::vision::RandomCropDecodeResize({50, 50}, {0.5, 0.6}, {0.9}); - EXPECT_EQ(random_crop_decode_resize_4, nullptr); - - std::shared_ptr random_crop_decode_resize_5 = - mindspore::dataset::api::vision::RandomCropDecodeResize({50, 50}, {0.5, 0.6}, {0.9, 0.1}); - EXPECT_EQ(random_crop_decode_resize_5, nullptr); - - // incorrect max_attempts range - std::shared_ptr random_crop_decode_resize_6 = - mindspore::dataset::api::vision::RandomCropDecodeResize({50, 50}, {0.5, 0.6}, {0.9, 0.9}, - mindspore::dataset::InterpolationMode::kLinear, 0); - EXPECT_EQ(random_crop_decode_resize_6, nullptr); -} +TEST_F(MindDataTestPipeline, DISABLED_TestUniformAugmentFail1) { + MS_LOG(INFO) << "Doing MindDataTestPipeline-TestUniformAugmentFail1 with invalid zero num_ops parameter."; -TEST_F(MindDataTestPipeline, TestRescaleSucess1) { - MS_LOG(INFO) << "Doing MindDataTestPipeline-TestRescaleSucess1."; - // Create an ImageFolder Dataset - std::string folder_path = datasets_root_path_ + "/testPK/data/"; - std::shared_ptr ds = ImageFolder(folder_path, true, SequentialSampler(0, 1)); + // Create a Mnist Dataset + std::string folder_path = datasets_root_path_ + "/testMnistData/"; + std::shared_ptr ds = Mnist(folder_path, "all", RandomSampler(false, 20)); EXPECT_NE(ds, nullptr); - // Create an iterator over the result of the above dataset - // This will trigger the creation of the Execution Tree and launch it. - std::shared_ptr iter = ds->CreateIterator(); - EXPECT_NE(iter, nullptr); - - // Iterate the dataset and get each row - std::unordered_map> row; - iter->GetNextRow(&row); + // Create objects for the tensor ops + std::shared_ptr random_crop_op = vision::RandomCrop({28, 28}); + EXPECT_NE(random_crop_op, nullptr); - auto image = row["image"]; + std::shared_ptr center_crop_op = vision::CenterCrop({16, 16}); + EXPECT_NE(center_crop_op, nullptr); - // Create objects for the tensor ops - std::shared_ptr rescale = mindspore::dataset::api::vision::Rescale(1.0, 0.0); - EXPECT_NE(rescale, nullptr); + // Try UniformAugment with invalid zero num_ops value + std::shared_ptr uniform_aug_op = vision::UniformAugment({random_crop_op, center_crop_op}, 0); + EXPECT_EQ(uniform_aug_op, nullptr); +} - // Convert to the same type - std::shared_ptr type_cast = transforms::TypeCast("uint8"); - EXPECT_NE(type_cast, nullptr); +TEST_F(MindDataTestPipeline, DISABLED_TestUniformAugmentFail2) { + MS_LOG(INFO) << "Doing MindDataTestPipeline-TestUniformAugmentFail2 with invalid negative num_ops parameter."; - ds = ds->Map({rescale, type_cast}, {"image"}); + // Create a Mnist Dataset + std::string folder_path = datasets_root_path_ + "/testMnistData/"; + std::shared_ptr ds = Mnist(folder_path, "all", RandomSampler(false, 20)); EXPECT_NE(ds, nullptr); - // Create an iterator over the result of the above dataset - // This will trigger the creation of the Execution Tree and launch it. - std::shared_ptr iter1 = ds->CreateIterator(); - EXPECT_NE(iter1, nullptr); + // Create objects for the tensor ops + std::shared_ptr random_crop_op = vision::RandomCrop({28, 28}); + EXPECT_NE(random_crop_op, nullptr); - // Iterate the dataset and get each row1 - std::unordered_map> row1; - iter1->GetNextRow(&row1); + std::shared_ptr center_crop_op = vision::CenterCrop({16, 16}); + EXPECT_NE(center_crop_op, nullptr); - auto image1 = row1["image"]; + // Try UniformAugment with invalid negative num_ops value + std::shared_ptr uniform_aug_op = vision::UniformAugment({random_crop_op, center_crop_op}, -1); + EXPECT_EQ(uniform_aug_op, nullptr); +} - EXPECT_EQ(*image, *image1); +TEST_F(MindDataTestPipeline, TestUniformAugWithOps) { + MS_LOG(INFO) << "Doing MindDataTestPipeline-TestUniformAugWithOps."; - // Manually terminate the pipeline - iter1->Stop(); -} + // Create a Mnist Dataset + std::string folder_path = datasets_root_path_ + "/testMnistData/"; + std::shared_ptr ds = Mnist(folder_path, "all", RandomSampler(false, 20)); + EXPECT_NE(ds, nullptr); -TEST_F(MindDataTestPipeline, TestRescaleSucess2) { - MS_LOG(INFO) << "Doing MindDataTestPipeline-TestRescaleSucess2 with different params."; - // Create an ImageFolder Dataset - std::string folder_path = datasets_root_path_ + "/testPK/data/"; - std::shared_ptr ds = ImageFolder(folder_path, true, RandomSampler(false, 1)); + // Create a Repeat operation on ds + int32_t repeat_num = 1; + ds = ds->Repeat(repeat_num); EXPECT_NE(ds, nullptr); // Create objects for the tensor ops - std::shared_ptr rescale = mindspore::dataset::api::vision::Rescale(1.0 / 255, 1.0); - EXPECT_NE(rescale, nullptr); + std::shared_ptr resize_op = vision::Resize({30, 30}); + EXPECT_NE(resize_op, nullptr); + + std::shared_ptr random_crop_op = vision::RandomCrop({28, 28}); + EXPECT_NE(random_crop_op, nullptr); - ds = ds->Map({rescale}, {"image"}); + std::shared_ptr center_crop_op = vision::CenterCrop({16, 16}); + EXPECT_NE(center_crop_op, nullptr); + + std::shared_ptr uniform_aug_op = vision::UniformAugment({random_crop_op, center_crop_op}, 2); + EXPECT_NE(uniform_aug_op, nullptr); + + // Create a Map operation on ds + ds = ds->Map({resize_op, uniform_aug_op}); EXPECT_NE(ds, nullptr); // Create an iterator over the result of the above dataset @@ -1632,15 +1717,8 @@ TEST_F(MindDataTestPipeline, TestRescaleSucess2) { iter->GetNextRow(&row); } - EXPECT_EQ(i, 1); + EXPECT_EQ(i, 20); // Manually terminate the pipeline iter->Stop(); } - -TEST_F(MindDataTestPipeline, TestRescaleFail) { - MS_LOG(INFO) << "Doing MindDataTestPipeline-TestRescaleSucess3 with invalid params."; - // incorrect negative rescale parameter - std::shared_ptr rescale = mindspore::dataset::api::vision::Rescale(-1.0, 0.0); - EXPECT_EQ(rescale, nullptr); -} \ No newline at end of file