From: @cathwong Reviewed-by: Signed-off-by:tags/v1.2.0-rc1
| @@ -76,8 +76,8 @@ TEST_F(MindDataTestPipeline, TestImageFolderWithSamplers) { | |||
| uint64_t i = 0; | |||
| while (row.size() != 0) { | |||
| i++; | |||
| // auto image = row["image"]; | |||
| // MS_LOG(INFO) << "Tensor image shape: " << image->shape(); | |||
| auto image = row["image"]; | |||
| MS_LOG(INFO) << "Tensor image shape: " << image.Shape(); | |||
| iter->GetNextRow(&row); | |||
| } | |||
| @@ -239,7 +239,8 @@ TEST_F(MindDataTestPipeline, TestDistributedSamplerSuccess2) { | |||
| // num_shards=4, shard_id=0, shuffle=false, num_samplers=0, seed=0, offset=-1, even_dist=true | |||
| Sampler *sampler = new DistributedSampler(4, 0, false, 0, 0, -1, true); | |||
| EXPECT_NE(sampler, nullptr); | |||
| // Note that with new, we have to explicitly delete the allocated object as shown below. | |||
| // Note: No need to check for output after calling API class constructor | |||
| // Create an ImageFolder Dataset | |||
| std::string folder_path = datasets_root_path_ + "/testPK/data/"; | |||
| @@ -261,6 +262,9 @@ TEST_F(MindDataTestPipeline, TestDistributedSamplerSuccess2) { | |||
| EXPECT_EQ(i, 11); | |||
| iter->Stop(); | |||
| // Delete allocated objects with raw pointers | |||
| delete sampler; | |||
| } | |||
| TEST_F(MindDataTestPipeline, TestDistributedSamplerSuccess3) { | |||
| @@ -318,7 +322,8 @@ TEST_F(MindDataTestPipeline, TestDistributedSamplerFail2) { | |||
| // num_shards=4, shard_id=0, shuffle=false, num_samplers=0, seed=0, offset=5, even_dist=true | |||
| // offset=5 which is greater than num_shards=4 --> will fail later | |||
| Sampler *sampler = new DistributedSampler(4, 0, false, 0, 0, 5, false); | |||
| EXPECT_NE(sampler, nullptr); | |||
| // Note that with new, we have to explicitly delete the allocated object as shown below. | |||
| // Note: No need to check for output after calling API class constructor | |||
| // Create an ImageFolder Dataset | |||
| std::string folder_path = datasets_root_path_ + "/testPK/data/"; | |||
| @@ -328,6 +333,9 @@ TEST_F(MindDataTestPipeline, TestDistributedSamplerFail2) { | |||
| // Iterate will fail because sampler is not initiated successfully. | |||
| std::shared_ptr<Iterator> iter = ds->CreateIterator(); | |||
| EXPECT_EQ(iter, nullptr); | |||
| // Delete allocated objects with raw pointers | |||
| delete sampler; | |||
| } | |||
| TEST_F(MindDataTestPipeline, TestDistributedSamplerFail3) { | |||
| @@ -42,7 +42,7 @@ TEST_F(MindDataTestPipeline, TestAutoContrastSuccess1) { | |||
| // Create auto contrast object with default values | |||
| std::shared_ptr<TensorTransform> auto_contrast(new vision::AutoContrast()); | |||
| EXPECT_NE(auto_contrast, nullptr); | |||
| // Note: No need to check for output after calling API class constructor | |||
| // Create a Map operation on ds | |||
| ds = ds->Map({auto_contrast}); | |||
| @@ -65,8 +65,8 @@ TEST_F(MindDataTestPipeline, TestAutoContrastSuccess1) { | |||
| uint64_t i = 0; | |||
| while (row.size() != 0) { | |||
| i++; | |||
| // auto image = row["image"]; | |||
| // MS_LOG(INFO) << "Tensor image shape: " << image->shape(); | |||
| auto image = row["image"]; | |||
| MS_LOG(INFO) << "Tensor image shape: " << image.Shape(); | |||
| iter->GetNextRow(&row); | |||
| } | |||
| @@ -91,7 +91,7 @@ TEST_F(MindDataTestPipeline, TestAutoContrastSuccess2) { | |||
| // Create auto contrast object | |||
| std::shared_ptr<TensorTransform> auto_contrast(new vision::AutoContrast(10, {10, 20})); | |||
| EXPECT_NE(auto_contrast, nullptr); | |||
| // Note: No need to check for output after calling API class constructor | |||
| // Create a Map operation on ds | |||
| ds = ds->Map({auto_contrast}); | |||
| @@ -114,8 +114,8 @@ TEST_F(MindDataTestPipeline, TestAutoContrastSuccess2) { | |||
| uint64_t i = 0; | |||
| while (row.size() != 0) { | |||
| i++; | |||
| // auto image = row["image"]; | |||
| // MS_LOG(INFO) << "Tensor image shape: " << image->shape(); | |||
| auto image = row["image"]; | |||
| MS_LOG(INFO) << "Tensor image shape: " << image.Shape(); | |||
| iter->GetNextRow(&row); | |||
| } | |||
| @@ -125,18 +125,6 @@ TEST_F(MindDataTestPipeline, TestAutoContrastSuccess2) { | |||
| iter->Stop(); | |||
| } | |||
| TEST_F(MindDataTestPipeline, TestAutoContrastFail) { | |||
| // FIXME: For error tests, need to check for failure from CreateIterator execution | |||
| MS_LOG(INFO) << "Doing MindDataTestPipeline-TestAutoContrastFail with invalid params."; | |||
| // Testing invalid cutoff < 0 | |||
| std::shared_ptr<TensorTransform> auto_contrast1(new vision::AutoContrast(-1.0)); | |||
| // FIXME: Need to check error Status is returned during CreateIterator | |||
| EXPECT_NE(auto_contrast1, nullptr); | |||
| // Testing invalid cutoff > 100 | |||
| std::shared_ptr<TensorTransform> auto_contrast2(new vision::AutoContrast(110.0, {10, 20})); | |||
| EXPECT_NE(auto_contrast2, nullptr); | |||
| } | |||
| TEST_F(MindDataTestPipeline, TestCenterCrop) { | |||
| MS_LOG(INFO) << "Doing MindDataTestPipeline-TestCenterCrop with single integer input."; | |||
| @@ -152,7 +140,7 @@ TEST_F(MindDataTestPipeline, TestCenterCrop) { | |||
| // Create centre crop object with square crop | |||
| std::shared_ptr<TensorTransform> centre_out1(new vision::CenterCrop({30})); | |||
| EXPECT_NE(centre_out1, nullptr); | |||
| // Note: No need to check for output after calling API class constructor | |||
| // Create a Map operation on ds | |||
| ds = ds->Map({centre_out1}); | |||
| @@ -175,8 +163,8 @@ TEST_F(MindDataTestPipeline, TestCenterCrop) { | |||
| uint64_t i = 0; | |||
| while (row.size() != 0) { | |||
| i++; | |||
| // auto image = row["image"]; | |||
| // MS_LOG(INFO) << "Tensor image shape: " << image->shape(); | |||
| auto image = row["image"]; | |||
| MS_LOG(INFO) << "Tensor image shape: " << image.Shape(); | |||
| iter->GetNextRow(&row); | |||
| } | |||
| @@ -186,41 +174,6 @@ TEST_F(MindDataTestPipeline, TestCenterCrop) { | |||
| iter->Stop(); | |||
| } | |||
| TEST_F(MindDataTestPipeline, TestCenterCropFail) { | |||
| MS_LOG(INFO) << "Doing MindDataTestPipeline-TestCenterCrop with invalid parameters."; | |||
| // FIXME: For error tests, need to check for failure from CreateIterator execution | |||
| // center crop height value negative | |||
| std::shared_ptr<TensorTransform> center_crop1(new mindspore::dataset::vision::CenterCrop({-32, 32})); | |||
| EXPECT_NE(center_crop1, nullptr); | |||
| // center crop width value negative | |||
| std::shared_ptr<TensorTransform> center_crop2(new mindspore::dataset::vision::CenterCrop({32, -32})); | |||
| EXPECT_NE(center_crop2, nullptr); | |||
| // 0 value would result in nullptr | |||
| std::shared_ptr<TensorTransform> center_crop3(new mindspore::dataset::vision::CenterCrop({0, 32})); | |||
| EXPECT_NE(center_crop3, nullptr); | |||
| // center crop with 3 values | |||
| std::shared_ptr<TensorTransform> center_crop4(new mindspore::dataset::vision::CenterCrop({10, 20, 30})); | |||
| EXPECT_NE(center_crop4, nullptr); | |||
| } | |||
| TEST_F(MindDataTestPipeline, TestCropFail) { | |||
| MS_LOG(INFO) << "Doing MindDataTestPipeline-TestCrop with invalid parameters."; | |||
| // FIXME: For error tests, need to check for failure from CreateIterator execution | |||
| // wrong width | |||
| std::shared_ptr<TensorTransform> crop1(new mindspore::dataset::vision::Crop({0, 0}, {32, -32})); | |||
| EXPECT_NE(crop1, nullptr); | |||
| // wrong height | |||
| std::shared_ptr<TensorTransform> crop2(new mindspore::dataset::vision::Crop({0, 0}, {-32, -32})); | |||
| EXPECT_NE(crop2, nullptr); | |||
| // zero height | |||
| std::shared_ptr<TensorTransform> crop3(new mindspore::dataset::vision::Crop({0, 0}, {0, 32})); | |||
| EXPECT_NE(crop3, nullptr); | |||
| // negative coordinates | |||
| std::shared_ptr<TensorTransform> crop4(new mindspore::dataset::vision::Crop({-1, 0}, {32, 32})); | |||
| EXPECT_NE(crop4, nullptr); | |||
| } | |||
| TEST_F(MindDataTestPipeline, TestCutMixBatchSuccess1) { | |||
| MS_LOG(INFO) << "Doing MindDataTestPipeline-TestCutMixBatchSuccess1."; | |||
| // Testing CutMixBatch on a batch of CHW images | |||
| @@ -233,7 +186,7 @@ TEST_F(MindDataTestPipeline, TestCutMixBatchSuccess1) { | |||
| // Create objects for the tensor ops | |||
| std::shared_ptr<TensorTransform> hwc_to_chw = std::make_shared<vision::HWC2CHW>(); | |||
| EXPECT_NE(hwc_to_chw, nullptr); | |||
| // Note: No need to check for output after calling API class constructor | |||
| // Create a Map operation on ds | |||
| ds = ds->Map({hwc_to_chw}, {"image"}); | |||
| @@ -244,10 +197,9 @@ TEST_F(MindDataTestPipeline, TestCutMixBatchSuccess1) { | |||
| ds = ds->Batch(batch_size); | |||
| EXPECT_NE(ds, nullptr); | |||
| // Create objects for the tensor ops | |||
| std::shared_ptr<TensorTransform> one_hot_op = std::make_shared<transforms::OneHot>(number_of_classes); | |||
| EXPECT_NE(one_hot_op, nullptr); | |||
| // Note: No need to check for output after calling API class constructor | |||
| // Create a Map operation on ds | |||
| ds = ds->Map({one_hot_op}, {"label"}); | |||
| @@ -255,7 +207,7 @@ TEST_F(MindDataTestPipeline, TestCutMixBatchSuccess1) { | |||
| std::shared_ptr<TensorTransform> cutmix_batch_op = | |||
| std::make_shared<vision::CutMixBatch>(mindspore::dataset::ImageBatchFormat::kNCHW, 1.0, 1.0); | |||
| EXPECT_NE(cutmix_batch_op, nullptr); | |||
| // Note: No need to check for output after calling API class constructor | |||
| // Create a Map operation on ds | |||
| ds = ds->Map({cutmix_batch_op}, {"image", "label"}); | |||
| @@ -273,16 +225,15 @@ TEST_F(MindDataTestPipeline, TestCutMixBatchSuccess1) { | |||
| uint64_t i = 0; | |||
| while (row.size() != 0) { | |||
| i++; | |||
| // auto image = row["image"]; | |||
| // auto label = row["label"]; | |||
| // MS_LOG(INFO) << "Tensor image shape: " << image->shape(); | |||
| // MS_LOG(INFO) << "Label shape: " << label->shape(); | |||
| // EXPECT_EQ(image->shape().AsVector().size() == 4 && batch_size == image->shape()[0] && 3 == image->shape()[1] && | |||
| // 32 == image->shape()[2] && 32 == image->shape()[3], | |||
| // true); | |||
| // EXPECT_EQ(label->shape().AsVector().size() == 2 && batch_size == label->shape()[0] && | |||
| // number_of_classes == label->shape()[1], | |||
| // true); | |||
| auto image = row["image"]; | |||
| auto label = row["label"]; | |||
| MS_LOG(INFO) << "Tensor image shape: " << image.Shape(); | |||
| MS_LOG(INFO) << "Label shape: " << label.Shape(); | |||
| EXPECT_EQ(image.Shape().size() == 4 && batch_size == image.Shape()[0] && 3 == image.Shape()[1] && | |||
| 32 == image.Shape()[2] && 32 == image.Shape()[3], | |||
| true); | |||
| EXPECT_EQ(label.Shape().size() == 2 && batch_size == label.Shape()[0] && number_of_classes == label.Shape()[1], | |||
| true); | |||
| iter->GetNextRow(&row); | |||
| } | |||
| @@ -309,14 +260,15 @@ TEST_F(MindDataTestPipeline, TestCutMixBatchSuccess2) { | |||
| // Create objects for the tensor ops | |||
| std::shared_ptr<TensorTransform> one_hot_op = std::make_shared<transforms::OneHot>(number_of_classes); | |||
| EXPECT_NE(one_hot_op, nullptr); | |||
| // Note: No need to check for output after calling API class constructor | |||
| // Create a Map operation on ds | |||
| ds = ds->Map({one_hot_op}, {"label"}); | |||
| EXPECT_NE(ds, nullptr); | |||
| std::shared_ptr<TensorTransform> cutmix_batch_op = std::make_shared<vision::CutMixBatch>(mindspore::dataset::ImageBatchFormat::kNHWC); | |||
| EXPECT_NE(cutmix_batch_op, nullptr); | |||
| std::shared_ptr<TensorTransform> cutmix_batch_op = | |||
| std::make_shared<vision::CutMixBatch>(mindspore::dataset::ImageBatchFormat::kNHWC); | |||
| // Note: No need to check for output after calling API class constructor | |||
| // Create a Map operation on ds | |||
| ds = ds->Map({cutmix_batch_op}, {"image", "label"}); | |||
| @@ -334,16 +286,16 @@ TEST_F(MindDataTestPipeline, TestCutMixBatchSuccess2) { | |||
| uint64_t i = 0; | |||
| while (row.size() != 0) { | |||
| i++; | |||
| // auto image = row["image"]; | |||
| // auto label = row["label"]; | |||
| // MS_LOG(INFO) << "Tensor image shape: " << image->shape(); | |||
| // MS_LOG(INFO) << "Label shape: " << label->shape(); | |||
| // EXPECT_EQ(image->shape().AsVector().size() == 4 && batch_size == image->shape()[0] && 32 == image->shape()[1] && | |||
| // 32 == image->shape()[2] && 3 == image->shape()[3], | |||
| // true); | |||
| // EXPECT_EQ(label->shape().AsVector().size() == 2 && batch_size == label->shape()[0] && | |||
| // number_of_classes == label->shape()[1], | |||
| // true); | |||
| auto image = row["image"]; | |||
| auto label = row["label"]; | |||
| MS_LOG(INFO) << "Tensor image shape: " << image.Shape(); | |||
| MS_LOG(INFO) << "Label shape: " << label.Shape(); | |||
| EXPECT_EQ(image.Shape().size() == 4 && batch_size == image.Shape()[0] && 32 == image.Shape()[1] && | |||
| 32 == image.Shape()[2] && 3 == image.Shape()[3], | |||
| true); | |||
| EXPECT_EQ(label.Shape().size() == 2 && batch_size == label.Shape()[0] && number_of_classes == label.Shape()[1], | |||
| true); | |||
| iter->GetNextRow(&row); | |||
| } | |||
| @@ -368,7 +320,7 @@ TEST_F(MindDataTestPipeline, TestCutMixBatchFail1) { | |||
| // Create objects for the tensor ops | |||
| std::shared_ptr<TensorTransform> one_hot_op = std::make_shared<transforms::OneHot>(10); | |||
| EXPECT_NE(one_hot_op, nullptr); | |||
| // Note: No need to check for output after calling API class constructor | |||
| // Create a Map operation on ds | |||
| ds = ds->Map({one_hot_op}, {"label"}); | |||
| @@ -377,7 +329,7 @@ TEST_F(MindDataTestPipeline, TestCutMixBatchFail1) { | |||
| // Create CutMixBatch operation with invalid input, alpha<0 | |||
| std::shared_ptr<TensorTransform> cutmix_batch_op = | |||
| std::make_shared<vision::CutMixBatch>(mindspore::dataset::ImageBatchFormat::kNHWC, -1, 0.5); | |||
| EXPECT_NE(cutmix_batch_op, nullptr); | |||
| // Note: No need to check for output after calling API class constructor | |||
| // Create a Map operation on ds | |||
| ds = ds->Map({cutmix_batch_op}); | |||
| @@ -403,7 +355,7 @@ TEST_F(MindDataTestPipeline, TestCutMixBatchFail2) { | |||
| // Create objects for the tensor ops | |||
| std::shared_ptr<TensorTransform> one_hot_op = std::make_shared<transforms::OneHot>(10); | |||
| EXPECT_NE(one_hot_op, nullptr); | |||
| // Note: No need to check for output after calling API class constructor | |||
| // Create a Map operation on ds | |||
| ds = ds->Map({one_hot_op}, {"label"}); | |||
| @@ -412,7 +364,7 @@ TEST_F(MindDataTestPipeline, TestCutMixBatchFail2) { | |||
| // Create CutMixBatch operation with invalid input, prob<0 | |||
| std::shared_ptr<TensorTransform> cutmix_batch_op = | |||
| std::make_shared<vision::CutMixBatch>(mindspore::dataset::ImageBatchFormat::kNHWC, 1, -0.5); | |||
| EXPECT_NE(cutmix_batch_op, nullptr); | |||
| // Note: No need to check for output after calling API class constructor | |||
| // Create a Map operation on ds | |||
| ds = ds->Map({cutmix_batch_op}); | |||
| @@ -438,7 +390,7 @@ TEST_F(MindDataTestPipeline, TestCutMixBatchFail3) { | |||
| // Create objects for the tensor ops | |||
| std::shared_ptr<TensorTransform> one_hot_op = std::make_shared<transforms::OneHot>(10); | |||
| EXPECT_NE(one_hot_op, nullptr); | |||
| // Note: No need to check for output after calling API class constructor | |||
| // Create a Map operation on ds | |||
| ds = ds->Map({one_hot_op}, {"label"}); | |||
| @@ -447,7 +399,7 @@ TEST_F(MindDataTestPipeline, TestCutMixBatchFail3) { | |||
| // Create CutMixBatch operation with invalid input, alpha=0 (boundary case) | |||
| std::shared_ptr<TensorTransform> cutmix_batch_op = | |||
| std::make_shared<vision::CutMixBatch>(mindspore::dataset::ImageBatchFormat::kNHWC, 0.0, 0.5); | |||
| EXPECT_NE(cutmix_batch_op, nullptr); | |||
| // Note: No need to check for output after calling API class constructor | |||
| // Create a Map operation on ds | |||
| ds = ds->Map({cutmix_batch_op}); | |||
| @@ -472,7 +424,7 @@ TEST_F(MindDataTestPipeline, TestCutMixBatchFail4) { | |||
| // Create objects for the tensor ops | |||
| std::shared_ptr<TensorTransform> one_hot_op = std::make_shared<transforms::OneHot>(10); | |||
| EXPECT_NE(one_hot_op, nullptr); | |||
| // Note: No need to check for output after calling API class constructor | |||
| // Create a Map operation on ds | |||
| ds = ds->Map({one_hot_op}, {"label"}); | |||
| @@ -481,7 +433,7 @@ TEST_F(MindDataTestPipeline, TestCutMixBatchFail4) { | |||
| // Create CutMixBatch operation with invalid input, prob>1 | |||
| std::shared_ptr<TensorTransform> cutmix_batch_op = | |||
| std::make_shared<vision::CutMixBatch>(mindspore::dataset::ImageBatchFormat::kNHWC, 1, 1.5); | |||
| EXPECT_NE(cutmix_batch_op, nullptr); | |||
| // Note: No need to check for output after calling API class constructor | |||
| // Create a Map operation on ds | |||
| ds = ds->Map({cutmix_batch_op}); | |||
| @@ -492,30 +444,6 @@ TEST_F(MindDataTestPipeline, TestCutMixBatchFail4) { | |||
| EXPECT_EQ(iter, nullptr); | |||
| } | |||
| TEST_F(MindDataTestPipeline, TestCutOutFail1) { | |||
| MS_LOG(INFO) << "Doing MindDataTestPipeline-TestCutOutFail1 with invalid parameters."; | |||
| // FIXME: For error tests, need to check for failure from CreateIterator execution | |||
| // Create object for the tensor op | |||
| // Invalid negative length | |||
| std::shared_ptr<TensorTransform> cutout_op = std::make_shared<vision::CutOut>(-10); | |||
| EXPECT_NE(cutout_op, nullptr); | |||
| // Invalid negative number of patches | |||
| cutout_op = std::make_shared<vision::CutOut>(10, -1); | |||
| EXPECT_NE(cutout_op, nullptr); | |||
| } | |||
| TEST_F(MindDataTestPipeline, TestCutOutFail2) { | |||
| MS_LOG(INFO) << "Doing MindDataTestPipeline-TestCutOutFail2 with invalid params, boundary cases."; | |||
| // FIXME: For error tests, need to check for failure from CreateIterator execution | |||
| // Create object for the tensor op | |||
| // Invalid zero length | |||
| std::shared_ptr<TensorTransform> cutout_op = std::make_shared<vision::CutOut>(0); | |||
| EXPECT_NE(cutout_op, nullptr); | |||
| // Invalid zero number of patches | |||
| cutout_op = std::make_shared<vision::CutOut>(10, 0); | |||
| EXPECT_NE(cutout_op, nullptr); | |||
| } | |||
| TEST_F(MindDataTestPipeline, TestCutOut) { | |||
| MS_LOG(INFO) << "Doing MindDataTestPipeline-TestCutOut."; | |||
| @@ -531,10 +459,8 @@ TEST_F(MindDataTestPipeline, TestCutOut) { | |||
| // Create objects for the tensor ops | |||
| std::shared_ptr<TensorTransform> cut_out1 = std::make_shared<vision::CutOut>(30, 5); | |||
| EXPECT_NE(cut_out1, nullptr); | |||
| std::shared_ptr<TensorTransform> cut_out2 = std::make_shared<vision::CutOut>(30); | |||
| EXPECT_NE(cut_out2, nullptr); | |||
| // Note: No need to check for output after calling API class constructor | |||
| // Create a Map operation on ds | |||
| ds = ds->Map({cut_out1, cut_out2}); | |||
| @@ -557,8 +483,8 @@ TEST_F(MindDataTestPipeline, TestCutOut) { | |||
| uint64_t i = 0; | |||
| while (row.size() != 0) { | |||
| i++; | |||
| // auto image = row["image"]; | |||
| // MS_LOG(INFO) << "Tensor image shape: " << image->shape(); | |||
| auto image = row["image"]; | |||
| MS_LOG(INFO) << "Tensor image shape: " << image.Shape(); | |||
| iter->GetNextRow(&row); | |||
| } | |||
| @@ -583,6 +509,7 @@ TEST_F(MindDataTestPipeline, TestDecode) { | |||
| // Create Decode object | |||
| vision::Decode decode = vision::Decode(true); | |||
| // Note: No need to check for output after calling API class constructor | |||
| // Create a Map operation on ds | |||
| ds = ds->Map({decode}); | |||
| @@ -605,8 +532,8 @@ TEST_F(MindDataTestPipeline, TestDecode) { | |||
| uint64_t i = 0; | |||
| while (row.size() != 0) { | |||
| i++; | |||
| // auto image = row["image"]; | |||
| // MS_LOG(INFO) << "Tensor image shape: " << image->shape(); | |||
| auto image = row["image"]; | |||
| MS_LOG(INFO) << "Tensor image shape: " << image.Shape(); | |||
| iter->GetNextRow(&row); | |||
| } | |||
| EXPECT_EQ(i, 20); | |||
| @@ -630,7 +557,7 @@ TEST_F(MindDataTestPipeline, TestHwcToChw) { | |||
| // Create objects for the tensor ops | |||
| std::shared_ptr<TensorTransform> channel_swap = std::make_shared<vision::HWC2CHW>(); | |||
| EXPECT_NE(channel_swap, nullptr); | |||
| // Note: No need to check for output after calling API class constructor | |||
| // Create a Map operation on ds | |||
| ds = ds->Map({channel_swap}); | |||
| @@ -653,12 +580,12 @@ TEST_F(MindDataTestPipeline, TestHwcToChw) { | |||
| uint64_t i = 0; | |||
| while (row.size() != 0) { | |||
| i++; | |||
| // auto image = row["image"]; | |||
| // MS_LOG(INFO) << "Tensor image shape: " << image->shape(); | |||
| // check if the image is in NCHW | |||
| // EXPECT_EQ(batch_size == image->shape()[0] && 3 == image->shape()[1] && 2268 == image->shape()[2] && | |||
| // 4032 == image->shape()[3], | |||
| // true); | |||
| auto image = row["image"]; | |||
| MS_LOG(INFO) << "Tensor image shape: " << image.Shape(); | |||
| // Check if the image is in NCHW | |||
| EXPECT_EQ( | |||
| batch_size == image.Shape()[0] && 3 == image.Shape()[1] && 2268 == image.Shape()[2] && 4032 == image.Shape()[3], | |||
| true); | |||
| iter->GetNextRow(&row); | |||
| } | |||
| EXPECT_EQ(i, 20); | |||
| @@ -677,7 +604,7 @@ TEST_F(MindDataTestPipeline, TestInvert) { | |||
| // Create objects for the tensor ops | |||
| std::shared_ptr<TensorTransform> invert_op = std::make_shared<vision::Invert>(); | |||
| EXPECT_NE(invert_op, nullptr); | |||
| // Note: No need to check for output after calling API class constructor | |||
| // Create a Map operation on ds | |||
| ds = ds->Map({invert_op}); | |||
| @@ -695,8 +622,8 @@ TEST_F(MindDataTestPipeline, TestInvert) { | |||
| uint64_t i = 0; | |||
| while (row.size() != 0) { | |||
| i++; | |||
| // auto image = row["image"]; | |||
| // MS_LOG(INFO) << "Tensor image shape: " << image->shape(); | |||
| auto image = row["image"]; | |||
| MS_LOG(INFO) << "Tensor image shape: " << image.Shape(); | |||
| iter->GetNextRow(&row); | |||
| } | |||
| EXPECT_EQ(i, 20); | |||
| @@ -707,7 +634,7 @@ TEST_F(MindDataTestPipeline, TestInvert) { | |||
| TEST_F(MindDataTestPipeline, TestMixUpBatchFail1) { | |||
| MS_LOG(INFO) << "Doing MindDataTestPipeline-TestMixUpBatchFail1 with negative alpha parameter."; | |||
| // FIXME: For error tests, need to check for failure from CreateIterator execution | |||
| // Create a Cifar10 Dataset | |||
| std::string folder_path = datasets_root_path_ + "/testCifar10Data/"; | |||
| std::shared_ptr<Dataset> ds = Cifar10(folder_path, "all", std::make_shared<RandomSampler>(false, 10)); | |||
| @@ -720,7 +647,7 @@ TEST_F(MindDataTestPipeline, TestMixUpBatchFail1) { | |||
| // Create objects for the tensor ops | |||
| std::shared_ptr<TensorTransform> one_hot_op = std::make_shared<transforms::OneHot>(10); | |||
| EXPECT_NE(one_hot_op, nullptr); | |||
| // Note: No need to check for output after calling API class constructor | |||
| // Create a Map operation on ds | |||
| ds = ds->Map({one_hot_op}, {"label"}); | |||
| @@ -728,7 +655,7 @@ TEST_F(MindDataTestPipeline, TestMixUpBatchFail1) { | |||
| // Create MixUpBatch operation with invalid input, alpha<0 | |||
| std::shared_ptr<TensorTransform> mixup_batch_op = std::make_shared<vision::MixUpBatch>(-1); | |||
| EXPECT_NE(mixup_batch_op, nullptr); | |||
| // Note: No need to check for output after calling API class constructor | |||
| // Create a Map operation on ds | |||
| ds = ds->Map({mixup_batch_op}); | |||
| @@ -741,7 +668,7 @@ TEST_F(MindDataTestPipeline, TestMixUpBatchFail1) { | |||
| TEST_F(MindDataTestPipeline, TestMixUpBatchFail2) { | |||
| MS_LOG(INFO) << "Doing MindDataTestPipeline-TestMixUpBatchFail2 with zero alpha parameter."; | |||
| // FIXME: For error tests, need to check for failure from CreateIterator execution | |||
| // Create a Cifar10 Dataset | |||
| std::string folder_path = datasets_root_path_ + "/testCifar10Data/"; | |||
| std::shared_ptr<Dataset> ds = Cifar10(folder_path, "all", std::make_shared<RandomSampler>(false, 10)); | |||
| @@ -754,7 +681,7 @@ TEST_F(MindDataTestPipeline, TestMixUpBatchFail2) { | |||
| // Create objects for the tensor ops | |||
| std::shared_ptr<TensorTransform> one_hot_op = std::make_shared<transforms::OneHot>(10); | |||
| EXPECT_NE(one_hot_op, nullptr); | |||
| // Note: No need to check for output after calling API class constructor | |||
| // Create a Map operation on ds | |||
| ds = ds->Map({one_hot_op}, {"label"}); | |||
| @@ -762,7 +689,7 @@ TEST_F(MindDataTestPipeline, TestMixUpBatchFail2) { | |||
| // Create MixUpBatch operation with invalid input, alpha<0 (boundary case) | |||
| std::shared_ptr<TensorTransform> mixup_batch_op = std::make_shared<vision::MixUpBatch>(0.0); | |||
| EXPECT_NE(mixup_batch_op, nullptr); | |||
| // Note: No need to check for output after calling API class constructor | |||
| // Create a Map operation on ds | |||
| ds = ds->Map({mixup_batch_op}); | |||
| @@ -788,14 +715,14 @@ TEST_F(MindDataTestPipeline, TestMixUpBatchSuccess1) { | |||
| // Create objects for the tensor ops | |||
| std::shared_ptr<TensorTransform> one_hot_op = std::make_shared<transforms::OneHot>(10); | |||
| EXPECT_NE(one_hot_op, nullptr); | |||
| // Note: No need to check for output after calling API class constructor | |||
| // Create a Map operation on ds | |||
| ds = ds->Map({one_hot_op}, {"label"}); | |||
| EXPECT_NE(ds, nullptr); | |||
| std::shared_ptr<TensorTransform> mixup_batch_op = std::make_shared<vision::MixUpBatch>(2.0); | |||
| EXPECT_NE(mixup_batch_op, nullptr); | |||
| // Note: No need to check for output after calling API class constructor | |||
| // Create a Map operation on ds | |||
| ds = ds->Map({mixup_batch_op}, {"image", "label"}); | |||
| @@ -813,8 +740,8 @@ TEST_F(MindDataTestPipeline, TestMixUpBatchSuccess1) { | |||
| uint64_t i = 0; | |||
| while (row.size() != 0) { | |||
| i++; | |||
| // auto image = row["image"]; | |||
| // MS_LOG(INFO) << "Tensor image shape: " << image->shape(); | |||
| auto image = row["image"]; | |||
| MS_LOG(INFO) << "Tensor image shape: " << image.Shape(); | |||
| iter->GetNextRow(&row); | |||
| } | |||
| @@ -839,14 +766,14 @@ TEST_F(MindDataTestPipeline, TestMixUpBatchSuccess2) { | |||
| // Create objects for the tensor ops | |||
| std::shared_ptr<TensorTransform> one_hot_op = std::make_shared<transforms::OneHot>(10); | |||
| EXPECT_NE(one_hot_op, nullptr); | |||
| // Note: No need to check for output after calling API class constructor | |||
| // Create a Map operation on ds | |||
| ds = ds->Map({one_hot_op}, {"label"}); | |||
| EXPECT_NE(ds, nullptr); | |||
| std::shared_ptr<TensorTransform> mixup_batch_op = std::make_shared<vision::MixUpBatch>(); | |||
| EXPECT_NE(mixup_batch_op, nullptr); | |||
| // Note: No need to check for output after calling API class constructor | |||
| // Create a Map operation on ds | |||
| ds = ds->Map({mixup_batch_op}, {"image", "label"}); | |||
| @@ -864,8 +791,8 @@ TEST_F(MindDataTestPipeline, TestMixUpBatchSuccess2) { | |||
| uint64_t i = 0; | |||
| while (row.size() != 0) { | |||
| i++; | |||
| // auto image = row["image"]; | |||
| // MS_LOG(INFO) << "Tensor image shape: " << image->shape(); | |||
| auto image = row["image"]; | |||
| MS_LOG(INFO) << "Tensor image shape: " << image.Shape(); | |||
| iter->GetNextRow(&row); | |||
| } | |||
| @@ -890,7 +817,7 @@ TEST_F(MindDataTestPipeline, TestNormalize) { | |||
| // Create objects for the tensor ops | |||
| std::shared_ptr<TensorTransform> normalize(new vision::Normalize({121.0, 115.0, 0.0}, {70.0, 68.0, 71.0})); | |||
| EXPECT_NE(normalize, nullptr); | |||
| // Note: No need to check for output after calling API class constructor | |||
| // Create a Map operation on ds | |||
| ds = ds->Map({normalize}); | |||
| @@ -913,8 +840,8 @@ TEST_F(MindDataTestPipeline, TestNormalize) { | |||
| uint64_t i = 0; | |||
| while (row.size() != 0) { | |||
| i++; | |||
| // auto image = row["image"]; | |||
| // MS_LOG(INFO) << "Tensor image shape: " << image->shape(); | |||
| auto image = row["image"]; | |||
| MS_LOG(INFO) << "Tensor image shape: " << image.Shape(); | |||
| iter->GetNextRow(&row); | |||
| } | |||
| @@ -924,35 +851,6 @@ TEST_F(MindDataTestPipeline, TestNormalize) { | |||
| iter->Stop(); | |||
| } | |||
| TEST_F(MindDataTestPipeline, TestNormalizeFail) { | |||
| MS_LOG(INFO) << "Doing MindDataTestPipeline-TestNormalizeFail with invalid parameters."; | |||
| // FIXME: For error tests, need to check for failure from CreateIterator execution | |||
| // std value at 0.0 | |||
| std::shared_ptr<TensorTransform> normalize1( | |||
| new mindspore::dataset::vision::Normalize({121.0, 115.0, 100.0}, {0.0, 68.0, 71.0})); | |||
| EXPECT_NE(normalize1, nullptr); | |||
| // mean out of range | |||
| std::shared_ptr<TensorTransform> normalize2( | |||
| new mindspore::dataset::vision::Normalize({121.0, 0.0, 100.0}, {256.0, 68.0, 71.0})); | |||
| EXPECT_NE(normalize2, nullptr); | |||
| // mean out of range | |||
| std::shared_ptr<TensorTransform> normalize3( | |||
| new mindspore::dataset::vision::Normalize({256.0, 0.0, 100.0}, {70.0, 68.0, 71.0})); | |||
| EXPECT_NE(normalize3, nullptr); | |||
| // mean out of range | |||
| std::shared_ptr<TensorTransform> normalize4( | |||
| new mindspore::dataset::vision::Normalize({-1.0, 0.0, 100.0}, {70.0, 68.0, 71.0})); | |||
| EXPECT_NE(normalize4, nullptr); | |||
| // normalize with 2 values (not 3 values) for mean | |||
| std::shared_ptr<TensorTransform> normalize5( | |||
| new mindspore::dataset::vision::Normalize({121.0, 115.0}, {70.0, 68.0, 71.0})); | |||
| EXPECT_NE(normalize5, nullptr); | |||
| // normalize with 2 values (not 3 values) for standard deviation | |||
| std::shared_ptr<TensorTransform> normalize6( | |||
| new mindspore::dataset::vision::Normalize({121.0, 115.0, 100.0}, {68.0, 71.0})); | |||
| EXPECT_NE(normalize6, nullptr); | |||
| } | |||
| TEST_F(MindDataTestPipeline, TestNormalizePad) { | |||
| MS_LOG(INFO) << "Doing MindDataTestPipeline-TestNormalizePad."; | |||
| @@ -969,7 +867,7 @@ TEST_F(MindDataTestPipeline, TestNormalizePad) { | |||
| // Create objects for the tensor ops | |||
| std::shared_ptr<TensorTransform> normalizepad( | |||
| new vision::NormalizePad({121.0, 115.0, 100.0}, {70.0, 68.0, 71.0}, "float32")); | |||
| EXPECT_NE(normalizepad, nullptr); | |||
| // Note: No need to check for output after calling API class constructor | |||
| // Create a Map operation on ds | |||
| ds = ds->Map({normalizepad}); | |||
| @@ -987,9 +885,10 @@ TEST_F(MindDataTestPipeline, TestNormalizePad) { | |||
| uint64_t i = 0; | |||
| while (row.size() != 0) { | |||
| i++; | |||
| // auto image = row["image"]; | |||
| // EXPECT_EQ(image->shape()[2], 4); | |||
| // MS_LOG(INFO) << "Tensor image shape: " << image->shape(); | |||
| auto image = row["image"]; | |||
| MS_LOG(INFO) << "Tensor image shape: " << image.Shape(); | |||
| EXPECT_EQ(image.Shape()[2], 4); | |||
| iter->GetNextRow(&row); | |||
| } | |||
| @@ -999,27 +898,6 @@ TEST_F(MindDataTestPipeline, TestNormalizePad) { | |||
| iter->Stop(); | |||
| } | |||
| TEST_F(MindDataTestPipeline, TestNormalizePadFail) { | |||
| MS_LOG(INFO) << "Doing MindDataTestPipeline-TestNormalizePadFail with invalid parameters."; | |||
| // FIXME: For error tests, need to check for failure from CreateIterator execution | |||
| // std value at 0.0 | |||
| std::shared_ptr<TensorTransform> normalizepad1( | |||
| new mindspore::dataset::vision::NormalizePad({121.0, 115.0, 100.0}, {0.0, 68.0, 71.0})); | |||
| EXPECT_NE(normalizepad1, nullptr); | |||
| // normalizepad with 2 values (not 3 values) for mean | |||
| std::shared_ptr<TensorTransform> normalizepad2( | |||
| new mindspore::dataset::vision::NormalizePad({121.0, 115.0}, {70.0, 68.0, 71.0})); | |||
| EXPECT_NE(normalizepad2, nullptr); | |||
| // normalizepad with 2 values (not 3 values) for standard deviation | |||
| std::shared_ptr<TensorTransform> normalizepad3( | |||
| new mindspore::dataset::vision::NormalizePad({121.0, 115.0, 100.0}, {68.0, 71.0})); | |||
| EXPECT_NE(normalizepad3, nullptr); | |||
| // normalizepad with invalid dtype | |||
| std::shared_ptr<TensorTransform> normalizepad4( | |||
| new mindspore::dataset::vision::NormalizePad({121.0, 115.0, 100.0}, {68.0, 71.0, 71.0}, "123")); | |||
| EXPECT_NE(normalizepad4, nullptr); | |||
| } | |||
| TEST_F(MindDataTestPipeline, TestPad) { | |||
| MS_LOG(INFO) << "Doing MindDataTestPipeline-TestPad."; | |||
| @@ -1035,13 +913,9 @@ TEST_F(MindDataTestPipeline, TestPad) { | |||
| // Create objects for the tensor ops | |||
| std::shared_ptr<TensorTransform> pad_op1(new vision::Pad({1, 2, 3, 4}, {0}, BorderType::kSymmetric)); | |||
| EXPECT_NE(pad_op1, nullptr); | |||
| std::shared_ptr<TensorTransform> pad_op2(new vision::Pad({1}, {1, 1, 1}, BorderType::kEdge)); | |||
| EXPECT_NE(pad_op2, nullptr); | |||
| std::shared_ptr<TensorTransform> pad_op3(new vision::Pad({1, 4})); | |||
| EXPECT_NE(pad_op3, nullptr); | |||
| // Note: No need to check for output after calling API class constructor | |||
| // Create a Map operation on ds | |||
| ds = ds->Map({pad_op1, pad_op2, pad_op3}); | |||
| @@ -1064,8 +938,8 @@ TEST_F(MindDataTestPipeline, TestPad) { | |||
| uint64_t i = 0; | |||
| while (row.size() != 0) { | |||
| i++; | |||
| // auto image = row["image"]; | |||
| // MS_LOG(INFO) << "Tensor image shape: " << image->shape(); | |||
| auto image = row["image"]; | |||
| MS_LOG(INFO) << "Tensor image shape: " << image.Shape(); | |||
| iter->GetNextRow(&row); | |||
| } | |||
| @@ -30,7 +30,8 @@ TEST_F(MindDataTestPipeline, TestBoundingBoxAugmentSuccess1Shr) { | |||
| MS_LOG(INFO) << "Doing MindDataTestPipeline-TestBoundingBoxAugmentSuccess1Shr."; | |||
| // Create an VOC Dataset | |||
| std::string folder_path = datasets_root_path_ + "/testVOC2012_2"; | |||
| std::shared_ptr<Dataset> ds = VOC(folder_path, "Detection", "train", {}, true, std::make_shared<SequentialSampler>(0, 3)); | |||
| std::shared_ptr<Dataset> ds = | |||
| VOC(folder_path, "Detection", "train", {}, true, std::make_shared<SequentialSampler>(0, 3)); | |||
| EXPECT_NE(ds, nullptr); | |||
| // Create objects for the tensor ops | |||
| @@ -54,8 +55,8 @@ TEST_F(MindDataTestPipeline, TestBoundingBoxAugmentSuccess1Shr) { | |||
| uint64_t i = 0; | |||
| while (row.size() != 0) { | |||
| i++; | |||
| // auto image = row["image"]; | |||
| // MS_LOG(INFO) << "Tensor image shape: " << image->shape(); | |||
| auto image = row["image"]; | |||
| MS_LOG(INFO) << "Tensor image shape: " << image.Shape(); | |||
| iter->GetNextRow(&row); | |||
| } | |||
| @@ -68,11 +69,13 @@ TEST_F(MindDataTestPipeline, TestBoundingBoxAugmentSuccess2Auto) { | |||
| MS_LOG(INFO) << "Doing MindDataTestPipeline-TestBoundingBoxAugmentSuccess2Auto."; | |||
| // Create an VOC Dataset | |||
| std::string folder_path = datasets_root_path_ + "/testVOC2012_2"; | |||
| std::shared_ptr<Dataset> ds = VOC(folder_path, "Detection", "train", {}, true, std::make_shared<SequentialSampler>(0, 3)); | |||
| std::shared_ptr<Dataset> ds = | |||
| VOC(folder_path, "Detection", "train", {}, true, std::make_shared<SequentialSampler>(0, 3)); | |||
| EXPECT_NE(ds, nullptr); | |||
| // Create objects for the tensor ops | |||
| // Use auto for raw pointers | |||
| // Note that with auto and new, we have to explicitly delete the allocated object as shown below. | |||
| auto random_rotation_op(new vision::RandomRotation({90.0})); | |||
| auto bound_box_augment_op(new vision::BoundingBoxAugment({random_rotation_op}, 1.0)); | |||
| @@ -92,21 +95,26 @@ TEST_F(MindDataTestPipeline, TestBoundingBoxAugmentSuccess2Auto) { | |||
| uint64_t i = 0; | |||
| while (row.size() != 0) { | |||
| i++; | |||
| // auto image = row["image"]; | |||
| // MS_LOG(INFO) << "Tensor image shape: " << image->shape(); | |||
| auto image = row["image"]; | |||
| MS_LOG(INFO) << "Tensor image shape: " << image.Shape(); | |||
| iter->GetNextRow(&row); | |||
| } | |||
| EXPECT_EQ(i, 3); | |||
| // Manually terminate the pipeline | |||
| iter->Stop(); | |||
| // Delete allocated objects with raw pointers | |||
| delete random_rotation_op; | |||
| delete bound_box_augment_op; | |||
| } | |||
| TEST_F(MindDataTestPipeline, TestBoundingBoxAugmentSuccess3Obj) { | |||
| MS_LOG(INFO) << "Doing MindDataTestPipeline-TestBoundingBoxAugmentSuccess3Obj."; | |||
| // Create an VOC Dataset | |||
| std::string folder_path = datasets_root_path_ + "/testVOC2012_2"; | |||
| std::shared_ptr<Dataset> ds = VOC(folder_path, "Detection", "train", {}, true, std::make_shared<SequentialSampler>(0, 3)); | |||
| std::shared_ptr<Dataset> ds = | |||
| VOC(folder_path, "Detection", "train", {}, true, std::make_shared<SequentialSampler>(0, 3)); | |||
| EXPECT_NE(ds, nullptr); | |||
| // Create objects for the tensor ops | |||
| @@ -130,8 +138,8 @@ TEST_F(MindDataTestPipeline, TestBoundingBoxAugmentSuccess3Obj) { | |||
| uint64_t i = 0; | |||
| while (row.size() != 0) { | |||
| i++; | |||
| // auto image = row["image"]; | |||
| // MS_LOG(INFO) << "Tensor image shape: " << image->shape(); | |||
| auto image = row["image"]; | |||
| MS_LOG(INFO) << "Tensor image shape: " << image.Shape(); | |||
| iter->GetNextRow(&row); | |||
| } | |||
| @@ -145,7 +153,8 @@ TEST_F(MindDataTestPipeline, TestBoundingBoxAugmentFail1) { | |||
| // Create an VOC Dataset | |||
| std::string folder_path = datasets_root_path_ + "/testVOC2012_2"; | |||
| std::shared_ptr<Dataset> ds = VOC(folder_path, "Detection", "train", {}, true, std::make_shared<SequentialSampler>(0, 3)); | |||
| std::shared_ptr<Dataset> ds = | |||
| VOC(folder_path, "Detection", "train", {}, true, std::make_shared<SequentialSampler>(0, 3)); | |||
| EXPECT_NE(ds, nullptr); | |||
| // Create objects for the tensor ops | |||
| @@ -169,7 +178,8 @@ TEST_F(MindDataTestPipeline, TestBoundingBoxAugmentFail2) { | |||
| // Create an VOC Dataset | |||
| std::string folder_path = datasets_root_path_ + "/testVOC2012_2"; | |||
| std::shared_ptr<Dataset> ds = VOC(folder_path, "Detection", "train", {}, true, std::make_shared<SequentialSampler>(0, 3)); | |||
| std::shared_ptr<Dataset> ds = | |||
| VOC(folder_path, "Detection", "train", {}, true, std::make_shared<SequentialSampler>(0, 3)); | |||
| EXPECT_NE(ds, nullptr); | |||
| // Create objects for the tensor ops | |||
| @@ -193,7 +203,8 @@ TEST_F(MindDataTestPipeline, TestBoundingBoxAugmentFail3) { | |||
| // Create an VOC Dataset | |||
| std::string folder_path = datasets_root_path_ + "/testVOC2012_2"; | |||
| std::shared_ptr<Dataset> ds = VOC(folder_path, "Detection", "train", {}, true, std::make_shared<SequentialSampler>(0, 3)); | |||
| std::shared_ptr<Dataset> ds = | |||
| VOC(folder_path, "Detection", "train", {}, true, std::make_shared<SequentialSampler>(0, 3)); | |||
| EXPECT_NE(ds, nullptr); | |||
| // Create BoundingBoxAugment op with invalid nullptr transform | |||
| @@ -214,7 +225,8 @@ TEST_F(MindDataTestPipeline, TestBoundingBoxAugmentFail4) { | |||
| // Create an VOC Dataset | |||
| std::string folder_path = datasets_root_path_ + "/testVOC2012_2"; | |||
| std::shared_ptr<Dataset> ds = VOC(folder_path, "Detection", "train", {}, true, std::make_shared<SequentialSampler>(0, 3)); | |||
| std::shared_ptr<Dataset> ds = | |||
| VOC(folder_path, "Detection", "train", {}, true, std::make_shared<SequentialSampler>(0, 3)); | |||
| EXPECT_NE(ds, nullptr); | |||
| // Create objects for the tensor ops | |||
| @@ -46,11 +46,11 @@ TEST_F(MindDataTestPipeline, TestRescaleSucess1) { | |||
| // Create objects for the tensor ops | |||
| std::shared_ptr<TensorTransform> rescale(new mindspore::dataset::vision::Rescale(1.0, 0.0)); | |||
| EXPECT_NE(rescale, nullptr); | |||
| // Note: No need to check for output after calling API class constructor | |||
| // Convert to the same type | |||
| std::shared_ptr<TensorTransform> type_cast(new transforms::TypeCast("uint8")); | |||
| EXPECT_NE(type_cast, nullptr); | |||
| // Note: No need to check for output after calling API class constructor | |||
| ds = ds->Map({rescale, type_cast}, {"image"}); | |||
| EXPECT_NE(ds, nullptr); | |||
| @@ -81,7 +81,7 @@ TEST_F(MindDataTestPipeline, TestRescaleSucess2) { | |||
| // Create objects for the tensor ops | |||
| std::shared_ptr<TensorTransform> rescale(new mindspore::dataset::vision::Rescale(1.0 / 255, 1.0)); | |||
| EXPECT_NE(rescale, nullptr); | |||
| // Note: No need to check for output after calling API class constructor | |||
| ds = ds->Map({rescale}, {"image"}); | |||
| EXPECT_NE(ds, nullptr); | |||
| @@ -98,8 +98,8 @@ TEST_F(MindDataTestPipeline, TestRescaleSucess2) { | |||
| uint64_t i = 0; | |||
| while (row.size() != 0) { | |||
| i++; | |||
| // auto image = row["image"]; | |||
| // MS_LOG(INFO) << "Tensor image shape: " << image->shape(); | |||
| auto image = row["image"]; | |||
| MS_LOG(INFO) << "Tensor image shape: " << image.Shape(); | |||
| iter->GetNextRow(&row); | |||
| } | |||
| @@ -109,14 +109,6 @@ TEST_F(MindDataTestPipeline, TestRescaleSucess2) { | |||
| iter->Stop(); | |||
| } | |||
| TEST_F(MindDataTestPipeline, TestRescaleFail) { | |||
| MS_LOG(INFO) << "Doing MindDataTestPipeline-TestRescaleFail with invalid params."; | |||
| // FIXME: For error tests, need to check for failure from CreateIterator execution | |||
| // incorrect negative rescale parameter | |||
| std::shared_ptr<TensorTransform> rescale(new mindspore::dataset::vision::Rescale(-1.0, 0.0)); | |||
| EXPECT_NE(rescale, nullptr); | |||
| } | |||
| TEST_F(MindDataTestPipeline, TestResize1) { | |||
| MS_LOG(INFO) << "Doing MindDataTestPipeline-TestResize1 with single integer input."; | |||
| // Create an ImageFolder Dataset | |||
| @@ -131,7 +123,7 @@ TEST_F(MindDataTestPipeline, TestResize1) { | |||
| // Create resize object with single integer input | |||
| std::shared_ptr<TensorTransform> resize_op(new vision::Resize({30})); | |||
| EXPECT_NE(resize_op, nullptr); | |||
| // Note: No need to check for output after calling API class constructor | |||
| // Create a Map operation on ds | |||
| ds = ds->Map({resize_op}); | |||
| @@ -154,8 +146,8 @@ TEST_F(MindDataTestPipeline, TestResize1) { | |||
| uint64_t i = 0; | |||
| while (row.size() != 0) { | |||
| i++; | |||
| // auto image = row["image"]; | |||
| // MS_LOG(INFO) << "Tensor image shape: " << image->shape(); | |||
| auto image = row["image"]; | |||
| MS_LOG(INFO) << "Tensor image shape: " << image.Shape(); | |||
| iter->GetNextRow(&row); | |||
| } | |||
| @@ -165,33 +157,18 @@ TEST_F(MindDataTestPipeline, TestResize1) { | |||
| iter->Stop(); | |||
| } | |||
| TEST_F(MindDataTestPipeline, TestResizeFail) { | |||
| MS_LOG(INFO) << "Doing MindDataTestPipeline-TestResize with invalid parameters."; | |||
| // FIXME: For error tests, need to check for failure from CreateIterator execution | |||
| // negative resize value | |||
| std::shared_ptr<TensorTransform> resize_op1(new mindspore::dataset::vision::Resize({30, -30})); | |||
| EXPECT_NE(resize_op1, nullptr); | |||
| // zero resize value | |||
| std::shared_ptr<TensorTransform> resize_op2(new mindspore::dataset::vision::Resize({0, 30})); | |||
| EXPECT_NE(resize_op2, nullptr); | |||
| // resize with 3 values | |||
| std::shared_ptr<TensorTransform> resize_op3(new mindspore::dataset::vision::Resize({30, 20, 10})); | |||
| EXPECT_NE(resize_op3, nullptr); | |||
| } | |||
| TEST_F(MindDataTestPipeline, TestResizeWithBBoxSuccess) { | |||
| MS_LOG(INFO) << "Doing MindDataTestPipeline-TestResizeWithBBoxSuccess."; | |||
| // Create an VOC Dataset | |||
| std::string folder_path = datasets_root_path_ + "/testVOC2012_2"; | |||
| std::shared_ptr<Dataset> ds = VOC(folder_path, "Detection", "train", {}, true, std::make_shared<SequentialSampler>(0, 3)); | |||
| std::shared_ptr<Dataset> ds = | |||
| VOC(folder_path, "Detection", "train", {}, true, std::make_shared<SequentialSampler>(0, 3)); | |||
| EXPECT_NE(ds, nullptr); | |||
| // Create objects for the tensor ops | |||
| std::shared_ptr<TensorTransform> resize_with_bbox_op(new vision::ResizeWithBBox({30})); | |||
| EXPECT_NE(resize_with_bbox_op, nullptr); | |||
| std::shared_ptr<TensorTransform> resize_with_bbox_op1(new vision::ResizeWithBBox({30, 30})); | |||
| EXPECT_NE(resize_with_bbox_op1, nullptr); | |||
| // Note: No need to check for output after calling API class constructor | |||
| // Create a Map operation on ds | |||
| ds = ds->Map({resize_with_bbox_op, resize_with_bbox_op1}, {"image", "bbox"}, {"image", "bbox"}, {"image", "bbox"}); | |||
| @@ -209,8 +186,8 @@ TEST_F(MindDataTestPipeline, TestResizeWithBBoxSuccess) { | |||
| uint64_t i = 0; | |||
| while (row.size() != 0) { | |||
| i++; | |||
| // auto image = row["image"]; | |||
| // MS_LOG(INFO) << "Tensor image shape: " << image->shape(); | |||
| auto image = row["image"]; | |||
| MS_LOG(INFO) << "Tensor image shape: " << image.Shape(); | |||
| iter->GetNextRow(&row); | |||
| } | |||
| @@ -218,38 +195,3 @@ TEST_F(MindDataTestPipeline, TestResizeWithBBoxSuccess) { | |||
| // Manually terminate the pipeline | |||
| iter->Stop(); | |||
| } | |||
| TEST_F(MindDataTestPipeline, TestResizeWithBBoxFail) { | |||
| MS_LOG(INFO) << "Doing MindDataTestPipeline-TestResizeWithBBoxFail with invalid parameters."; | |||
| // FIXME: For error tests, need to check for failure from CreateIterator execution | |||
| // Testing negative resize value | |||
| std::shared_ptr<TensorTransform> resize_with_bbox_op(new vision::ResizeWithBBox({10, -10})); | |||
| EXPECT_NE(resize_with_bbox_op, nullptr); | |||
| // Testing negative resize value | |||
| std::shared_ptr<TensorTransform> resize_with_bbox_op1(new vision::ResizeWithBBox({-10})); | |||
| EXPECT_NE(resize_with_bbox_op1, nullptr); | |||
| // Testinig zero resize value | |||
| std::shared_ptr<TensorTransform> resize_with_bbox_op2(new vision::ResizeWithBBox({0, 10})); | |||
| EXPECT_NE(resize_with_bbox_op2, nullptr); | |||
| // Testing resize with 3 values | |||
| std::shared_ptr<TensorTransform> resize_with_bbox_op3(new vision::ResizeWithBBox({10, 10, 10})); | |||
| EXPECT_NE(resize_with_bbox_op3, nullptr); | |||
| } | |||
| TEST_F(MindDataTestPipeline, TestVisionOperationName) { | |||
| MS_LOG(INFO) << "Doing MindDataTestPipeline-TestVisionOperationName."; | |||
| std::string correct_name; | |||
| // Create object for the tensor op, and check the name | |||
| /* FIXME - Update and move test to IR level | |||
| std::shared_ptr<TensorOperation> random_vertical_flip_op = vision::RandomVerticalFlip(0.5); | |||
| correct_name = "RandomVerticalFlip"; | |||
| EXPECT_EQ(correct_name, random_vertical_flip_op->Name()); | |||
| // Create object for the tensor op, and check the name | |||
| std::shared_ptr<TensorOperation> softDvpp_decode_resize_jpeg_op = vision::SoftDvppDecodeResizeJpeg({1, 1}); | |||
| correct_name = "SoftDvppDecodeResizeJpeg"; | |||
| EXPECT_EQ(correct_name, softDvpp_decode_resize_jpeg_op->Name()); | |||
| */ | |||
| } | |||
| @@ -66,8 +66,8 @@ TEST_F(MindDataTestPipeline, TestRandomSelectSubpolicySuccess1Shr) { | |||
| uint64_t i = 0; | |||
| while (row.size() != 0) { | |||
| i++; | |||
| // auto image = row["image"]; | |||
| // MS_LOG(INFO) << "Tensor image shape: " << image->shape(); | |||
| auto image = row["image"]; | |||
| MS_LOG(INFO) << "Tensor image shape: " << image.Shape(); | |||
| iter->GetNextRow(&row); | |||
| } | |||
| @@ -87,6 +87,7 @@ TEST_F(MindDataTestPipeline, TestRandomSelectSubpolicySuccess2Auto) { | |||
| // Create objects for the tensor ops | |||
| // Use auto for raw pointers | |||
| // Note that with auto and new, we have to explicitly delete the allocated object as shown below. | |||
| // Valid case: TensorTransform is not null and probability is between (0,1) | |||
| auto invert_op(new vision::Invert()); | |||
| auto equalize_op(new vision::Equalize()); | |||
| @@ -118,8 +119,8 @@ TEST_F(MindDataTestPipeline, TestRandomSelectSubpolicySuccess2Auto) { | |||
| uint64_t i = 0; | |||
| while (row.size() != 0) { | |||
| i++; | |||
| // auto image = row["image"]; | |||
| // MS_LOG(INFO) << "Tensor image shape: " << image->shape(); | |||
| auto image = row["image"]; | |||
| MS_LOG(INFO) << "Tensor image shape: " << image.Shape(); | |||
| iter->GetNextRow(&row); | |||
| } | |||
| @@ -127,6 +128,12 @@ TEST_F(MindDataTestPipeline, TestRandomSelectSubpolicySuccess2Auto) { | |||
| // Manually terminate the pipeline | |||
| iter->Stop(); | |||
| // Delete allocated objects with raw pointers | |||
| delete invert_op; | |||
| delete equalize_op; | |||
| delete resize_op; | |||
| delete random_select_subpolicy_op; | |||
| } | |||
| TEST_F(MindDataTestPipeline, TestRandomSelectSubpolicySuccess3Obj) { | |||
| @@ -169,8 +176,8 @@ TEST_F(MindDataTestPipeline, TestRandomSelectSubpolicySuccess3Obj) { | |||
| uint64_t i = 0; | |||
| while (row.size() != 0) { | |||
| i++; | |||
| // auto image = row["image"]; | |||
| // MS_LOG(INFO) << "Tensor image shape: " << image->shape(); | |||
| auto image = row["image"]; | |||
| MS_LOG(INFO) << "Tensor image shape: " << image.Shape(); | |||
| iter->GetNextRow(&row); | |||
| } | |||
| @@ -221,8 +228,8 @@ TEST_F(MindDataTestPipeline, TestRandomSelectSubpolicySuccess4MultiPolicy) { | |||
| uint64_t i = 0; | |||
| while (row.size() != 0) { | |||
| i++; | |||
| // auto image = row["image"]; | |||
| // MS_LOG(INFO) << "Tensor image shape: " << image->shape(); | |||
| auto image = row["image"]; | |||
| MS_LOG(INFO) << "Tensor image shape: " << image.Shape(); | |||
| iter->GetNextRow(&row); | |||
| } | |||
| @@ -36,9 +36,9 @@ TEST_F(MindDataTestPipeline, TestSoftDvppDecodeRandomCropResizeJpegSuccess1) { | |||
| EXPECT_NE(ds, nullptr); | |||
| // Create objects for the tensor ops | |||
| std::shared_ptr<TensorTransform> soft_dvpp_decode_random_crop_resize_jpeg(new | |||
| vision::SoftDvppDecodeRandomCropResizeJpeg({500})); | |||
| EXPECT_NE(soft_dvpp_decode_random_crop_resize_jpeg, nullptr); | |||
| std::shared_ptr<TensorTransform> soft_dvpp_decode_random_crop_resize_jpeg( | |||
| new vision::SoftDvppDecodeRandomCropResizeJpeg({500})); | |||
| // Note: No need to check for output after calling API class constructor | |||
| // Create a Map operation on ds | |||
| ds = ds->Map({soft_dvpp_decode_random_crop_resize_jpeg}, {"image"}); | |||
| @@ -78,9 +78,9 @@ TEST_F(MindDataTestPipeline, TestSoftDvppDecodeRandomCropResizeJpegSuccess2) { | |||
| EXPECT_NE(ds, nullptr); | |||
| // Create objects for the tensor ops | |||
| std::shared_ptr<TensorTransform> soft_dvpp_decode_random_crop_resize_jpeg(new | |||
| vision::SoftDvppDecodeRandomCropResizeJpeg({500, 600}, {0.25, 0.75}, {0.5, 1.25}, 20)); | |||
| EXPECT_NE(soft_dvpp_decode_random_crop_resize_jpeg, nullptr); | |||
| std::shared_ptr<TensorTransform> soft_dvpp_decode_random_crop_resize_jpeg( | |||
| new vision::SoftDvppDecodeRandomCropResizeJpeg({500, 600}, {0.25, 0.75}, {0.5, 1.25}, 20)); | |||
| // Note: No need to check for output after calling API class constructor | |||
| // Create a Map operation on ds | |||
| ds = ds->Map({soft_dvpp_decode_random_crop_resize_jpeg}, {"image"}); | |||
| @@ -110,50 +110,6 @@ TEST_F(MindDataTestPipeline, TestSoftDvppDecodeRandomCropResizeJpegSuccess2) { | |||
| iter->Stop(); | |||
| } | |||
| TEST_F(MindDataTestPipeline, TestSoftDvppDecodeRandomCropResizeJpegFail) { | |||
| MS_LOG(INFO) << "Doing MindDataTestPipeline-TestSoftDvppDecodeRandomCropResizeJpegFail with incorrect parameters."; | |||
| // FIXME: For error tests, need to check for failure from CreateIterator execution | |||
| // SoftDvppDecodeRandomCropResizeJpeg: size must only contain positive integers | |||
| auto soft_dvpp_decode_random_crop_resize_jpeg1(new vision::SoftDvppDecodeRandomCropResizeJpeg({-500, 600})); | |||
| EXPECT_NE(soft_dvpp_decode_random_crop_resize_jpeg1, nullptr); | |||
| // SoftDvppDecodeRandomCropResizeJpeg: size must only contain positive integers | |||
| auto soft_dvpp_decode_random_crop_resize_jpeg2(new vision::SoftDvppDecodeRandomCropResizeJpeg({-500})); | |||
| EXPECT_NE(soft_dvpp_decode_random_crop_resize_jpeg2, nullptr); | |||
| // SoftDvppDecodeRandomCropResizeJpeg: size must be a vector of one or two values | |||
| auto soft_dvpp_decode_random_crop_resize_jpeg3(new vision::SoftDvppDecodeRandomCropResizeJpeg({500, 600, 700})); | |||
| EXPECT_NE(soft_dvpp_decode_random_crop_resize_jpeg3, nullptr); | |||
| // SoftDvppDecodeRandomCropResizeJpeg: scale must be greater than or equal to 0 | |||
| auto soft_dvpp_decode_random_crop_resize_jpeg4(new vision::SoftDvppDecodeRandomCropResizeJpeg({500}, {-0.1, 0.9})); | |||
| EXPECT_NE(soft_dvpp_decode_random_crop_resize_jpeg4, nullptr); | |||
| // SoftDvppDecodeRandomCropResizeJpeg: scale must be in the format of (min, max) | |||
| auto soft_dvpp_decode_random_crop_resize_jpeg5(new vision::SoftDvppDecodeRandomCropResizeJpeg({500}, {0.6, 0.2})); | |||
| EXPECT_NE(soft_dvpp_decode_random_crop_resize_jpeg5, nullptr); | |||
| // SoftDvppDecodeRandomCropResizeJpeg: scale must be a vector of two values | |||
| auto soft_dvpp_decode_random_crop_resize_jpeg6(new vision::SoftDvppDecodeRandomCropResizeJpeg({500}, {0.5, 0.6, 0.7})); | |||
| EXPECT_NE(soft_dvpp_decode_random_crop_resize_jpeg6, nullptr); | |||
| // SoftDvppDecodeRandomCropResizeJpeg: ratio must be greater than or equal to 0 | |||
| auto soft_dvpp_decode_random_crop_resize_jpeg7(new vision::SoftDvppDecodeRandomCropResizeJpeg({500}, {0.5, 0.9}, {-0.2, 0.4})); | |||
| EXPECT_NE(soft_dvpp_decode_random_crop_resize_jpeg7, nullptr); | |||
| // SoftDvppDecodeRandomCropResizeJpeg: ratio must be in the format of (min, max) | |||
| auto soft_dvpp_decode_random_crop_resize_jpeg8(new vision::SoftDvppDecodeRandomCropResizeJpeg({500}, {0.5, 0.9}, {0.4, 0.2})); | |||
| EXPECT_NE(soft_dvpp_decode_random_crop_resize_jpeg8, nullptr); | |||
| // SoftDvppDecodeRandomCropResizeJpeg: ratio must be a vector of two values | |||
| auto soft_dvpp_decode_random_crop_resize_jpeg9(new vision::SoftDvppDecodeRandomCropResizeJpeg({500}, {0.5, 0.9}, {0.1, 0.2, 0.3})); | |||
| EXPECT_NE(soft_dvpp_decode_random_crop_resize_jpeg9, nullptr); | |||
| // SoftDvppDecodeRandomCropResizeJpeg: max_attempts must be greater than or equal to 1 | |||
| auto soft_dvpp_decode_random_crop_resize_jpeg10(new vision::SoftDvppDecodeRandomCropResizeJpeg({500}, {0.5, 0.9}, {0.1, 0.2}, 0)); | |||
| EXPECT_NE(soft_dvpp_decode_random_crop_resize_jpeg10, nullptr); | |||
| } | |||
| TEST_F(MindDataTestPipeline, TestSoftDvppDecodeResizeJpegSuccess1) { | |||
| MS_LOG(INFO) << "Doing MindDataTestPipeline-TestSoftDvppDecodeResizeJpegSuccess1 with single integer input."; | |||
| // Create an ImageFolder Dataset | |||
| @@ -168,7 +124,7 @@ TEST_F(MindDataTestPipeline, TestSoftDvppDecodeResizeJpegSuccess1) { | |||
| // Create SoftDvppDecodeResizeJpeg object with single integer input | |||
| std::shared_ptr<TensorTransform> soft_dvpp_decode_resize_jpeg_op(new vision::SoftDvppDecodeResizeJpeg({1134})); | |||
| EXPECT_NE(soft_dvpp_decode_resize_jpeg_op, nullptr); | |||
| // Note: No need to check for output after calling API class constructor | |||
| // Create a Map operation on ds | |||
| ds = ds->Map({soft_dvpp_decode_resize_jpeg_op}); | |||
| @@ -206,7 +162,7 @@ TEST_F(MindDataTestPipeline, TestSoftDvppDecodeResizeJpegSuccess2) { | |||
| // Create SoftDvppDecodeResizeJpeg object with single integer input | |||
| std::shared_ptr<TensorTransform> soft_dvpp_decode_resize_jpeg_op(new vision::SoftDvppDecodeResizeJpeg({100, 200})); | |||
| EXPECT_NE(soft_dvpp_decode_resize_jpeg_op, nullptr); | |||
| // Note: No need to check for output after calling API class constructor | |||
| // Create a Map operation on ds | |||
| ds = ds->Map({soft_dvpp_decode_resize_jpeg_op}); | |||
| @@ -234,23 +190,3 @@ TEST_F(MindDataTestPipeline, TestSoftDvppDecodeResizeJpegSuccess2) { | |||
| // Manually terminate the pipeline | |||
| iter->Stop(); | |||
| } | |||
| TEST_F(MindDataTestPipeline, TestSoftDvppDecodeResizeJpegFail) { | |||
| MS_LOG(INFO) << "Doing MindDataTestPipeline-TestSoftDvppDecodeResizeJpegFail with incorrect size."; | |||
| // FIXME: For error tests, need to check for failure from CreateIterator execution | |||
| // CSoftDvppDecodeResizeJpeg: size must be a vector of one or two values | |||
| std::shared_ptr<TensorTransform> soft_dvpp_decode_resize_jpeg_op1(new vision::SoftDvppDecodeResizeJpeg({})); | |||
| EXPECT_NE(soft_dvpp_decode_resize_jpeg_op1, nullptr); | |||
| // SoftDvppDecodeResizeJpeg: size must be a vector of one or two values | |||
| std::shared_ptr<TensorTransform> soft_dvpp_decode_resize_jpeg_op2(new vision::SoftDvppDecodeResizeJpeg({1, 2, 3})); | |||
| EXPECT_NE(soft_dvpp_decode_resize_jpeg_op2, nullptr); | |||
| // SoftDvppDecodeResizeJpeg: size must only contain positive integers | |||
| std::shared_ptr<TensorTransform> soft_dvpp_decode_resize_jpeg_op3(new vision::SoftDvppDecodeResizeJpeg({20, -20})); | |||
| EXPECT_NE(soft_dvpp_decode_resize_jpeg_op3, nullptr); | |||
| // SoftDvppDecodeResizeJpeg: size must only contain positive integers | |||
| std::shared_ptr<TensorTransform> soft_dvpp_decode_resize_jpeg_op4(new vision::SoftDvppDecodeResizeJpeg({0})); | |||
| EXPECT_NE(soft_dvpp_decode_resize_jpeg_op4, nullptr); | |||
| } | |||
| @@ -63,8 +63,8 @@ TEST_F(MindDataTestPipeline, TestUniformAugWithOps1Shr) { | |||
| uint64_t i = 0; | |||
| while (row.size() != 0) { | |||
| i++; | |||
| // auto image = row["image"]; | |||
| // MS_LOG(INFO) << "Tensor image shape: " << image->shape(); | |||
| auto image = row["image"]; | |||
| MS_LOG(INFO) << "Tensor image shape: " << image.Shape(); | |||
| iter->GetNextRow(&row); | |||
| } | |||
| @@ -89,6 +89,7 @@ TEST_F(MindDataTestPipeline, TestUniformAugWithOps2Auto) { | |||
| // Create objects for the tensor ops | |||
| // Use auto for raw pointers | |||
| // Note that with auto and new, we have to explicitly delete the allocated object as shown below. | |||
| auto resize_op(new vision::Resize({30, 30})); | |||
| auto random_crop_op(new vision::RandomCrop({28, 28})); | |||
| auto center_crop_op(new vision::CenterCrop({16, 16})); | |||
| @@ -110,8 +111,8 @@ TEST_F(MindDataTestPipeline, TestUniformAugWithOps2Auto) { | |||
| uint64_t i = 0; | |||
| while (row.size() != 0) { | |||
| i++; | |||
| // auto image = row["image"]; | |||
| // MS_LOG(INFO) << "Tensor image shape: " << image->shape(); | |||
| auto image = row["image"]; | |||
| MS_LOG(INFO) << "Tensor image shape: " << image.Shape(); | |||
| iter->GetNextRow(&row); | |||
| } | |||
| @@ -119,6 +120,12 @@ TEST_F(MindDataTestPipeline, TestUniformAugWithOps2Auto) { | |||
| // Manually terminate the pipeline | |||
| iter->Stop(); | |||
| // Delete allocated objects with raw pointers | |||
| delete resize_op; | |||
| delete random_crop_op; | |||
| delete center_crop_op; | |||
| delete uniform_aug_op; | |||
| } | |||
| TEST_F(MindDataTestPipeline, TestUniformAugWithOps3Obj) { | |||
| @@ -157,8 +164,8 @@ TEST_F(MindDataTestPipeline, TestUniformAugWithOps3Obj) { | |||
| uint64_t i = 0; | |||
| while (row.size() != 0) { | |||
| i++; | |||
| // auto image = row["image"]; | |||
| // MS_LOG(INFO) << "Tensor image shape: " << image->shape(); | |||
| auto image = row["image"]; | |||
| MS_LOG(INFO) << "Tensor image shape: " << image.Shape(); | |||
| iter->GetNextRow(&row); | |||
| } | |||
| @@ -17,9 +17,6 @@ | |||
| #include <memory> | |||
| #include <string> | |||
| #include "common/common.h" | |||
| #include "minddata/dataset/include/datasets.h" | |||
| #include "minddata/dataset/include/transforms.h" | |||
| #include "minddata/dataset/include/vision.h" | |||
| #include "minddata/dataset/kernels/ir/vision/vision_ir.h" | |||
| using namespace mindspore::dataset; | |||
| @@ -29,67 +26,345 @@ class MindDataTestIRVision : public UT::DatasetOpTesting { | |||
| MindDataTestIRVision() = default; | |||
| }; | |||
| TEST_F(MindDataTestIRVision, TestAutoContrastIRFail1) { | |||
| MS_LOG(INFO) << "Doing MindDataTestIRVision-TestAutoContrastIRFail1."; | |||
| TEST_F(MindDataTestIRVision, TestAutoContrastFail1) { | |||
| MS_LOG(INFO) << "Doing MindDataTestIRVision-TestAutoContrastFail1."; | |||
| // Testing invalid cutoff < 0 | |||
| std::shared_ptr<TensorOperation> auto_contrast1(new vision::AutoContrastOperation(-1.0,{})); | |||
| ASSERT_NE(auto_contrast1, nullptr); | |||
| std::shared_ptr<TensorOperation> auto_contrast1(new vision::AutoContrastOperation(-1.0, {})); | |||
| Status rc1 = auto_contrast1->ValidateParams(); | |||
| EXPECT_ERROR(rc1); | |||
| // Testing invalid cutoff > 100 | |||
| std::shared_ptr<TensorOperation> auto_contrast2(new vision::AutoContrastOperation(110.0, {10, 20})); | |||
| ASSERT_NE(auto_contrast2, nullptr); | |||
| Status rc2 = auto_contrast2->ValidateParams(); | |||
| EXPECT_ERROR(rc2); | |||
| } | |||
| TEST_F(MindDataTestIRVision, TestCenterCropFail) { | |||
| MS_LOG(INFO) << "Doing MindDataTestIRVision-TestCenterCrop with invalid parameters."; | |||
| Status rc; | |||
| // center crop height value negative | |||
| std::shared_ptr<TensorOperation> center_crop1(new vision::CenterCropOperation({-32, 32})); | |||
| rc = center_crop1->ValidateParams(); | |||
| EXPECT_ERROR(rc); | |||
| // center crop width value negative | |||
| std::shared_ptr<TensorOperation> center_crop2(new vision::CenterCropOperation({32, -32})); | |||
| rc = center_crop2->ValidateParams(); | |||
| EXPECT_ERROR(rc); | |||
| // 0 value would result in nullptr | |||
| std::shared_ptr<TensorOperation> center_crop3(new vision::CenterCropOperation({0, 32})); | |||
| rc = center_crop3->ValidateParams(); | |||
| EXPECT_ERROR(rc); | |||
| // center crop with 3 values | |||
| std::shared_ptr<TensorOperation> center_crop4(new vision::CenterCropOperation({10, 20, 30})); | |||
| rc = center_crop4->ValidateParams(); | |||
| EXPECT_ERROR(rc); | |||
| } | |||
| TEST_F(MindDataTestIRVision, TestCropFail) { | |||
| MS_LOG(INFO) << "Doing MindDataTestIRVision-TestCrop with invalid parameters."; | |||
| Status rc; | |||
| // wrong width | |||
| std::shared_ptr<TensorOperation> crop1(new vision::CropOperation({0, 0}, {32, -32})); | |||
| rc = crop1->ValidateParams(); | |||
| EXPECT_ERROR(rc); | |||
| // wrong height | |||
| std::shared_ptr<TensorOperation> crop2(new vision::CropOperation({0, 0}, {-32, -32})); | |||
| rc = crop2->ValidateParams(); | |||
| EXPECT_ERROR(rc); | |||
| // zero height | |||
| std::shared_ptr<TensorOperation> crop3(new vision::CropOperation({0, 0}, {0, 32})); | |||
| rc = crop3->ValidateParams(); | |||
| EXPECT_ERROR(rc); | |||
| // negative coordinates | |||
| std::shared_ptr<TensorOperation> crop4(new vision::CropOperation({-1, 0}, {32, 32})); | |||
| rc = crop4->ValidateParams(); | |||
| EXPECT_ERROR(rc); | |||
| } | |||
| TEST_F(MindDataTestIRVision, TestCutOutFail1) { | |||
| MS_LOG(INFO) << "Doing MindDataTestIRVision-TestCutOutFail1 with invalid parameters."; | |||
| Status rc; | |||
| // Create object for the tensor op | |||
| // Invalid negative length | |||
| std::shared_ptr<TensorOperation> cutout_op = std::make_shared<vision::CutOutOperation>(-10, 1); | |||
| rc = cutout_op->ValidateParams(); | |||
| EXPECT_ERROR(rc); | |||
| // Invalid negative number of patches | |||
| cutout_op = std::make_shared<vision::CutOutOperation>(10, -1); | |||
| rc = cutout_op->ValidateParams(); | |||
| EXPECT_ERROR(rc); | |||
| } | |||
| TEST_F(MindDataTestIRVision, TestCutOutFail2) { | |||
| MS_LOG(INFO) << "Doing MindDataTestIRVision-TestCutOutFail2 with invalid params, boundary cases."; | |||
| Status rc; | |||
| // Create object for the tensor op | |||
| // Invalid zero length | |||
| std::shared_ptr<TensorOperation> cutout_op = std::make_shared<vision::CutOutOperation>(0, 1); | |||
| rc = cutout_op->ValidateParams(); | |||
| EXPECT_ERROR(rc); | |||
| // Invalid zero number of patches | |||
| cutout_op = std::make_shared<vision::CutOutOperation>(10, 0); | |||
| rc = cutout_op->ValidateParams(); | |||
| EXPECT_ERROR(rc); | |||
| } | |||
| TEST_F(MindDataTestIRVision, TestNormalizeFail) { | |||
| MS_LOG(INFO) << "Doing MindDataTestIRVision-TestNormalizeFail with invalid parameters."; | |||
| // std value at 0.0 | |||
| std::shared_ptr<TensorOperation> normalize1(new vision::NormalizeOperation({121.0, 115.0, 100.0}, {0.0, 68.0, 71.0})); | |||
| ASSERT_NE(normalize1, nullptr); | |||
| Status rc; | |||
| Status rc1 = normalize1->ValidateParams(); | |||
| EXPECT_ERROR(rc1); | |||
| // std value 0.0 out of range | |||
| std::shared_ptr<TensorOperation> normalize1(new vision::NormalizeOperation({121.0, 115.0, 100.0}, {0.0, 68.0, 71.0})); | |||
| rc = normalize1->ValidateParams(); | |||
| EXPECT_ERROR(rc); | |||
| // mean out of range | |||
| std::shared_ptr<TensorOperation> normalize2(new vision::NormalizeOperation({121.0, 0.0, 100.0}, {256.0, 68.0, 71.0})); | |||
| ASSERT_NE(normalize2, nullptr); | |||
| // std value 256.0 out of range | |||
| std::shared_ptr<TensorOperation> normalize2( | |||
| new vision::NormalizeOperation({121.0, 10.0, 100.0}, {256.0, 68.0, 71.0})); | |||
| rc = normalize2->ValidateParams(); | |||
| EXPECT_ERROR(rc); | |||
| Status rc2 = normalize2->ValidateParams(); | |||
| EXPECT_ERROR(rc2); | |||
| // mean out of range | |||
| // mean value 256.0 out of range | |||
| std::shared_ptr<TensorOperation> normalize3(new vision::NormalizeOperation({256.0, 0.0, 100.0}, {70.0, 68.0, 71.0})); | |||
| ASSERT_NE(normalize3, nullptr); | |||
| Status rc3 = normalize3->ValidateParams(); | |||
| EXPECT_ERROR(rc3); | |||
| rc = normalize3->ValidateParams(); | |||
| EXPECT_ERROR(rc); | |||
| // mean out of range | |||
| // mean value 0.0 out of range | |||
| std::shared_ptr<TensorOperation> normalize4(new vision::NormalizeOperation({-1.0, 0.0, 100.0}, {70.0, 68.0, 71.0})); | |||
| ASSERT_NE(normalize4, nullptr); | |||
| Status rc4 = normalize4->ValidateParams(); | |||
| EXPECT_ERROR(rc4); | |||
| rc = normalize4->ValidateParams(); | |||
| EXPECT_ERROR(rc); | |||
| // normalize with 2 values (not 3 values) for mean | |||
| std::shared_ptr<TensorOperation> normalize5(new vision::NormalizeOperation({121.0, 115.0}, {70.0, 68.0, 71.0})); | |||
| ASSERT_NE(normalize5, nullptr); | |||
| Status rc5 = normalize5->ValidateParams(); | |||
| EXPECT_ERROR(rc5); | |||
| rc = normalize5->ValidateParams(); | |||
| EXPECT_ERROR(rc); | |||
| // normalize with 2 values (not 3 values) for standard deviation | |||
| std::shared_ptr<TensorOperation> normalize6(new vision::NormalizeOperation({121.0, 115.0, 100.0}, {68.0, 71.0})); | |||
| ASSERT_NE(normalize6, nullptr); | |||
| rc = normalize6->ValidateParams(); | |||
| EXPECT_ERROR(rc); | |||
| } | |||
| TEST_F(MindDataTestIRVision, TestNormalizePadFail) { | |||
| MS_LOG(INFO) << "Doing MindDataTestIRVision-TestNormalizePadFail with invalid parameters."; | |||
| Status rc; | |||
| // std value at 0.0 | |||
| std::shared_ptr<TensorOperation> normalizepad1( | |||
| new vision::NormalizePadOperation({121.0, 115.0, 100.0}, {0.0, 68.0, 71.0}, "float32")); | |||
| rc = normalizepad1->ValidateParams(); | |||
| EXPECT_ERROR(rc); | |||
| // normalizepad with 2 values (not 3 values) for mean | |||
| std::shared_ptr<TensorOperation> normalizepad2( | |||
| new vision::NormalizePadOperation({121.0, 115.0}, {70.0, 68.0, 71.0}, "float32")); | |||
| rc = normalizepad2->ValidateParams(); | |||
| EXPECT_ERROR(rc); | |||
| // normalizepad with 2 values (not 3 values) for standard deviation | |||
| std::shared_ptr<TensorOperation> normalizepad3( | |||
| new vision::NormalizePadOperation({121.0, 115.0, 100.0}, {68.0, 71.0}, "float32")); | |||
| rc = normalizepad3->ValidateParams(); | |||
| EXPECT_ERROR(rc); | |||
| // normalizepad with invalid dtype | |||
| std::shared_ptr<TensorOperation> normalizepad4( | |||
| new vision::NormalizePadOperation({121.0, 115.0, 100.0}, {68.0, 71.0, 71.0}, "123")); | |||
| rc = normalizepad4->ValidateParams(); | |||
| EXPECT_ERROR(rc); | |||
| } | |||
| TEST_F(MindDataTestIRVision, TestRescaleFail) { | |||
| MS_LOG(INFO) << "Doing MindDataTestIRVision-TestRescaleFail with invalid params."; | |||
| Status rc; | |||
| // incorrect negative rescale parameter | |||
| std::shared_ptr<TensorOperation> rescale(new vision::RescaleOperation(-1.0, 0.0)); | |||
| rc = rescale->ValidateParams(); | |||
| EXPECT_ERROR(rc); | |||
| } | |||
| TEST_F(MindDataTestIRVision, TestResizeFail) { | |||
| MS_LOG(INFO) << "Doing MindDataTestIRVision-TestResize with invalid parameters."; | |||
| Status rc; | |||
| // negative resize value | |||
| std::shared_ptr<TensorOperation> resize_op1(new vision::ResizeOperation({30, -30}, InterpolationMode::kLinear)); | |||
| rc = resize_op1->ValidateParams(); | |||
| EXPECT_ERROR(rc); | |||
| // zero resize value | |||
| std::shared_ptr<TensorOperation> resize_op2(new vision::ResizeOperation({0, 30}, InterpolationMode::kLinear)); | |||
| rc = resize_op2->ValidateParams(); | |||
| EXPECT_ERROR(rc); | |||
| // resize with 3 values | |||
| std::shared_ptr<TensorOperation> resize_op3(new vision::ResizeOperation({30, 20, 10}, InterpolationMode::kLinear)); | |||
| rc = resize_op3->ValidateParams(); | |||
| EXPECT_ERROR(rc); | |||
| } | |||
| TEST_F(MindDataTestIRVision, TestResizeWithBBoxFail) { | |||
| MS_LOG(INFO) << "Doing MindDataTestIRVision-TestResizeWithBBoxFail with invalid parameters."; | |||
| Status rc; | |||
| // Testing negative resize value | |||
| std::shared_ptr<TensorOperation> resize_with_bbox_op( | |||
| new vision::ResizeWithBBoxOperation({10, -10}, InterpolationMode::kLinear)); | |||
| EXPECT_NE(resize_with_bbox_op, nullptr); | |||
| rc = resize_with_bbox_op->ValidateParams(); | |||
| EXPECT_ERROR(rc); | |||
| // Testing negative resize value | |||
| std::shared_ptr<TensorOperation> resize_with_bbox_op1( | |||
| new vision::ResizeWithBBoxOperation({-10}, InterpolationMode::kLinear)); | |||
| EXPECT_NE(resize_with_bbox_op1, nullptr); | |||
| rc = resize_with_bbox_op1->ValidateParams(); | |||
| EXPECT_ERROR(rc); | |||
| // Testing zero resize value | |||
| std::shared_ptr<TensorOperation> resize_with_bbox_op2( | |||
| new vision::ResizeWithBBoxOperation({0, 10}, InterpolationMode::kLinear)); | |||
| EXPECT_NE(resize_with_bbox_op2, nullptr); | |||
| rc = resize_with_bbox_op2->ValidateParams(); | |||
| EXPECT_ERROR(rc); | |||
| // Testing resize with 3 values | |||
| std::shared_ptr<TensorOperation> resize_with_bbox_op3( | |||
| new vision::ResizeWithBBoxOperation({10, 10, 10}, InterpolationMode::kLinear)); | |||
| EXPECT_NE(resize_with_bbox_op3, nullptr); | |||
| rc = resize_with_bbox_op3->ValidateParams(); | |||
| EXPECT_ERROR(rc); | |||
| } | |||
| TEST_F(MindDataTestIRVision, TestSoftDvppDecodeRandomCropResizeJpegFail) { | |||
| MS_LOG(INFO) << "Doing MindDataTestIRVision-TestSoftDvppDecodeRandomCropResizeJpegFail with incorrect parameters."; | |||
| Status rc; | |||
| // SoftDvppDecodeRandomCropResizeJpeg: size must only contain positive integers | |||
| std::shared_ptr<TensorOperation> soft_dvpp_decode_random_crop_resize_jpeg1( | |||
| new vision::SoftDvppDecodeRandomCropResizeJpegOperation({-500, 600}, {0.08, 1.0}, {3. / 4., 4. / 3.}, 10)); | |||
| rc = soft_dvpp_decode_random_crop_resize_jpeg1->ValidateParams(); | |||
| EXPECT_ERROR(rc); | |||
| // SoftDvppDecodeRandomCropResizeJpeg: size must only contain positive integers | |||
| std::shared_ptr<TensorOperation> soft_dvpp_decode_random_crop_resize_jpeg2( | |||
| new vision::SoftDvppDecodeRandomCropResizeJpegOperation({-500}, {0.08, 1.0}, {3. / 4., 4. / 3.}, 10)); | |||
| rc = soft_dvpp_decode_random_crop_resize_jpeg2->ValidateParams(); | |||
| EXPECT_ERROR(rc); | |||
| // SoftDvppDecodeRandomCropResizeJpeg: size must be a vector of one or two values | |||
| std::shared_ptr<TensorOperation> soft_dvpp_decode_random_crop_resize_jpeg3( | |||
| new vision::SoftDvppDecodeRandomCropResizeJpegOperation({500, 600, 700}, {0.08, 1.0}, {3. / 4., 4. / 3.}, 10)); | |||
| rc = soft_dvpp_decode_random_crop_resize_jpeg3->ValidateParams(); | |||
| EXPECT_ERROR(rc); | |||
| // SoftDvppDecodeRandomCropResizeJpeg: scale must be greater than or equal to 0 | |||
| std::shared_ptr<TensorOperation> soft_dvpp_decode_random_crop_resize_jpeg4( | |||
| new vision::SoftDvppDecodeRandomCropResizeJpegOperation({500}, {-0.1, 0.9}, {3. / 4., 4. / 3.}, 1)); | |||
| rc = soft_dvpp_decode_random_crop_resize_jpeg4->ValidateParams(); | |||
| EXPECT_ERROR(rc); | |||
| // SoftDvppDecodeRandomCropResizeJpeg: scale must be in the format of (min, max) | |||
| std::shared_ptr<TensorOperation> soft_dvpp_decode_random_crop_resize_jpeg5( | |||
| new vision::SoftDvppDecodeRandomCropResizeJpegOperation({500}, {0.6, 0.2}, {3. / 4., 4. / 3.}, 1)); | |||
| rc = soft_dvpp_decode_random_crop_resize_jpeg5->ValidateParams(); | |||
| EXPECT_ERROR(rc); | |||
| // SoftDvppDecodeRandomCropResizeJpeg: scale must be a vector of two values | |||
| std::shared_ptr<TensorOperation> soft_dvpp_decode_random_crop_resize_jpeg6( | |||
| new vision::SoftDvppDecodeRandomCropResizeJpegOperation({500}, {0.5, 0.6, 0.7}, {3. / 4., 4. / 3.}, 1)); | |||
| rc = soft_dvpp_decode_random_crop_resize_jpeg6->ValidateParams(); | |||
| EXPECT_ERROR(rc); | |||
| // SoftDvppDecodeRandomCropResizeJpeg: ratio must be greater than or equal to 0 | |||
| std::shared_ptr<TensorOperation> soft_dvpp_decode_random_crop_resize_jpeg7( | |||
| new vision::SoftDvppDecodeRandomCropResizeJpegOperation({500}, {0.5, 0.9}, {-0.2, 0.4}, 5)); | |||
| rc = soft_dvpp_decode_random_crop_resize_jpeg7->ValidateParams(); | |||
| EXPECT_ERROR(rc); | |||
| // SoftDvppDecodeRandomCropResizeJpeg: ratio must be in the format of (min, max) | |||
| std::shared_ptr<TensorOperation> soft_dvpp_decode_random_crop_resize_jpeg8( | |||
| new vision::SoftDvppDecodeRandomCropResizeJpegOperation({500}, {0.5, 0.9}, {0.4, 0.2}, 5)); | |||
| rc = soft_dvpp_decode_random_crop_resize_jpeg8->ValidateParams(); | |||
| EXPECT_ERROR(rc); | |||
| // SoftDvppDecodeRandomCropResizeJpeg: ratio must be a vector of two values | |||
| std::shared_ptr<TensorOperation> soft_dvpp_decode_random_crop_resize_jpeg9( | |||
| new vision::SoftDvppDecodeRandomCropResizeJpegOperation({500}, {0.5, 0.9}, {0.1, 0.2, 0.3}, 5)); | |||
| rc = soft_dvpp_decode_random_crop_resize_jpeg9->ValidateParams(); | |||
| EXPECT_ERROR(rc); | |||
| // SoftDvppDecodeRandomCropResizeJpeg: max_attempts must be greater than or equal to 1 | |||
| std::shared_ptr<TensorOperation> soft_dvpp_decode_random_crop_resize_jpeg10( | |||
| new vision::SoftDvppDecodeRandomCropResizeJpegOperation({500}, {0.5, 0.9}, {0.1, 0.2}, 0)); | |||
| rc = soft_dvpp_decode_random_crop_resize_jpeg10->ValidateParams(); | |||
| EXPECT_ERROR(rc); | |||
| } | |||
| TEST_F(MindDataTestIRVision, TestSoftDvppDecodeResizeJpegFail) { | |||
| MS_LOG(INFO) << "Doing MindDataTestIRVision-TestSoftDvppDecodeResizeJpegFail with incorrect size."; | |||
| Status rc; | |||
| // CSoftDvppDecodeResizeJpeg: size must be a vector of one or two values | |||
| std::shared_ptr<TensorOperation> soft_dvpp_decode_resize_jpeg_op1(new vision::SoftDvppDecodeResizeJpegOperation({})); | |||
| rc = soft_dvpp_decode_resize_jpeg_op1->ValidateParams(); | |||
| EXPECT_ERROR(rc); | |||
| // SoftDvppDecodeResizeJpeg: size must be a vector of one or two values | |||
| std::shared_ptr<TensorOperation> soft_dvpp_decode_resize_jpeg_op2( | |||
| new vision::SoftDvppDecodeResizeJpegOperation({1, 2, 3})); | |||
| rc = soft_dvpp_decode_resize_jpeg_op2->ValidateParams(); | |||
| EXPECT_ERROR(rc); | |||
| // SoftDvppDecodeResizeJpeg: size must only contain positive integers | |||
| std::shared_ptr<TensorOperation> soft_dvpp_decode_resize_jpeg_op3( | |||
| new vision::SoftDvppDecodeResizeJpegOperation({20, -20})); | |||
| rc = soft_dvpp_decode_resize_jpeg_op3->ValidateParams(); | |||
| EXPECT_ERROR(rc); | |||
| // SoftDvppDecodeResizeJpeg: size must only contain positive integers | |||
| std::shared_ptr<TensorOperation> soft_dvpp_decode_resize_jpeg_op4(new vision::SoftDvppDecodeResizeJpegOperation({0})); | |||
| rc = soft_dvpp_decode_resize_jpeg_op4->ValidateParams(); | |||
| EXPECT_ERROR(rc); | |||
| } | |||
| TEST_F(MindDataTestIRVision, TestVisionOperationName) { | |||
| MS_LOG(INFO) << "Doing MindDataTestIRVision-TestVisionOperationName."; | |||
| std::string correct_name; | |||
| // Create object for the tensor op, and check the name | |||
| std::shared_ptr<TensorOperation> random_vertical_flip_op = std::make_shared<vision::RandomVerticalFlipOperation>(0.5); | |||
| correct_name = "RandomVerticalFlip"; | |||
| EXPECT_EQ(correct_name, random_vertical_flip_op->Name()); | |||
| Status rc6 = normalize6->ValidateParams(); | |||
| EXPECT_ERROR(rc6); | |||
| // Create object for the tensor op, and check the name | |||
| std::shared_ptr<TensorOperation> softDvpp_decode_resize_jpeg_op( | |||
| new vision::SoftDvppDecodeResizeJpegOperation({1, 1})); | |||
| correct_name = "SoftDvppDecodeResizeJpeg"; | |||
| EXPECT_EQ(correct_name, softDvpp_decode_resize_jpeg_op->Name()); | |||
| } | |||