!12553 dataset: Split c_api_vision_test.cc
From: @cathwong Reviewed-by: @robingrosman,@nsyca Signed-off-by: @robingrosmanpull/12553/MERGE
commit
182d928379
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,83 @@
|
||||
/**
|
||||
* Copyright 2020-2021 Huawei Technologies Co., Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "common/common.h"
|
||||
#include "minddata/dataset/include/datasets.h"
|
||||
#include "minddata/dataset/include/transforms.h"
|
||||
#include "minddata/dataset/include/vision.h"
|
||||
|
||||
using namespace mindspore::dataset;
|
||||
|
||||
class MindDataTestPipeline : public UT::DatasetOpTesting {
|
||||
protected:
|
||||
};
|
||||
|
||||
// Tests for vision C++ API BoundingBoxAugment TensorTransform Operation
|
||||
|
||||
TEST_F(MindDataTestPipeline, TestBoundingBoxAugmentSuccess) {
|
||||
MS_LOG(INFO) << "Doing MindDataTestPipeline-TestBoundingBoxAugmentSuccess.";
|
||||
// Create an VOC Dataset
|
||||
std::string folder_path = datasets_root_path_ + "/testVOC2012_2";
|
||||
std::shared_ptr<Dataset> ds = VOC(folder_path, "Detection", "train", {}, true, SequentialSampler(0, 3));
|
||||
EXPECT_NE(ds, nullptr);
|
||||
|
||||
/* FIXME - Resolve BoundingBoxAugment to properly handle TensorTransform input
|
||||
// Create objects for the tensor ops
|
||||
std::shared_ptr<TensorTransform> bound_box_augment = std::make_shared<vision::BoundingBoxAugment>(vision::RandomRotation({90.0}), 1.0);
|
||||
EXPECT_NE(bound_box_augment, nullptr);
|
||||
|
||||
// Create a Map operation on ds
|
||||
ds = ds->Map({bound_box_augment}, {"image", "bbox"}, {"image", "bbox"}, {"image", "bbox"});
|
||||
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<Iterator> iter = ds->CreateIterator();
|
||||
EXPECT_NE(iter, nullptr);
|
||||
|
||||
// Iterate the dataset and get each row
|
||||
std::unordered_map<std::string, mindspore::MSTensor> 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, 3);
|
||||
// Manually terminate the pipeline
|
||||
iter->Stop();
|
||||
*/
|
||||
}
|
||||
|
||||
TEST_F(MindDataTestPipeline, TestBoundingBoxAugmentFail) {
|
||||
MS_LOG(INFO) << "Doing MindDataTestPipeline-TestBoundingBoxAugmentFail with invalid params.";
|
||||
|
||||
// FIXME: For error tests, need to check for failure from CreateIterator execution
|
||||
/*
|
||||
// Testing invalid ratio < 0.0
|
||||
std::shared_ptr<TensorTransform> bound_box_augment = std::make_shared<vision::BoundingBoxAugment>(vision::RandomRotation({90.0}), -1.0);
|
||||
EXPECT_EQ(bound_box_augment, nullptr);
|
||||
// Testing invalid ratio > 1.0
|
||||
std::shared_ptr<TensorTransform> bound_box_augment1 = std::make_shared<vision::BoundingBoxAugment>(vision::RandomRotation({90.0}), 2.0);
|
||||
EXPECT_EQ(bound_box_augment1, nullptr);
|
||||
// Testing invalid transform
|
||||
std::shared_ptr<TensorTransform> bound_box_augment2 = std::make_shared<vision::BoundingBoxAugment>(nullptr, 0.5);
|
||||
EXPECT_EQ(bound_box_augment2, nullptr);
|
||||
*/
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,97 @@
|
||||
/**
|
||||
* Copyright 2020-2021 Huawei Technologies Co., Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "common/common.h"
|
||||
#include "minddata/dataset/include/datasets.h"
|
||||
#include "minddata/dataset/include/transforms.h"
|
||||
#include "minddata/dataset/include/vision.h"
|
||||
|
||||
using namespace mindspore::dataset;
|
||||
|
||||
class MindDataTestPipeline : public UT::DatasetOpTesting {
|
||||
protected:
|
||||
};
|
||||
|
||||
// Tests for vision C++ API RandomSelectSubpolicy TensorTransform Operations
|
||||
|
||||
TEST_F(MindDataTestPipeline, TestRandomSelectSubpolicySuccess) {
|
||||
MS_LOG(INFO) << "Doing MindDataTestPipeline-TestRandomSelectSubpolicySuccess.";
|
||||
|
||||
// Create an ImageFolder Dataset
|
||||
std::string folder_path = datasets_root_path_ + "/testPK/data/";
|
||||
std::shared_ptr<Dataset> ds = ImageFolder(folder_path, true, RandomSampler(false, 7));
|
||||
EXPECT_NE(ds, nullptr);
|
||||
|
||||
/* FIXME - Resolve RandomSelectSubpolicy to properly handle TensorTransform input
|
||||
// Create objects for the tensor ops
|
||||
// Valid case: TensorTransform is not null and probability is between (0,1)
|
||||
std::shared_ptr<TensorTransform> random_select_subpolicy(new vision::RandomSelectSubpolicy(
|
||||
{{{vision::Invert(), 0.5}, {vision::Equalize(), 0.5}}, {{vision::Resize({15, 15}), 1}}}));
|
||||
EXPECT_NE(random_select_subpolicy, nullptr);
|
||||
|
||||
// Create a Map operation on ds
|
||||
ds = ds->Map({random_select_subpolicy});
|
||||
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<Iterator> iter = ds->CreateIterator();
|
||||
EXPECT_NE(iter, nullptr);
|
||||
|
||||
// Iterate the dataset and get each row
|
||||
std::unordered_map<std::string, mindspore::MSTensor> 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, 7);
|
||||
|
||||
// Manually terminate the pipeline
|
||||
iter->Stop();
|
||||
*/
|
||||
}
|
||||
|
||||
TEST_F(MindDataTestPipeline, TestRandomSelectSubpolicyFail) {
|
||||
MS_LOG(INFO) << "Doing MindDataTestPipeline-TestRandomSelectSubpolicyFail.";
|
||||
// FIXME: For error tests, need to check for failure from CreateIterator execution
|
||||
/* FIXME - Resolve RandomSelectSubpolicy to properly handle TensorTransform input
|
||||
// RandomSelectSubpolicy : probability of transform must be between 0.0 and 1.0
|
||||
std::shared_ptr<TensorTransform> random_select_subpolicy1(new vision::RandomSelectSubpolicy(
|
||||
{{{vision::Invert(), 1.5}, {vision::Equalize(), 0.5}}, {{vision::Resize({15, 15}), 1}}}));
|
||||
EXPECT_NE(random_select_subpolicy1, nullptr);
|
||||
|
||||
// RandomSelectSubpolicy: policy must not be empty
|
||||
std::shared_ptr<TensorTransform> random_select_subpolicy2(new vision::RandomSelectSubpolicy({{{vision::Invert(), 0.5}, {vision::Equalize(), 0.5}}, {{nullptr, 1}}}));
|
||||
EXPECT_NE(random_select_subpolicy2, nullptr);
|
||||
|
||||
// RandomSelectSubpolicy: policy must not be empty
|
||||
std::shared_ptr<TensorTransform> random_select_subpolicy3(new vision::RandomSelectSubpolicy({}));
|
||||
EXPECT_NE(random_select_subpolicy3, nullptr);
|
||||
|
||||
// RandomSelectSubpolicy: policy must not be empty
|
||||
std::shared_ptr<TensorTransform> random_select_subpolicy4(new vision::RandomSelectSubpolicy({{{vision::Invert(), 0.5}, {vision::Equalize(), 0.5}}, {}}));
|
||||
EXPECT_NE(random_select_subpolicy4, nullptr);
|
||||
|
||||
// RandomSelectSubpolicy: policy must not be empty
|
||||
std::shared_ptr<TensorTransform> random_select_subpolicy5(new vision::RandomSelectSubpolicy({{{}, {vision::Equalize(), 0.5}}, {{vision::Resize({15, 15}), 1}}}));
|
||||
EXPECT_NE(random_select_subpolicy5, nullptr);
|
||||
*/
|
||||
}
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,127 @@
|
||||
/**
|
||||
* Copyright 2020-2021 Huawei Technologies Co., Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "common/common.h"
|
||||
#include "minddata/dataset/include/datasets.h"
|
||||
#include "minddata/dataset/include/transforms.h"
|
||||
#include "minddata/dataset/include/vision.h"
|
||||
|
||||
using namespace mindspore::dataset;
|
||||
|
||||
class MindDataTestPipeline : public UT::DatasetOpTesting {
|
||||
protected:
|
||||
};
|
||||
|
||||
// Tests for vision UniformAugment
|
||||
// Tests for vision C++ API UniformAugment TensorTransform Operations
|
||||
|
||||
TEST_F(MindDataTestPipeline, TestUniformAugmentFail1) {
|
||||
MS_LOG(INFO) << "Doing MindDataTestPipeline-TestUniformAugmentFail1 with invalid num_ops parameter.";
|
||||
// FIXME: For error tests, need to check for failure from CreateIterator execution
|
||||
/*
|
||||
// Create objects for the tensor ops
|
||||
std::shared_ptr<TensorTransform> random_crop_op(new vision::RandomCrop({28, 28}));
|
||||
EXPECT_NE(random_crop_op, nullptr);
|
||||
|
||||
std::shared_ptr<TensorTransform> center_crop_op(new vision::CenterCrop({16, 16}));
|
||||
EXPECT_NE(center_crop_op, nullptr);
|
||||
|
||||
// FIXME: For error tests, need to check for failure from CreateIterator execution
|
||||
// UniformAug: num_ops must be greater than 0
|
||||
std::shared_ptr<TensorTransform> uniform_aug_op1(new vision::UniformAugment({random_crop_op, center_crop_op}, 0));
|
||||
EXPECT_EQ(uniform_aug_op1, nullptr);
|
||||
|
||||
// UniformAug: num_ops must be greater than 0
|
||||
std::shared_ptr<TensorTransform> uniform_aug_op2(new vision::UniformAugment({random_crop_op, center_crop_op}, -1));
|
||||
EXPECT_EQ(uniform_aug_op2, nullptr);
|
||||
|
||||
// UniformAug: num_ops is greater than transforms size
|
||||
std::shared_ptr<TensorTransform> uniform_aug_op3(new vision::UniformAugment({random_crop_op, center_crop_op}, 3));
|
||||
EXPECT_EQ(uniform_aug_op3, nullptr);
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
TEST_F(MindDataTestPipeline, TestUniformAugmentFail2) {
|
||||
MS_LOG(INFO) << "Doing MindDataTestPipeline-TestUniformAugmentFail2 with invalid transform.";
|
||||
|
||||
// FIXME: For error tests, need to check for failure from CreateIterator execution
|
||||
/*
|
||||
// UniformAug: transform ops must not be null
|
||||
std::shared_ptr<TensorTransform> uniform_aug_op1(new vision::UniformAugment({vision::RandomCrop({-28})}, 1));
|
||||
EXPECT_NE(uniform_aug_op1, nullptr);
|
||||
|
||||
// UniformAug: transform ops must not be null
|
||||
std::shared_ptr<TensorTransform> uniform_aug_op2(new vision::UniformAugment({vision::RandomCrop({28}), nullptr}, 2));
|
||||
EXPECT_NE(uniform_aug_op2, nullptr);
|
||||
|
||||
// UniformAug: transform list must not be empty
|
||||
std::shared_ptr<TensorTransform> uniform_aug_op3(new vision::UniformAugment({}, 1));
|
||||
EXPECT_NE(uniform_aug_op3, nullptr);
|
||||
*/
|
||||
}
|
||||
|
||||
TEST_F(MindDataTestPipeline, TestUniformAugWithOps) {
|
||||
MS_LOG(INFO) << "Doing MindDataTestPipeline-TestUniformAugWithOps.";
|
||||
|
||||
// Create a Mnist Dataset
|
||||
std::string folder_path = datasets_root_path_ + "/testMnistData/";
|
||||
std::shared_ptr<Dataset> ds = Mnist(folder_path, "all", RandomSampler(false, 20));
|
||||
EXPECT_NE(ds, nullptr);
|
||||
|
||||
// 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<TensorTransform> resize_op(new vision::Resize({30, 30}));
|
||||
EXPECT_NE(resize_op, nullptr);
|
||||
|
||||
std::shared_ptr<TensorTransform> random_crop_op(new vision::RandomCrop({28, 28}));
|
||||
EXPECT_NE(random_crop_op, nullptr);
|
||||
|
||||
std::shared_ptr<TensorTransform> center_crop_op(new vision::CenterCrop({16, 16}));
|
||||
EXPECT_NE(center_crop_op, nullptr);
|
||||
|
||||
std::shared_ptr<TensorTransform> uniform_aug_op(new 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
|
||||
// This will trigger the creation of the Execution Tree and launch it.
|
||||
std::shared_ptr<Iterator> iter = ds->CreateIterator();
|
||||
EXPECT_NE(iter, nullptr);
|
||||
|
||||
// Iterate the dataset and get each row
|
||||
std::unordered_map<std::string, mindspore::MSTensor> 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, 20);
|
||||
|
||||
// Manually terminate the pipeline
|
||||
iter->Stop();
|
||||
}
|
Loading…
Reference in new issue