|
|
|
@ -1,5 +1,5 @@
|
|
|
|
|
/**
|
|
|
|
|
* Copyright 2020 Huawei Technologies Co., Ltd
|
|
|
|
|
* 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.
|
|
|
|
@ -22,9 +22,9 @@
|
|
|
|
|
#include "utils/log_adapter.h"
|
|
|
|
|
|
|
|
|
|
using namespace mindspore::dataset;
|
|
|
|
|
using mindspore::MsLogLevel::INFO;
|
|
|
|
|
using mindspore::ExceptionType::NoExceptionType;
|
|
|
|
|
using mindspore::LogStream;
|
|
|
|
|
using mindspore::ExceptionType::NoExceptionType;
|
|
|
|
|
using mindspore::MsLogLevel::INFO;
|
|
|
|
|
|
|
|
|
|
class MindDataTestExecute : public UT::CVOP::CVOpCommon {
|
|
|
|
|
protected:
|
|
|
|
@ -41,9 +41,9 @@ TEST_F(MindDataTestExecute, TestComposeTransforms) {
|
|
|
|
|
auto image = mindspore::MSTensor(std::make_shared<DETensor>(de_tensor));
|
|
|
|
|
|
|
|
|
|
// Transform params
|
|
|
|
|
std::shared_ptr<TensorOperation> decode = vision::Decode();
|
|
|
|
|
std::shared_ptr<TensorOperation> center_crop = vision::CenterCrop({30});
|
|
|
|
|
std::shared_ptr<TensorOperation> rescale = vision::Rescale(1./3, 0.5);
|
|
|
|
|
std::shared_ptr<TensorTransform> decode = std::make_shared<vision::Decode>();
|
|
|
|
|
std::shared_ptr<TensorTransform> center_crop(new vision::CenterCrop({30}));
|
|
|
|
|
std::shared_ptr<TensorTransform> rescale = std::make_shared<vision::Rescale>(1. / 3, 0.5);
|
|
|
|
|
|
|
|
|
|
auto transform = Execute({decode, center_crop, rescale});
|
|
|
|
|
Status rc = transform(image, &image);
|
|
|
|
@ -52,3 +52,132 @@ TEST_F(MindDataTestExecute, TestComposeTransforms) {
|
|
|
|
|
EXPECT_EQ(30, image.Shape()[0]);
|
|
|
|
|
EXPECT_EQ(30, image.Shape()[1]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(MindDataTestExecute, TestTransformInput1) {
|
|
|
|
|
MS_LOG(INFO) << "Doing MindDataTestExecute-TestTransformInput1.";
|
|
|
|
|
// Test Execute with transform op input using API constructors, with std::shared_ptr<TensorTransform pointers,
|
|
|
|
|
// instantiated via mix of make_shared and new
|
|
|
|
|
|
|
|
|
|
// Read images
|
|
|
|
|
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::shared_ptr<TensorTransform> decode = std::make_shared<vision::Decode>();
|
|
|
|
|
std::shared_ptr<TensorTransform> resize(new vision::Resize({224, 224}));
|
|
|
|
|
std::shared_ptr<TensorTransform> normalize(
|
|
|
|
|
new vision::Normalize({0.485 * 255, 0.456 * 255, 0.406 * 255}, {0.229 * 255, 0.224 * 255, 0.225 * 255}));
|
|
|
|
|
std::shared_ptr<TensorTransform> hwc2chw = std::make_shared<vision::HWC2CHW>();
|
|
|
|
|
|
|
|
|
|
mindspore::dataset::Execute Transform({decode, resize, normalize, hwc2chw});
|
|
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(MindDataTestExecute, TestTransformInput2) {
|
|
|
|
|
MS_LOG(INFO) << "Doing MindDataTestExecute-TestTransformInput2.";
|
|
|
|
|
// Test Execute with transform op input using API constructors, with std::shared_ptr<TensorTransform pointers,
|
|
|
|
|
// instantiated via new
|
|
|
|
|
|
|
|
|
|
// Read images
|
|
|
|
|
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::shared_ptr<TensorTransform> decode(new vision::Decode());
|
|
|
|
|
std::shared_ptr<TensorTransform> resize(new vision::Resize({224, 224}));
|
|
|
|
|
std::shared_ptr<TensorTransform> normalize(
|
|
|
|
|
new vision::Normalize({0.485 * 255, 0.456 * 255, 0.406 * 255}, {0.229 * 255, 0.224 * 255, 0.225 * 255}));
|
|
|
|
|
std::shared_ptr<TensorTransform> hwc2chw(new vision::HWC2CHW());
|
|
|
|
|
|
|
|
|
|
mindspore::dataset::Execute Transform({decode, resize, normalize, hwc2chw});
|
|
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(MindDataTestExecute, TestTransformInput3) {
|
|
|
|
|
MS_LOG(INFO) << "Doing MindDataTestExecute-TestTransformInput3.";
|
|
|
|
|
// Test Execute with transform op 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
|
|
|
|
|
auto decode(new vision::Decode()); // auto will create raw pointer to Decode class
|
|
|
|
|
auto resize(new vision::Resize({224, 224}));
|
|
|
|
|
auto normalize(
|
|
|
|
|
new vision::Normalize({0.485 * 255, 0.456 * 255, 0.406 * 255}, {0.229 * 255, 0.224 * 255, 0.225 * 255}));
|
|
|
|
|
auto hwc2chw(new vision::HWC2CHW());
|
|
|
|
|
|
|
|
|
|
std::vector<TensorTransform *> op_list = {decode, resize, normalize, hwc2chw};
|
|
|
|
|
mindspore::dataset::Execute Transform(op_list);
|
|
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(MindDataTestExecute, TestTransformInputSequential) {
|
|
|
|
|
MS_LOG(INFO) << "Doing MindDataTestExecute-TestTransformInputSequential.";
|
|
|
|
|
// Test Execute with transform op input using API constructors, with auto pointers;
|
|
|
|
|
// Apply 2 transformations sequentially, including single non-vector Transform op input
|
|
|
|
|
|
|
|
|
|
// Read images
|
|
|
|
|
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#1 operations
|
|
|
|
|
auto decode(new vision::Decode()); // auto will create raw pointer to Decode class
|
|
|
|
|
auto resize(new vision::Resize({224, 224}));
|
|
|
|
|
auto normalize(
|
|
|
|
|
new vision::Normalize({0.485 * 255, 0.456 * 255, 0.406 * 255}, {0.229 * 255, 0.224 * 255, 0.225 * 255}));
|
|
|
|
|
|
|
|
|
|
std::vector<TensorTransform *> op_list = {decode, resize, normalize};
|
|
|
|
|
mindspore::dataset::Execute Transform(op_list);
|
|
|
|
|
|
|
|
|
|
// Apply transform#1 on image
|
|
|
|
|
Status rc = Transform(image, &image);
|
|
|
|
|
|
|
|
|
|
// Define transform#2 operations
|
|
|
|
|
auto hwc2chw(new vision::HWC2CHW());
|
|
|
|
|
|
|
|
|
|
TensorTransform *op_single = hwc2chw;
|
|
|
|
|
mindspore::dataset::Execute Transform2(op_single);
|
|
|
|
|
|
|
|
|
|
// Apply transform#2 on image
|
|
|
|
|
rc = Transform2(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);
|
|
|
|
|
}
|
|
|
|
|