!12553 dataset: Split c_api_vision_test.cc
From: @cathwong Reviewed-by: @robingrosman,@nsyca Signed-off-by: @robingrosman
This commit is contained in:
commit
182d928379
|
@ -34,7 +34,13 @@ SET(DE_UT_SRCS
|
|||
c_api_text_sentence_piece_vocab_test.cc
|
||||
c_api_text_vocab_test.cc
|
||||
c_api_transforms_test.cc
|
||||
c_api_vision_test.cc
|
||||
c_api_vision_a_to_q_test.cc
|
||||
c_api_vision_bounding_box_augment_test.cc
|
||||
c_api_vision_random_subselect_policy_test.cc
|
||||
c_api_vision_random_test.cc
|
||||
c_api_vision_r_to_z_test.cc
|
||||
c_api_vision_soft_dvpp_test.cc
|
||||
c_api_vision_uniform_aug_test.cc
|
||||
celeba_op_test.cc
|
||||
center_crop_op_test.cc
|
||||
channel_swap_test.cc
|
||||
|
|
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);
|
||||
*/
|
||||
}
|
|
@ -0,0 +1,255 @@
|
|||
/**
|
||||
* 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 R to Z TensorTransform Operations (in alphabetical order)
|
||||
|
||||
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<Dataset> ds = ImageFolder(folder_path, true, SequentialSampler(0, 1));
|
||||
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);
|
||||
|
||||
auto image = row["image"];
|
||||
|
||||
// Create objects for the tensor ops
|
||||
std::shared_ptr<TensorTransform> rescale(new mindspore::dataset::vision::Rescale(1.0, 0.0));
|
||||
EXPECT_NE(rescale, nullptr);
|
||||
|
||||
// Convert to the same type
|
||||
std::shared_ptr<TensorTransform> type_cast(new transforms::TypeCast("uint8"));
|
||||
EXPECT_NE(type_cast, nullptr);
|
||||
|
||||
ds = ds->Map({rescale, type_cast}, {"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<Iterator> iter1 = ds->CreateIterator();
|
||||
EXPECT_NE(iter1, nullptr);
|
||||
|
||||
// Iterate the dataset and get each row1
|
||||
std::unordered_map<std::string, mindspore::MSTensor> row1;
|
||||
iter1->GetNextRow(&row1);
|
||||
|
||||
auto image1 = row1["image"];
|
||||
|
||||
// EXPECT_EQ(*image, *image1);
|
||||
|
||||
// Manually terminate the pipeline
|
||||
iter1->Stop();
|
||||
}
|
||||
|
||||
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<Dataset> ds = ImageFolder(folder_path, true, RandomSampler(false, 1));
|
||||
EXPECT_NE(ds, nullptr);
|
||||
|
||||
// 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);
|
||||
|
||||
ds = ds->Map({rescale}, {"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<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, 1);
|
||||
|
||||
// Manually terminate the pipeline
|
||||
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
|
||||
std::string folder_path = datasets_root_path_ + "/testPK/data/";
|
||||
std::shared_ptr<Dataset> ds = ImageFolder(folder_path, true, RandomSampler(false, 6));
|
||||
EXPECT_NE(ds, nullptr);
|
||||
|
||||
// Create a Repeat operation on ds
|
||||
int32_t repeat_num = 4;
|
||||
ds = ds->Repeat(repeat_num);
|
||||
EXPECT_NE(ds, nullptr);
|
||||
|
||||
// Create resize object with single integer input
|
||||
std::shared_ptr<TensorTransform> resize_op(new vision::Resize({30}));
|
||||
EXPECT_NE(resize_op, nullptr);
|
||||
|
||||
// Create a Map operation on ds
|
||||
ds = ds->Map({resize_op});
|
||||
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<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, 24);
|
||||
|
||||
// Manually terminate the pipeline
|
||||
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, 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);
|
||||
|
||||
// Create a Map operation on ds
|
||||
ds = ds->Map({resize_with_bbox_op, resize_with_bbox_op1}, {"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, 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());
|
||||
*/
|
||||
}
|
|
@ -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
|
@ -0,0 +1,256 @@
|
|||
/**
|
||||
* 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 SoftDvpp* TensorTransform Operations (in alphabetical order)
|
||||
|
||||
TEST_F(MindDataTestPipeline, TestSoftDvppDecodeRandomCropResizeJpegSuccess1) {
|
||||
MS_LOG(INFO)
|
||||
<< "Doing MindDataTestPipeline-TestSoftDvppDecodeRandomCropResizeJpegSuccess1 with single integer input.";
|
||||
|
||||
// Create an ImageFolder Dataset
|
||||
std::string folder_path = datasets_root_path_ + "/testPK/data/";
|
||||
std::shared_ptr<Dataset> ds = ImageFolder(folder_path, false, RandomSampler(false, 4));
|
||||
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);
|
||||
|
||||
// Create a Map operation on ds
|
||||
ds = ds->Map({soft_dvpp_decode_random_crop_resize_jpeg}, {"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<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();
|
||||
// EXPECT_EQ(image->shape()[0] == 500 && image->shape()[1] == 500, true);
|
||||
iter->GetNextRow(&row);
|
||||
}
|
||||
|
||||
EXPECT_EQ(i, 4);
|
||||
|
||||
// Manually terminate the pipeline
|
||||
iter->Stop();
|
||||
}
|
||||
|
||||
TEST_F(MindDataTestPipeline, TestSoftDvppDecodeRandomCropResizeJpegSuccess2) {
|
||||
MS_LOG(INFO)
|
||||
<< "Doing MindDataTestPipeline-TestSoftDvppDecodeRandomCropResizeJpegSuccess2 with (height, width) input.";
|
||||
|
||||
// Create an ImageFolder Dataset
|
||||
std::string folder_path = datasets_root_path_ + "/testPK/data/";
|
||||
std::shared_ptr<Dataset> ds = ImageFolder(folder_path, false, RandomSampler(false, 6));
|
||||
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);
|
||||
|
||||
// Create a Map operation on ds
|
||||
ds = ds->Map({soft_dvpp_decode_random_crop_resize_jpeg}, {"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<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();
|
||||
// EXPECT_EQ(image->shape()[0] == 500 && image->shape()[1] == 600, true);
|
||||
iter->GetNextRow(&row);
|
||||
}
|
||||
|
||||
EXPECT_EQ(i, 6);
|
||||
|
||||
// Manually terminate the pipeline
|
||||
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
|
||||
std::string folder_path = datasets_root_path_ + "/testPK/data/";
|
||||
std::shared_ptr<Dataset> ds = ImageFolder(folder_path, false, RandomSampler(false, 4));
|
||||
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 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);
|
||||
|
||||
// Create a Map operation on ds
|
||||
ds = ds->Map({soft_dvpp_decode_resize_jpeg_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, 12);
|
||||
|
||||
// Manually terminate the pipeline
|
||||
iter->Stop();
|
||||
}
|
||||
|
||||
TEST_F(MindDataTestPipeline, TestSoftDvppDecodeResizeJpegSuccess2) {
|
||||
MS_LOG(INFO) << "Doing MindDataTestPipeline-TestSoftDvppDecodeResizeJpegSuccess2 with (height, width) input.";
|
||||
// Create an ImageFolder Dataset
|
||||
std::string folder_path = datasets_root_path_ + "/testPK/data/";
|
||||
std::shared_ptr<Dataset> ds = ImageFolder(folder_path, false, RandomSampler(false, 2));
|
||||
EXPECT_NE(ds, nullptr);
|
||||
|
||||
// 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);
|
||||
|
||||
// Create a Map operation on ds
|
||||
ds = ds->Map({soft_dvpp_decode_resize_jpeg_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, 2);
|
||||
|
||||
// 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);
|
||||
}
|
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();
|
||||
}
|
|
@ -181,3 +181,34 @@ TEST_F(MindDataTestExecute, TestTransformInputSequential) {
|
|||
ASSERT_EQ(image.Shape()[1], 224);
|
||||
ASSERT_EQ(image.Shape()[2], 224);
|
||||
}
|
||||
|
||||
TEST_F(MindDataTestExecute, TestTransformDecodeResizeCenterCrop1) {
|
||||
MS_LOG(INFO) << "Doing MindDataTestExecute-TestTransformDecodeResizeCenterCrop1.";
|
||||
// Test Execute with Decode, Resize and CenterCrop transform ops input using API constructors, with auto pointers
|
||||
|
||||
// Read image
|
||||
std::shared_ptr<mindspore::dataset::Tensor> de_tensor;
|
||||
mindspore::dataset::Tensor::CreateFromFile("data/dataset/apple.jpg", &de_tensor);
|
||||
auto image = mindspore::MSTensor(std::make_shared<mindspore::dataset::DETensor>(de_tensor));
|
||||
|
||||
// Define transform operations
|
||||
std::vector<int32_t> resize_paras = {256, 256};
|
||||
std::vector<int32_t> crop_paras = {224, 224};
|
||||
auto decode(new vision::Decode());
|
||||
auto resize(new vision::Resize(resize_paras));
|
||||
auto centercrop(new vision::CenterCrop(crop_paras));
|
||||
auto hwc2chw(new vision::HWC2CHW());
|
||||
|
||||
std::vector<TensorTransform *> op_list = {decode, resize, centercrop, hwc2chw};
|
||||
mindspore::dataset::Execute Transform(op_list, "CPU");
|
||||
|
||||
// Apply transform on image
|
||||
Status rc = Transform(image, &image);
|
||||
|
||||
// Check image info
|
||||
ASSERT_TRUE(rc.IsOk());
|
||||
ASSERT_EQ(image.Shape().size(), 3);
|
||||
ASSERT_EQ(image.Shape()[0], 3);
|
||||
ASSERT_EQ(image.Shape()[1], 224);
|
||||
ASSERT_EQ(image.Shape()[2], 224);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue