first commit
added test file testing file + api fix 1 update for comments new tests added tests revert some files last test added lint fixes lint fix 2 added further required tests fixes lint fix
This commit is contained in:
parent
b830ef1717
commit
fa9ff8ca0e
|
@ -147,13 +147,18 @@ std::shared_ptr<TensorOperation> Mask::Parse() {
|
|||
|
||||
// Constructor to OneHot
|
||||
struct OneHot::Data {
|
||||
explicit Data(int32_t num_classes) : num_classes_(num_classes) {}
|
||||
explicit Data(int32_t num_classes, double smoothing_rate)
|
||||
: num_classes_(num_classes), smoothing_rate_(smoothing_rate) {}
|
||||
int32_t num_classes_;
|
||||
double smoothing_rate_;
|
||||
};
|
||||
|
||||
OneHot::OneHot(int32_t num_classes) : data_(std::make_shared<Data>(num_classes)) {}
|
||||
OneHot::OneHot(int32_t num_classes, double smoothing_rate)
|
||||
: data_(std::make_shared<Data>(num_classes, smoothing_rate)) {}
|
||||
|
||||
std::shared_ptr<TensorOperation> OneHot::Parse() { return std::make_shared<OneHotOperation>(data_->num_classes_); }
|
||||
std::shared_ptr<TensorOperation> OneHot::Parse() {
|
||||
return std::make_shared<OneHotOperation>(data_->num_classes_, data_->smoothing_rate_);
|
||||
}
|
||||
|
||||
// Constructor to PadEnd
|
||||
struct PadEnd::Data {
|
||||
|
|
|
@ -76,6 +76,7 @@
|
|||
#include "minddata/dataset/kernels/ir/vision/rotate_ir.h"
|
||||
#include "minddata/dataset/kernels/ir/vision/slice_patches_ir.h"
|
||||
#include "minddata/dataset/kernels/ir/vision/swap_red_blue_ir.h"
|
||||
#include "minddata/dataset/kernels/ir/vision/to_tensor_ir.h"
|
||||
#include "minddata/dataset/kernels/ir/vision/uniform_aug_ir.h"
|
||||
#include "minddata/dataset/kernels/ir/vision/vertical_flip_ir.h"
|
||||
#include "minddata/dataset/util/log_adapter.h"
|
||||
|
@ -266,15 +267,18 @@ std::shared_ptr<TensorOperation> CutMixBatch::Parse() {
|
|||
|
||||
// CutOutOp.
|
||||
struct CutOut::Data {
|
||||
Data(int32_t length, int32_t num_patches) : length_(length), num_patches_(num_patches) {}
|
||||
Data(int32_t length, int32_t num_patches, bool is_hwc)
|
||||
: length_(length), num_patches_(num_patches), is_hwc_(is_hwc) {}
|
||||
int32_t length_;
|
||||
int32_t num_patches_;
|
||||
bool is_hwc_;
|
||||
};
|
||||
|
||||
CutOut::CutOut(int32_t length, int32_t num_patches) : data_(std::make_shared<Data>(length, num_patches)) {}
|
||||
CutOut::CutOut(int32_t length, int32_t num_patches, bool is_hwc)
|
||||
: data_(std::make_shared<Data>(length, num_patches, is_hwc)) {}
|
||||
|
||||
std::shared_ptr<TensorOperation> CutOut::Parse() {
|
||||
return std::make_shared<CutOutOperation>(data_->length_, data_->num_patches_, true);
|
||||
return std::make_shared<CutOutOperation>(data_->length_, data_->num_patches_, data_->is_hwc_);
|
||||
}
|
||||
#endif // not ENABLE_ANDROID
|
||||
|
||||
|
@ -460,25 +464,33 @@ std::shared_ptr<TensorOperation> MixUpBatch::Parse() { return std::make_shared<M
|
|||
|
||||
// Normalize Transform Operation.
|
||||
struct Normalize::Data {
|
||||
Data(const std::vector<float> &mean, const std::vector<float> &std) : mean_(mean), std_(std) {}
|
||||
Data(const std::vector<float> &mean, const std::vector<float> &std, bool is_hwc)
|
||||
: mean_(mean), std_(std), is_hwc_(is_hwc) {}
|
||||
std::vector<float> mean_;
|
||||
std::vector<float> std_;
|
||||
bool is_hwc_;
|
||||
};
|
||||
|
||||
Normalize::Normalize(const std::vector<float> &mean, const std::vector<float> &std)
|
||||
: data_(std::make_shared<Data>(mean, std)) {}
|
||||
Normalize::Normalize(const std::vector<float> &mean, const std::vector<float> &std, bool is_hwc)
|
||||
: data_(std::make_shared<Data>(mean, std, is_hwc)) {}
|
||||
|
||||
std::shared_ptr<TensorOperation> Normalize::Parse() {
|
||||
return std::make_shared<NormalizeOperation>(data_->mean_, data_->std_, true);
|
||||
return std::make_shared<NormalizeOperation>(data_->mean_, data_->std_, data_->is_hwc_);
|
||||
}
|
||||
|
||||
std::shared_ptr<TensorOperation> Normalize::Parse(const MapTargetDevice &env) {
|
||||
#ifdef ENABLE_ANDROID
|
||||
if (data_->is_hwc_ == false) {
|
||||
MS_LOG(ERROR) << "Normalize op on Lite does not support 'is_hwc' = false.";
|
||||
return nullptr;
|
||||
}
|
||||
#endif
|
||||
if (env == MapTargetDevice::kAscend310) {
|
||||
#ifdef ENABLE_ACL
|
||||
return std::make_shared<DvppNormalizeOperation>(data_->mean_, data_->std_);
|
||||
#endif // ENABLE_ACL
|
||||
} else if (env == MapTargetDevice::kCpu) {
|
||||
return std::make_shared<NormalizeOperation>(data_->mean_, data_->std_, true);
|
||||
return std::make_shared<NormalizeOperation>(data_->mean_, data_->std_, data_->is_hwc_);
|
||||
}
|
||||
MS_LOG(ERROR) << "Unsupported MapTargetDevice, only supported kCpu and kAscend310.";
|
||||
return nullptr;
|
||||
|
@ -487,19 +499,20 @@ std::shared_ptr<TensorOperation> Normalize::Parse(const MapTargetDevice &env) {
|
|||
#ifndef ENABLE_ANDROID
|
||||
// NormalizePad Transform Operation.
|
||||
struct NormalizePad::Data {
|
||||
Data(const std::vector<float> &mean, const std::vector<float> &std, const std::string &dtype)
|
||||
: mean_(mean), std_(std), dtype_(dtype) {}
|
||||
Data(const std::vector<float> &mean, const std::vector<float> &std, const std::string &dtype, bool is_hwc)
|
||||
: mean_(mean), std_(std), dtype_(dtype), is_hwc_(is_hwc) {}
|
||||
std::vector<float> mean_;
|
||||
std::vector<float> std_;
|
||||
std::string dtype_;
|
||||
bool is_hwc_;
|
||||
};
|
||||
|
||||
NormalizePad::NormalizePad(const std::vector<float> &mean, const std::vector<float> &std,
|
||||
const std::vector<char> &dtype)
|
||||
: data_(std::make_shared<Data>(mean, std, CharToString(dtype))) {}
|
||||
const std::vector<char> &dtype, bool is_hwc)
|
||||
: data_(std::make_shared<Data>(mean, std, CharToString(dtype), is_hwc)) {}
|
||||
|
||||
std::shared_ptr<TensorOperation> NormalizePad::Parse() {
|
||||
return std::make_shared<NormalizePadOperation>(data_->mean_, data_->std_, data_->dtype_, true);
|
||||
return std::make_shared<NormalizePadOperation>(data_->mean_, data_->std_, data_->dtype_, data_->is_hwc_);
|
||||
}
|
||||
|
||||
// Pad Transform Operation.
|
||||
|
@ -1119,9 +1132,18 @@ std::shared_ptr<TensorOperation> SlicePatches::Parse() {
|
|||
|
||||
// SwapRedBlue Transform Operation.
|
||||
SwapRedBlue::SwapRedBlue() = default;
|
||||
|
||||
std::shared_ptr<TensorOperation> SwapRedBlue::Parse() { return std::make_shared<SwapRedBlueOperation>(); }
|
||||
|
||||
// ToTensor Transform Operation.
|
||||
struct ToTensor::Data {
|
||||
explicit Data(std::string &output_type) : output_type_(output_type) {}
|
||||
std::string output_type_;
|
||||
};
|
||||
|
||||
ToTensor::ToTensor(std::string output_type) : data_(std::make_shared<Data>(output_type)) {}
|
||||
|
||||
std::shared_ptr<TensorOperation> ToTensor::Parse() { return std::make_shared<ToTensorOperation>(data_->output_type_); }
|
||||
|
||||
// UniformAug Transform Operation.
|
||||
struct UniformAugment::Data {
|
||||
std::vector<std::shared_ptr<TensorOperation>> transforms_;
|
||||
|
|
|
@ -361,6 +361,7 @@ class MS_API OneHot final : public TensorTransform {
|
|||
public:
|
||||
/// \brief Constructor.
|
||||
/// \param[in] num_classes number of classes.
|
||||
/// \param[in] smoothing_rate smoothing rate default(0.0).
|
||||
/// \par Example
|
||||
/// \code
|
||||
/// /* Define operations */
|
||||
|
@ -371,7 +372,7 @@ class MS_API OneHot final : public TensorTransform {
|
|||
/// dataset = dataset->Map({one_hot_op}, // operations
|
||||
/// {"column"}); // input columns
|
||||
/// \endcode
|
||||
explicit OneHot(int32_t num_classes);
|
||||
explicit OneHot(int32_t num_classes, double smoothing_rate = 0.0);
|
||||
|
||||
/// \brief Destructor
|
||||
~OneHot() = default;
|
||||
|
|
|
@ -265,14 +265,16 @@ class MS_API CutOut final : public TensorTransform {
|
|||
/// \brief Constructor.
|
||||
/// \param[in] length Integer representing the side length of each square patch.
|
||||
/// \param[in] num_patches Integer representing the number of patches to be cut out of an image.
|
||||
/// \param[in] is_hwc A boolean to indicate whether the input image is in HWC format (true) or CHW
|
||||
/// format (false) (default = true).
|
||||
/// \par Example
|
||||
/// \code
|
||||
/// /* dataset is an instance of Dataset object */
|
||||
/// dataset = dataset->Map({std::make_shared<vision::Decode>(),
|
||||
/// std::make_shared<vision::CutOut>(1, 4)}, // operations
|
||||
/// {"image"}); // input columns
|
||||
/// std::make_shared<vision::CutOut>(1, 4, true)}, // operations
|
||||
/// {"image"}); // input columns
|
||||
/// \endcode
|
||||
explicit CutOut(int32_t length, int32_t num_patches = 1);
|
||||
explicit CutOut(int32_t length, int32_t num_patches = 1, bool is_hwc = true);
|
||||
|
||||
/// \brief Destructor.
|
||||
~CutOut() = default;
|
||||
|
@ -404,6 +406,8 @@ class MS_API NormalizePad final : public TensorTransform {
|
|||
/// The standard deviation values must be in range (0.0, 255.0].
|
||||
/// \param[in] dtype The output datatype of Tensor.
|
||||
/// The standard deviation values must be "float32" or "float16"(default = "float32").
|
||||
/// \param[in] is_hwc A boolean to indicate whether the input image is in HWC format (true) or CHW
|
||||
/// format (false) (default = true).
|
||||
/// \par Example
|
||||
/// \code
|
||||
/// /* Define operations */
|
||||
|
@ -414,10 +418,12 @@ class MS_API NormalizePad final : public TensorTransform {
|
|||
/// dataset = dataset->Map({decode_op, normalize_pad_op}, // operations
|
||||
/// {"image"}); // input columns
|
||||
/// \endcode
|
||||
NormalizePad(const std::vector<float> &mean, const std::vector<float> &std, const std::string &dtype = "float32")
|
||||
: NormalizePad(mean, std, StringToChar(dtype)) {}
|
||||
NormalizePad(const std::vector<float> &mean, const std::vector<float> &std, const std::string &dtype = "float32",
|
||||
bool is_hwc = true)
|
||||
: NormalizePad(mean, std, StringToChar(dtype), is_hwc) {}
|
||||
|
||||
NormalizePad(const std::vector<float> &mean, const std::vector<float> &std, const std::vector<char> &dtype);
|
||||
NormalizePad(const std::vector<float> &mean, const std::vector<float> &std, const std::vector<char> &dtype,
|
||||
bool is_hwc = true);
|
||||
|
||||
/// \brief Destructor.
|
||||
~NormalizePad() = default;
|
||||
|
@ -1589,6 +1595,36 @@ class MS_API SwapRedBlue final : public TensorTransform {
|
|||
std::shared_ptr<TensorOperation> Parse() override;
|
||||
};
|
||||
|
||||
/// \brief Rescale to divide by 255 and convert from HWC format to CHW format with required datatype.
|
||||
/// \brief Default datatype is "float32".
|
||||
class MS_API ToTensor final : public TensorTransform {
|
||||
public:
|
||||
/// \brief Constructor.
|
||||
/// \param[in] output_type The type of the output tensor (default="float32").
|
||||
/// \par Example
|
||||
/// \code
|
||||
/// /* Define operations */
|
||||
/// auto to_tensor_op = vision::ToTensor();
|
||||
///
|
||||
/// /* dataset is an instance of Dataset object */
|
||||
/// dataset = dataset->Map({ToTensor}, // operations
|
||||
/// {"image"}); // input columns
|
||||
/// \endcode
|
||||
explicit ToTensor(std::string output_type = "float32");
|
||||
|
||||
/// \brief Destructor.
|
||||
~ToTensor() = default;
|
||||
|
||||
protected:
|
||||
/// \brief The function to convert a TensorTransform object into a TensorOperation object.
|
||||
/// \return Shared pointer to TensorOperation object.
|
||||
std::shared_ptr<TensorOperation> Parse() override;
|
||||
|
||||
private:
|
||||
struct Data;
|
||||
std::shared_ptr<Data> data_;
|
||||
};
|
||||
|
||||
/// \brief Randomly perform transformations, as selected from input transform list, on the input tensor.
|
||||
class MS_API UniformAugment final : public TensorTransform {
|
||||
public:
|
||||
|
|
|
@ -238,6 +238,9 @@ class MS_API Normalize final : public TensorTransform {
|
|||
/// The mean values must be in range [0.0, 255.0].
|
||||
/// \param[in] std A vector of standard deviations for each channel, with respect to channel order.
|
||||
/// The standard deviation values must be in range (0.0, 255.0].
|
||||
/// \param[in] is_hwc A boolean to indicate whether the input image is in HWC format (true) or CHW
|
||||
/// format (false) (Lite only supports true) (default = true).
|
||||
|
||||
/// \par Example
|
||||
/// \code
|
||||
/// /* Define operations */
|
||||
|
@ -248,7 +251,7 @@ class MS_API Normalize final : public TensorTransform {
|
|||
/// dataset = dataset->Map({decode_op, normalize_op}, // operations
|
||||
/// {"image"}); // input columns
|
||||
/// \endcode
|
||||
Normalize(const std::vector<float> &mean, const std::vector<float> &std);
|
||||
Normalize(const std::vector<float> &mean, const std::vector<float> &std, bool is_hwc = true);
|
||||
|
||||
/// \brief Destructor.
|
||||
~Normalize() = default;
|
||||
|
|
|
@ -116,8 +116,8 @@ TEST_F(MindDataTestPipeline, TestComposeFail2) {
|
|||
|
||||
// Compose: transform ops must not be null
|
||||
std::shared_ptr<TensorTransform> decode_op = std::make_shared<vision::Decode>();
|
||||
auto compose = std::make_shared<transforms::Compose>(
|
||||
std::vector<std::shared_ptr<TensorTransform>>{decode_op, nullptr});
|
||||
auto compose =
|
||||
std::make_shared<transforms::Compose>(std::vector<std::shared_ptr<TensorTransform>>{decode_op, nullptr});
|
||||
|
||||
// Create a Map operation on ds
|
||||
ds = ds->Map({compose}, {"image"});
|
||||
|
@ -1361,7 +1361,7 @@ TEST_F(MindDataTestPipeline, TestMaskFail2) {
|
|||
}
|
||||
|
||||
/// Feature: OneHot op
|
||||
/// Description: Test OneHot op basic usage
|
||||
/// Description: Test OneHot op basic usage with default smoothing value
|
||||
/// Expectation: Output is equal to the expected output
|
||||
TEST_F(MindDataTestPipeline, TestOneHotSuccess1) {
|
||||
MS_LOG(INFO) << "Doing MindDataTestPipeline-TestOneHotSuccess1.";
|
||||
|
@ -1479,6 +1479,52 @@ TEST_F(MindDataTestPipeline, TestOneHotSuccess2) {
|
|||
iter->Stop();
|
||||
}
|
||||
|
||||
/// Feature: OneHot op
|
||||
/// Description: Test OneHot op with non-default smoothing rate value
|
||||
/// Expectation: Rows in the dataset are iterated without failure
|
||||
TEST_F(MindDataTestPipeline, TestOneHotSuccess3) {
|
||||
MS_LOG(INFO) << "Doing MindDataTestPipeline-TestOneHotSuccess3.";
|
||||
// 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));
|
||||
EXPECT_NE(ds, nullptr);
|
||||
|
||||
// Create a Batch operation on ds
|
||||
int32_t batch_size = 5;
|
||||
ds = ds->Batch(batch_size);
|
||||
EXPECT_NE(ds, nullptr);
|
||||
|
||||
// Create objects for the tensor ops
|
||||
// Create OneHot op with non-default smoothing_rate
|
||||
std::shared_ptr<TensorTransform> one_hot_op = std::make_shared<transforms::OneHot>(10, 0.2);
|
||||
|
||||
// Create a Map operation on ds
|
||||
ds = ds->Map({one_hot_op}, {"label"});
|
||||
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;
|
||||
ASSERT_OK(iter->GetNextRow(&row));
|
||||
|
||||
uint64_t i = 0;
|
||||
while (row.size() != 0) {
|
||||
i++;
|
||||
auto image = row["image"];
|
||||
MS_LOG(INFO) << "Tensor image shape: " << image.Shape();
|
||||
ASSERT_OK(iter->GetNextRow(&row));
|
||||
}
|
||||
|
||||
EXPECT_EQ(i, 2);
|
||||
|
||||
// Manually terminate the pipeline
|
||||
iter->Stop();
|
||||
}
|
||||
|
||||
/// Feature: OneHot op
|
||||
/// Description: Test OneHot op with invalid num_class=0
|
||||
/// Expectation: Error message is logged, and CreateIterator() for invalid pipeline returns nullptr
|
||||
|
@ -1936,8 +1982,8 @@ TEST_F(MindDataTestPipeline, TestRandomApplyFail2) {
|
|||
|
||||
// RandomApply: transform ops must not be null
|
||||
std::shared_ptr<TensorTransform> decode_op = std::make_shared<vision::Decode>();
|
||||
auto random_apply = std::make_shared<transforms::RandomApply>(
|
||||
std::vector<std::shared_ptr<TensorTransform>>{decode_op, nullptr});
|
||||
auto random_apply =
|
||||
std::make_shared<transforms::RandomApply>(std::vector<std::shared_ptr<TensorTransform>>{decode_op, nullptr});
|
||||
|
||||
// Create a Map operation on ds
|
||||
ds = ds->Map({random_apply}, {"image"});
|
||||
|
@ -2081,8 +2127,8 @@ TEST_F(MindDataTestPipeline, TestRandomChoiceFail2) {
|
|||
|
||||
// RandomChoice: transform ops must not be null
|
||||
std::shared_ptr<TensorTransform> decode_op = std::make_shared<vision::Decode>();
|
||||
auto random_choice = std::make_shared<transforms::RandomApply>(
|
||||
std::vector<std::shared_ptr<TensorTransform>>{decode_op, nullptr});
|
||||
auto random_choice =
|
||||
std::make_shared<transforms::RandomApply>(std::vector<std::shared_ptr<TensorTransform>>{decode_op, nullptr});
|
||||
|
||||
// Create a Map operation on ds
|
||||
ds = ds->Map({random_choice}, {"image"});
|
||||
|
|
|
@ -677,10 +677,10 @@ TEST_F(MindDataTestPipeline, TestCutMixBatchFail4) {
|
|||
}
|
||||
|
||||
/// Feature: CutOut op
|
||||
/// Description: Test CutOut op basic usage
|
||||
/// Description: Test CutOut op basic usage with default HWC parameter
|
||||
/// Expectation: Output is equal to the expected output
|
||||
TEST_F(MindDataTestPipeline, TestCutOut) {
|
||||
MS_LOG(INFO) << "Doing MindDataTestPipeline-TestCutOut.";
|
||||
TEST_F(MindDataTestPipeline, TestCutOutDefaultHWC) {
|
||||
MS_LOG(INFO) << "Doing MindDataTestPipeline-TestCutOutDefaultHWC.";
|
||||
|
||||
// Create an ImageFolder Dataset
|
||||
std::string folder_path = datasets_root_path_ + "/testPK/data/";
|
||||
|
@ -729,6 +729,152 @@ TEST_F(MindDataTestPipeline, TestCutOut) {
|
|||
iter->Stop();
|
||||
}
|
||||
|
||||
/// Feature: CutOut op
|
||||
/// Description: Test CutOut op with HWC true and HWC input
|
||||
/// Expectation: Output is equal to the expected output
|
||||
TEST_F(MindDataTestPipeline, TestCutOutHWCTrueValid) {
|
||||
MS_LOG(INFO) << "Doing MindDataTestPipeline-TestCutOutHWCTrueValid.";
|
||||
|
||||
// Create an ImageFolder Dataset
|
||||
std::string folder_path = datasets_root_path_ + "/testPK/data/";
|
||||
std::shared_ptr<Dataset> ds = ImageFolder(folder_path, true, std::make_shared<RandomSampler>(false, 2));
|
||||
EXPECT_NE(ds, nullptr);
|
||||
|
||||
// Create objects for the tensor ops
|
||||
std::shared_ptr<TensorTransform> cut_out = std::make_shared<vision::CutOut>(30, 5, true);
|
||||
|
||||
// Create a Map operation on ds
|
||||
ds = ds->Map({cut_out});
|
||||
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;
|
||||
ASSERT_OK(iter->GetNextRow(&row));
|
||||
|
||||
uint64_t i = 0;
|
||||
while (row.size() != 0) {
|
||||
i++;
|
||||
auto image = row["image"];
|
||||
MS_LOG(INFO) << "Tensor image shape: " << image.Shape();
|
||||
ASSERT_OK(iter->GetNextRow(&row));
|
||||
}
|
||||
|
||||
EXPECT_EQ(i, 2);
|
||||
|
||||
// Manually terminate the pipeline
|
||||
iter->Stop();
|
||||
}
|
||||
|
||||
/// Feature: CutOut op
|
||||
/// Description: Test CutOut op with HWC false and HWC input
|
||||
/// Expectation: Error is caught for mismatched input image format (HWC)
|
||||
TEST_F(MindDataTestPipeline, TestCutOutHWCFalseInvalid) {
|
||||
MS_LOG(INFO) << "Doing MindDataTestPipeline-TestCutOutHWCFalseInvalid.";
|
||||
|
||||
// Create an ImageFolder Dataset
|
||||
std::string folder_path = datasets_root_path_ + "/testPK/data/";
|
||||
std::shared_ptr<Dataset> ds = ImageFolder(folder_path, true, std::make_shared<RandomSampler>(false, 2));
|
||||
EXPECT_NE(ds, nullptr);
|
||||
|
||||
// Create objects for the tensor ops
|
||||
std::shared_ptr<TensorTransform> cut_out = std::make_shared<vision::CutOut>(30, 5, false);
|
||||
|
||||
// Create a Map operation on ds
|
||||
ds = ds->Map({cut_out});
|
||||
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;
|
||||
ASSERT_ERROR(iter->GetNextRow(&row));
|
||||
// Manually terminate the pipeline
|
||||
iter->Stop();
|
||||
}
|
||||
|
||||
/// Feature: CutOut op
|
||||
/// Description: Test CutOut op with HWC true and CHW input
|
||||
/// Expectation: Error is caught for mismatched input image format (CHW)
|
||||
TEST_F(MindDataTestPipeline, TestCutOutHWCTrueInvalid) {
|
||||
MS_LOG(INFO) << "Doing MindDataTestPipeline-TestCutOutHWCTrueInvalid.";
|
||||
|
||||
// Create an ImageFolder Dataset
|
||||
std::string folder_path = datasets_root_path_ + "/testPK/data/";
|
||||
std::shared_ptr<Dataset> ds = ImageFolder(folder_path, true, std::make_shared<RandomSampler>(false, 2));
|
||||
EXPECT_NE(ds, nullptr);
|
||||
|
||||
// Create objects for the tensor ops
|
||||
auto cut_out = std::make_shared<vision::CutOut>(30, 5, true);
|
||||
// Op to convert input image format to CHW
|
||||
auto HWC2CHW = std::make_shared<vision::HWC2CHW>();
|
||||
|
||||
// Create a Map operation on ds
|
||||
ds = ds->Map({HWC2CHW, cut_out});
|
||||
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;
|
||||
ASSERT_ERROR(iter->GetNextRow(&row));
|
||||
// Manually terminate the pipeline
|
||||
iter->Stop();
|
||||
}
|
||||
|
||||
/// Feature: CutOut op
|
||||
/// Description: Test CutOut op with HWC false and CHW input
|
||||
/// Expectation: Output is equal to the expected output
|
||||
TEST_F(MindDataTestPipeline, TestCutOutHWCFalseValid) {
|
||||
MS_LOG(INFO) << "Doing MindDataTestPipeline-TestCutOutHWCFalseValid.";
|
||||
|
||||
// Create an ImageFolder Dataset
|
||||
std::string folder_path = datasets_root_path_ + "/testPK/data/";
|
||||
std::shared_ptr<Dataset> ds = ImageFolder(folder_path, true, std::make_shared<RandomSampler>(false, 2));
|
||||
EXPECT_NE(ds, nullptr);
|
||||
|
||||
// Create objects for the tensor ops
|
||||
auto cut_out = std::make_shared<vision::CutOut>(30, 5, false);
|
||||
// Op to convert input image format to CHW
|
||||
auto HWC2CHW = std::make_shared<vision::HWC2CHW>();
|
||||
|
||||
// Create a Map operation on ds
|
||||
ds = ds->Map({HWC2CHW, cut_out});
|
||||
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;
|
||||
ASSERT_OK(iter->GetNextRow(&row));
|
||||
|
||||
uint64_t i = 0;
|
||||
while (row.size() != 0) {
|
||||
i++;
|
||||
auto image = row["image"];
|
||||
MS_LOG(INFO) << "Tensor image shape: " << image.Shape();
|
||||
ASSERT_OK(iter->GetNextRow(&row));
|
||||
}
|
||||
|
||||
EXPECT_EQ(i, 2);
|
||||
|
||||
// Manually terminate the pipeline
|
||||
iter->Stop();
|
||||
}
|
||||
|
||||
/// Feature: Decode op
|
||||
/// Description: Test Decode op basic usage
|
||||
/// Expectation: Output is equal to the expected output
|
||||
|
@ -1059,10 +1205,10 @@ TEST_F(MindDataTestPipeline, TestMixUpBatchSuccess2) {
|
|||
}
|
||||
|
||||
/// Feature: Normalize op
|
||||
/// Description: Test Normalize op basic usage
|
||||
/// Description: Test Normalize op basic usage with default HWC parameter
|
||||
/// Expectation: Output is equal to the expected output
|
||||
TEST_F(MindDataTestPipeline, TestNormalize) {
|
||||
MS_LOG(INFO) << "Doing MindDataTestPipeline-TestNormalize.";
|
||||
TEST_F(MindDataTestPipeline, TestNormalizeDefaultHWC) {
|
||||
MS_LOG(INFO) << "Doing MindDataTestPipeline-TestNormalizeDefaultHWC.";
|
||||
|
||||
// Create an ImageFolder Dataset
|
||||
std::string folder_path = datasets_root_path_ + "/testPK/data/";
|
||||
|
@ -1075,8 +1221,8 @@ TEST_F(MindDataTestPipeline, TestNormalize) {
|
|||
EXPECT_NE(ds, nullptr);
|
||||
|
||||
// Create objects for the tensor ops
|
||||
auto normalize = std::make_shared<vision::Normalize>(
|
||||
std::vector<float>{121.0, 115.0, 0.0}, std::vector<float>{70.0, 68.0, 71.0});
|
||||
auto normalize =
|
||||
std::make_shared<vision::Normalize>(std::vector<float>{121.0, 115.0, 0.0}, std::vector<float>{70.0, 68.0, 71.0});
|
||||
// Note: No need to check for output after calling API class constructor
|
||||
|
||||
// Create a Map operation on ds
|
||||
|
@ -1111,11 +1257,157 @@ TEST_F(MindDataTestPipeline, TestNormalize) {
|
|||
iter->Stop();
|
||||
}
|
||||
|
||||
/// Feature: NormalizePad op
|
||||
/// Description: Test NormalizePad op basic usage
|
||||
/// Feature: Normalize op
|
||||
/// Description: Test Normalize HWC true and HWC input
|
||||
/// Expectation: Output is equal to the expected output
|
||||
TEST_F(MindDataTestPipeline, TestNormalizePad) {
|
||||
MS_LOG(INFO) << "Doing MindDataTestPipeline-TestNormalizePad.";
|
||||
TEST_F(MindDataTestPipeline, TestNormalizeHWCTrueValid) {
|
||||
MS_LOG(INFO) << "Doing MindDataTestPipeline-TestNormalizeHWCTrueValid.";
|
||||
|
||||
// Create an ImageFolder Dataset
|
||||
std::string folder_path = datasets_root_path_ + "/testPK/data/";
|
||||
std::shared_ptr<Dataset> ds = ImageFolder(folder_path, true, std::make_shared<RandomSampler>(false, 2));
|
||||
EXPECT_NE(ds, nullptr);
|
||||
|
||||
auto normalize = std::make_shared<vision::Normalize>(std::vector<float>{121.0, 115.0, 0.0},
|
||||
std::vector<float>{70.0, 68.0, 71.0}, true);
|
||||
|
||||
// Create a Map operation on ds
|
||||
ds = ds->Map({normalize});
|
||||
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;
|
||||
ASSERT_OK(iter->GetNextRow(&row));
|
||||
|
||||
uint64_t i = 0;
|
||||
while (row.size() != 0) {
|
||||
i++;
|
||||
auto image = row["image"];
|
||||
MS_LOG(INFO) << "Tensor image shape: " << image.Shape();
|
||||
ASSERT_OK(iter->GetNextRow(&row));
|
||||
}
|
||||
|
||||
EXPECT_EQ(i, 2);
|
||||
|
||||
// Manually terminate the pipeline
|
||||
iter->Stop();
|
||||
}
|
||||
|
||||
/// Feature: Normalize op
|
||||
/// Description: Test Normalize op with HWC false and HWC input
|
||||
/// Expectation: Error is caught for mismatched input image format (HWC)
|
||||
TEST_F(MindDataTestPipeline, TestNormalizeHWCFalseInvalid) {
|
||||
MS_LOG(INFO) << "Doing MindDataTestPipeline-TestNormalize.";
|
||||
|
||||
// Create an ImageFolder Dataset
|
||||
std::string folder_path = datasets_root_path_ + "/testPK/data/";
|
||||
std::shared_ptr<Dataset> ds = ImageFolder(folder_path, true, std::make_shared<RandomSampler>(false, 2));
|
||||
EXPECT_NE(ds, nullptr);
|
||||
|
||||
auto normalize = std::make_shared<vision::Normalize>(std::vector<float>{121.0, 115.0, 0.0},
|
||||
std::vector<float>{70.0, 68.0, 71.0}, false);
|
||||
|
||||
// Create a Map operation on ds
|
||||
ds = ds->Map({normalize});
|
||||
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;
|
||||
ASSERT_ERROR(iter->GetNextRow(&row));
|
||||
// Manually terminate the pipeline
|
||||
iter->Stop();
|
||||
}
|
||||
|
||||
/// Feature: Normalize op
|
||||
/// Description: Test Normalize op with HWC true and CHW input
|
||||
/// Expectation: Error is caught for mismatched input image format (CHW)
|
||||
TEST_F(MindDataTestPipeline, TestNormalizeHWCTrueInvalid) {
|
||||
MS_LOG(INFO) << "Doing MindDataTestPipeline-TestNormalizeHWCTrueInvalid.";
|
||||
|
||||
// Create an ImageFolder Dataset
|
||||
std::string folder_path = datasets_root_path_ + "/testPK/data/";
|
||||
std::shared_ptr<Dataset> ds = ImageFolder(folder_path, true, std::make_shared<RandomSampler>(false, 2));
|
||||
EXPECT_NE(ds, nullptr);
|
||||
|
||||
auto normalize = std::make_shared<vision::Normalize>(std::vector<float>{121.0, 115.0, 0.0},
|
||||
std::vector<float>{70.0, 68.0, 71.0}, true);
|
||||
|
||||
auto HWC2CHW = std::make_shared<vision::HWC2CHW>();
|
||||
|
||||
// Create a Map operation on ds
|
||||
ds = ds->Map({HWC2CHW, normalize});
|
||||
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;
|
||||
ASSERT_ERROR(iter->GetNextRow(&row));
|
||||
// Manually terminate the pipeline
|
||||
iter->Stop();
|
||||
}
|
||||
|
||||
/// Feature: Normalize op
|
||||
/// Description: Test Normalize op with CHW true and CHW input
|
||||
/// Expectation: Output is equal to the expected output
|
||||
TEST_F(MindDataTestPipeline, TestNormalizeHWCFalseValid) {
|
||||
MS_LOG(INFO) << "Doing MindDataTestPipeline-TestNormalizeHWCFalseValid.";
|
||||
|
||||
// Create an ImageFolder Dataset
|
||||
std::string folder_path = datasets_root_path_ + "/testPK/data/";
|
||||
std::shared_ptr<Dataset> ds = ImageFolder(folder_path, true, std::make_shared<RandomSampler>(false, 2));
|
||||
EXPECT_NE(ds, nullptr);
|
||||
|
||||
auto normalize = std::make_shared<vision::Normalize>(std::vector<float>{121.0, 115.0, 0.0},
|
||||
std::vector<float>{70.0, 68.0, 71.0}, false);
|
||||
|
||||
auto HWC2CHW = std::make_shared<vision::HWC2CHW>();
|
||||
|
||||
// Create a Map operation on ds
|
||||
ds = ds->Map({HWC2CHW, normalize});
|
||||
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;
|
||||
ASSERT_OK(iter->GetNextRow(&row));
|
||||
|
||||
uint64_t i = 0;
|
||||
while (row.size() != 0) {
|
||||
i++;
|
||||
auto image = row["image"];
|
||||
MS_LOG(INFO) << "Tensor image shape: " << image.Shape();
|
||||
ASSERT_OK(iter->GetNextRow(&row));
|
||||
}
|
||||
|
||||
EXPECT_EQ(i, 2);
|
||||
|
||||
// Manually terminate the pipeline
|
||||
iter->Stop();
|
||||
}
|
||||
|
||||
/// Feature: NormalizePad op
|
||||
/// Description: Test NormalizePad op basic usage with default HWC parameter
|
||||
/// Expectation: Output is equal to the expected output
|
||||
TEST_F(MindDataTestPipeline, TestNormalizePadDefault) {
|
||||
MS_LOG(INFO) << "Doing MindDataTestPipeline-TestNormalizePadDefault.";
|
||||
|
||||
// Create an ImageFolder Dataset
|
||||
std::string folder_path = datasets_root_path_ + "/testPK/data/";
|
||||
|
@ -1128,8 +1420,8 @@ TEST_F(MindDataTestPipeline, TestNormalizePad) {
|
|||
EXPECT_NE(ds, nullptr);
|
||||
|
||||
// Create objects for the tensor ops
|
||||
auto normalizepad = std::make_shared<vision::NormalizePad>(
|
||||
std::vector<float>{121.0, 115.0, 100.0}, std::vector<float>{70.0, 68.0, 71.0}, "float32");
|
||||
auto normalizepad = std::make_shared<vision::NormalizePad>(std::vector<float>{121.0, 115.0, 100.0},
|
||||
std::vector<float>{70.0, 68.0, 71.0}, "float32");
|
||||
// Note: No need to check for output after calling API class constructor
|
||||
|
||||
// Create a Map operation on ds
|
||||
|
@ -1161,6 +1453,220 @@ TEST_F(MindDataTestPipeline, TestNormalizePad) {
|
|||
iter->Stop();
|
||||
}
|
||||
|
||||
/// Feature: NormalizePad op
|
||||
/// Description: Test NormalizePad op with HWC true and HWC input
|
||||
/// Expectation: Output is equal to the expected output
|
||||
TEST_F(MindDataTestPipeline, TestNormalizePadHWCTrueValid) {
|
||||
MS_LOG(INFO) << "Doing MindDataTestPipeline-TestNormalizePadHWCTrueValid.";
|
||||
|
||||
// Create an ImageFolder Dataset
|
||||
std::string folder_path = datasets_root_path_ + "/testPK/data/";
|
||||
std::shared_ptr<Dataset> ds = ImageFolder(folder_path, true, std::make_shared<RandomSampler>(false, 2));
|
||||
EXPECT_NE(ds, nullptr);
|
||||
|
||||
// Create objects for the tensor ops
|
||||
auto normalizepad = std::make_shared<vision::NormalizePad>(std::vector<float>{121.0, 115.0, 100.0},
|
||||
std::vector<float>{70.0, 68.0, 71.0}, "float32", true);
|
||||
// Note: No need to check for output after calling API class constructor
|
||||
|
||||
// Create a Map operation on ds
|
||||
ds = ds->Map({normalizepad});
|
||||
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;
|
||||
ASSERT_OK(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()[2], 4);
|
||||
|
||||
ASSERT_OK(iter->GetNextRow(&row));
|
||||
}
|
||||
|
||||
EXPECT_EQ(i, 2);
|
||||
|
||||
// Manually terminate the pipeline
|
||||
iter->Stop();
|
||||
}
|
||||
|
||||
/// Feature: NormalizePad op
|
||||
/// Description: Test NormalizePad op with HWC false and HWC input
|
||||
/// Expectation: Error is caught for mismatched input image format (HWC)
|
||||
TEST_F(MindDataTestPipeline, TestNormalizePadHWCFalseInvalid) {
|
||||
MS_LOG(INFO) << "Doing MindDataTestPipeline-TestNormalizePadHWCFalseInvalid.";
|
||||
|
||||
// Create an ImageFolder Dataset
|
||||
std::string folder_path = datasets_root_path_ + "/testPK/data/";
|
||||
std::shared_ptr<Dataset> ds = ImageFolder(folder_path, true, std::make_shared<RandomSampler>(false, 2));
|
||||
EXPECT_NE(ds, nullptr);
|
||||
|
||||
// Create objects for the tensor ops
|
||||
auto normalizepad = std::make_shared<vision::NormalizePad>(std::vector<float>{121.0, 115.0, 100.0},
|
||||
std::vector<float>{70.0, 68.0, 71.0}, "float16", false);
|
||||
// Note: No need to check for output after calling API class constructor
|
||||
|
||||
// Create a Map operation on ds
|
||||
ds = ds->Map({normalizepad});
|
||||
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;
|
||||
ASSERT_ERROR(iter->GetNextRow(&row));
|
||||
|
||||
// Manually terminate the pipeline
|
||||
iter->Stop();
|
||||
}
|
||||
|
||||
/// Feature: NormalizePad op
|
||||
/// Description: Test NormalizePad op with HWC true and CHW input
|
||||
/// Expectation: Error is caught for mismatched input image format (CHW)
|
||||
TEST_F(MindDataTestPipeline, TestNormalizePadHWCTrueInvalid) {
|
||||
MS_LOG(INFO) << "Doing MindDataTestPipeline-TestNormalizePadHWCTrueInvalid.";
|
||||
|
||||
// Create an ImageFolder Dataset
|
||||
std::string folder_path = datasets_root_path_ + "/testPK/data/";
|
||||
std::shared_ptr<Dataset> ds = ImageFolder(folder_path, true, std::make_shared<RandomSampler>(false, 2));
|
||||
EXPECT_NE(ds, nullptr);
|
||||
|
||||
// Create objects for the tensor ops
|
||||
auto normalizepad = std::make_shared<vision::NormalizePad>(std::vector<float>{121.0, 115.0, 100.0},
|
||||
std::vector<float>{70.0, 68.0, 71.0}, "float32", true);
|
||||
// Note: No need to check for output after calling API class constructor
|
||||
|
||||
auto HWC2CHW = std::make_shared<vision::HWC2CHW>();
|
||||
|
||||
// Create a Map operation on ds
|
||||
ds = ds->Map({HWC2CHW, normalizepad});
|
||||
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;
|
||||
ASSERT_ERROR(iter->GetNextRow(&row));
|
||||
|
||||
// Manually terminate the pipeline
|
||||
iter->Stop();
|
||||
}
|
||||
|
||||
/// Feature: NormalizePad op
|
||||
/// Description: Test NormalizePad op with HWC false and CHW input
|
||||
/// Expectation: Output is equal to the expected output
|
||||
TEST_F(MindDataTestPipeline, TestNormalizePadHWCFalseValid) {
|
||||
MS_LOG(INFO) << "Doing MindDataTestPipeline-TestNormalizePadHWCFalseValid.";
|
||||
|
||||
// Create an ImageFolder Dataset
|
||||
std::string folder_path = datasets_root_path_ + "/testPK/data/";
|
||||
std::shared_ptr<Dataset> ds = ImageFolder(folder_path, true, std::make_shared<RandomSampler>(false, 2));
|
||||
EXPECT_NE(ds, nullptr);
|
||||
|
||||
// Create objects for the tensor ops
|
||||
auto normalizepad = std::make_shared<vision::NormalizePad>(std::vector<float>{121.0, 115.0, 100.0},
|
||||
std::vector<float>{70.0, 68.0, 71.0}, "float32", false);
|
||||
// Note: No need to check for output after calling API class constructor
|
||||
|
||||
auto HWC2CHW = std::make_shared<vision::HWC2CHW>();
|
||||
|
||||
// Create a Map operation on ds
|
||||
ds = ds->Map({HWC2CHW, normalizepad});
|
||||
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;
|
||||
ASSERT_OK(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()[2], 4032);
|
||||
|
||||
ASSERT_OK(iter->GetNextRow(&row));
|
||||
}
|
||||
|
||||
EXPECT_EQ(i, 2);
|
||||
|
||||
// Manually terminate the pipeline
|
||||
iter->Stop();
|
||||
}
|
||||
|
||||
/// Feature: NormalizePad op
|
||||
/// Description: Test NormalizePad op with invalid float64 dtype
|
||||
/// Expectation: Error is caught for invalid dtype provided
|
||||
TEST_F(MindDataTestPipeline, TestNormalizePadInvalidDTypeFloat64) {
|
||||
MS_LOG(INFO) << "Doing MindDataTestPipeline-TestNormalizePadInvalidDTypeFloat64.";
|
||||
|
||||
// Create an ImageFolder Dataset
|
||||
std::string folder_path = datasets_root_path_ + "/testPK/data/";
|
||||
std::shared_ptr<Dataset> ds = ImageFolder(folder_path, true, std::make_shared<RandomSampler>(false, 2));
|
||||
EXPECT_NE(ds, nullptr);
|
||||
|
||||
// Create objects for the tensor ops
|
||||
// Pass invalid dtype ("float64") to NormalizePad.
|
||||
auto normalizepad = std::make_shared<vision::NormalizePad>(std::vector<float>{121.0, 115.0, 100.0},
|
||||
std::vector<float>{70.0, 68.0, 71.0}, "float64", false);
|
||||
EXPECT_NE(normalizepad, nullptr);
|
||||
|
||||
// Create a Map operation on ds
|
||||
ds = ds->Map({normalizepad});
|
||||
EXPECT_NE(ds, nullptr);
|
||||
|
||||
// Create an iterator over the result of the above dataset.
|
||||
// Catch a nullptr from the iterator object.
|
||||
std::shared_ptr<Iterator> iter = ds->CreateIterator();
|
||||
EXPECT_EQ(iter, nullptr);
|
||||
}
|
||||
|
||||
/// Feature: NormalizePad op
|
||||
/// Description: Test NormalizePad op with invalid int32 dtype
|
||||
/// Expectation: Error is caught for invalid dtype provided
|
||||
TEST_F(MindDataTestPipeline, TestNormalizePadInvalidDTypeInt32) {
|
||||
MS_LOG(INFO) << "Doing MindDataTestPipeline-TestNormalizePadInvalidDTypeInt32.";
|
||||
|
||||
// Create an ImageFolder Dataset
|
||||
std::string folder_path = datasets_root_path_ + "/testPK/data/";
|
||||
std::shared_ptr<Dataset> ds = ImageFolder(folder_path, true, std::make_shared<RandomSampler>(false, 2));
|
||||
EXPECT_NE(ds, nullptr);
|
||||
|
||||
// Create objects for the tensor ops
|
||||
// Pass invalid dtype ("int32") to NormalizePad.
|
||||
auto normalizepad = std::make_shared<vision::NormalizePad>(std::vector<float>{121.0, 115.0, 100.0},
|
||||
std::vector<float>{70.0, 68.0, 71.0}, "int32", false);
|
||||
EXPECT_NE(normalizepad, nullptr);
|
||||
|
||||
// Create a Map operation on ds
|
||||
ds = ds->Map({normalizepad});
|
||||
EXPECT_NE(ds, nullptr);
|
||||
|
||||
// Create an iterator over the result of the above dataset.
|
||||
// Catch a nullptr from the iterator object.
|
||||
std::shared_ptr<Iterator> iter = ds->CreateIterator();
|
||||
EXPECT_EQ(iter, nullptr);
|
||||
}
|
||||
|
||||
/// Feature: Pad op
|
||||
/// Description: Test Pad op basic usage
|
||||
/// Expectation: Output is equal to the expected output
|
||||
|
@ -1178,12 +1684,11 @@ TEST_F(MindDataTestPipeline, TestPad) {
|
|||
EXPECT_NE(ds, nullptr);
|
||||
|
||||
// Create objects for the tensor ops
|
||||
auto pad_op1 = std::make_shared<vision::Pad>(
|
||||
std::vector<int32_t>{1, 2, 3, 4}, std::vector<uint8_t>{0}, BorderType::kSymmetric);
|
||||
auto pad_op2 = std::make_shared<vision::Pad>(
|
||||
std::vector<int32_t>{1}, std::vector<uint8_t>{1, 1, 1}, BorderType::kEdge);
|
||||
auto pad_op3 = std::make_shared<vision::Pad>(
|
||||
std::vector<int32_t>{1, 4});
|
||||
auto pad_op1 =
|
||||
std::make_shared<vision::Pad>(std::vector<int32_t>{1, 2, 3, 4}, std::vector<uint8_t>{0}, BorderType::kSymmetric);
|
||||
auto pad_op2 =
|
||||
std::make_shared<vision::Pad>(std::vector<int32_t>{1}, std::vector<uint8_t>{1, 1, 1}, BorderType::kEdge);
|
||||
auto pad_op3 = std::make_shared<vision::Pad>(std::vector<int32_t>{1, 4});
|
||||
// Note: No need to check for output after calling API class constructor
|
||||
|
||||
// Create a Map operation on ds
|
||||
|
|
|
@ -328,8 +328,8 @@ TEST_F(MindDataTestPipeline, TestRotateParamCheck) {
|
|||
|
||||
// Case 1: Size of center is not 2
|
||||
// Create objects for the tensor ops
|
||||
auto rotate1 = std::make_shared<vision::Rotate>(
|
||||
90.0, InterpolationMode::kNearestNeighbour, false, std::vector<float>{0.});
|
||||
auto rotate1 =
|
||||
std::make_shared<vision::Rotate>(90.0, InterpolationMode::kNearestNeighbour, false, std::vector<float>{0.});
|
||||
auto ds2 = ds->Map({rotate1});
|
||||
EXPECT_NE(ds2, nullptr);
|
||||
// Create an iterator over the result of the above dataset
|
||||
|
@ -339,8 +339,8 @@ TEST_F(MindDataTestPipeline, TestRotateParamCheck) {
|
|||
|
||||
// Case 2: Size of fill_value is not 1 or 3
|
||||
// Create objects for the tensor ops
|
||||
auto rotate2 = std::make_shared<vision::Rotate>(
|
||||
-30, InterpolationMode::kNearestNeighbour, false, std::vector<float>{1.0, 1.0}, std::vector<uint8_t>{2, 2});
|
||||
auto rotate2 = std::make_shared<vision::Rotate>(-30, InterpolationMode::kNearestNeighbour, false,
|
||||
std::vector<float>{1.0, 1.0}, std::vector<uint8_t>{2, 2});
|
||||
auto ds3 = ds->Map({rotate2});
|
||||
EXPECT_NE(ds3, nullptr);
|
||||
// Create an iterator over the result of the above dataset
|
||||
|
@ -363,8 +363,8 @@ TEST_F(MindDataTestPipeline, TestRotatePass) {
|
|||
// Create objects for the tensor ops
|
||||
auto resize = std::make_shared<vision::Resize>(std::vector<int32_t>{50, 25});
|
||||
|
||||
auto rotate = std::make_shared<vision::Rotate>(
|
||||
90, InterpolationMode::kLinear, true, std::vector<float>{-1, -1}, std::vector<uint8_t>{255, 255, 255});
|
||||
auto rotate = std::make_shared<vision::Rotate>(90, InterpolationMode::kLinear, true, std::vector<float>{-1, -1},
|
||||
std::vector<uint8_t>{255, 255, 255});
|
||||
|
||||
// Resize the image to 50 * 25
|
||||
ds = ds->Map({resize});
|
||||
|
@ -713,3 +713,82 @@ TEST_F(MindDataTestPipeline, TestRandomAdjustSharpnessInvalidDegree) {
|
|||
std::shared_ptr<Iterator> iter = ds->CreateIterator();
|
||||
EXPECT_EQ(iter, nullptr);
|
||||
}
|
||||
|
||||
/// Feature: ToTensor op
|
||||
/// Description: Test ToTensor op with default float32 type
|
||||
/// Expectation: Tensor type is changed to float32 and all rows iterated correctly
|
||||
TEST_F(MindDataTestPipeline, TestToTensorOpDefault) {
|
||||
MS_LOG(INFO) << "Doing MindDataTestPipeline-TestToTensorOpDefault.";
|
||||
|
||||
std::string MindDataPath = "data/dataset";
|
||||
std::string folder_path = MindDataPath + "/testImageNetData/train/";
|
||||
std::shared_ptr<Dataset> ds = ImageFolder(folder_path, true, std::make_shared<RandomSampler>(false, 2));
|
||||
EXPECT_NE(ds, nullptr);
|
||||
|
||||
auto to_tensor_op = vision::ToTensor();
|
||||
ds = ds->Map({to_tensor_op}, {"image"});
|
||||
EXPECT_NE(ds, nullptr);
|
||||
|
||||
std::shared_ptr<Iterator> iter = ds->CreateIterator();
|
||||
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 type: " << image.DataType();
|
||||
iter->GetNextRow(&row);
|
||||
}
|
||||
EXPECT_EQ(i, 2);
|
||||
iter->Stop();
|
||||
}
|
||||
|
||||
/// Feature: ToTensor op
|
||||
/// Description: Test ToTensor op with float64 type
|
||||
/// Expectation: Tensor type is changed to float64 and all rows iterated correctly
|
||||
TEST_F(MindDataTestPipeline, TestToTensorOpFloat64) {
|
||||
MS_LOG(INFO) << "Doing MindDataTestPipeline-TestToTensorOpFloat64.";
|
||||
|
||||
std::string MindDataPath = "data/dataset";
|
||||
std::string folder_path = MindDataPath + "/testImageNetData/train/";
|
||||
std::shared_ptr<Dataset> ds = ImageFolder(folder_path, true, std::make_shared<RandomSampler>(false, 2));
|
||||
EXPECT_NE(ds, nullptr);
|
||||
|
||||
auto to_tensor_op = vision::ToTensor("float64");
|
||||
ds = ds->Map({to_tensor_op}, {"image"});
|
||||
EXPECT_NE(ds, nullptr);
|
||||
|
||||
std::shared_ptr<Iterator> iter = ds->CreateIterator();
|
||||
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 type: " << image.DataType();
|
||||
iter->GetNextRow(&row);
|
||||
}
|
||||
EXPECT_EQ(i, 2);
|
||||
iter->Stop();
|
||||
}
|
||||
|
||||
/// Feature: ToTensor op
|
||||
/// Description: Test ToTensor op with default float64 type
|
||||
/// Expectation: Tensor type is changed to float64 and all rows iterated correctly
|
||||
TEST_F(MindDataTestPipeline, TestToTensorOpInvalidInput) {
|
||||
MS_LOG(INFO) << "Doing MindDataTestPipeline-TestToTensorOpInvalidInput.";
|
||||
|
||||
std::string MindDataPath = "data/dataset";
|
||||
std::string folder_path = MindDataPath + "/testImageNetData/train/";
|
||||
std::shared_ptr<Dataset> ds = ImageFolder(folder_path, true, std::make_shared<RandomSampler>(false, 2));
|
||||
EXPECT_NE(ds, nullptr);
|
||||
|
||||
auto type_cast = transforms::TypeCast(mindspore::DataType::kNumberTypeUInt32);
|
||||
auto to_tensor_op = vision::ToTensor("float64");
|
||||
ds = ds->Map({type_cast, to_tensor_op}, {"image"});
|
||||
EXPECT_NE(ds, nullptr);
|
||||
|
||||
std::shared_ptr<Iterator> iter = ds->CreateIterator();
|
||||
std::unordered_map<std::string, mindspore::MSTensor> row;
|
||||
ASSERT_ERROR(iter->GetNextRow(&row));
|
||||
}
|
|
@ -21,7 +21,7 @@ using namespace mindspore::dataset;
|
|||
|
||||
class MindDataTestOneHotOp : public UT::Common {
|
||||
protected:
|
||||
MindDataTestOneHotOp() {}
|
||||
MindDataTestOneHotOp() {}
|
||||
};
|
||||
|
||||
/// Feature: OneHot op
|
||||
|
|
|
@ -0,0 +1,183 @@
|
|||
/**
|
||||
* Copyright 2022 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 <memory>
|
||||
#include <string>
|
||||
#include "common/common.h"
|
||||
#include "common/cvop_common.h"
|
||||
#include "minddata/dataset/kernels/image/to_tensor_op.h"
|
||||
#include "minddata/dataset/kernels/data/type_cast_op.h"
|
||||
#include "minddata/dataset/core/client.h"
|
||||
#include "minddata/dataset/core/data_type.h"
|
||||
#include "minddata/dataset/core/tensor.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include "securec.h"
|
||||
|
||||
namespace common = mindspore::common;
|
||||
using namespace mindspore::dataset;
|
||||
|
||||
class MindDataTestToTensorOp : public UT::CVOP::CVOpCommon {
|
||||
public:
|
||||
MindDataTestToTensorOp() : CVOpCommon() {}
|
||||
};
|
||||
|
||||
/// Feature: ToTensor Op
|
||||
/// Description: Check type changing with ToTensor C op to int8
|
||||
/// Expectation: Run successfully
|
||||
TEST_F(MindDataTestToTensorOp, TestToTensorOpInt8) {
|
||||
MS_LOG(INFO) << "Doing MindDataTestToTensorOp::TestToTensorOpInt8.";
|
||||
auto to_tensor_op = std::make_unique<ToTensorOp>("int8");
|
||||
std::shared_ptr<Tensor> output_tensor;
|
||||
Status s = to_tensor_op->Compute(input_tensor_, &output_tensor);
|
||||
ASSERT_TRUE(DataType("int8") == output_tensor->type());
|
||||
}
|
||||
|
||||
/// Feature: ToTensor Op
|
||||
/// Description: Check type changing with ToTensor C op to int16
|
||||
/// Expectation: Run successfully
|
||||
TEST_F(MindDataTestToTensorOp, TestToTensorOpInt16) {
|
||||
MS_LOG(INFO) << "Doing MindDataTestToTensorOp::TestToTensorOpInt16.";
|
||||
auto to_tensor_op = std::make_unique<ToTensorOp>("int16");
|
||||
std::shared_ptr<Tensor> output_tensor;
|
||||
Status s = to_tensor_op->Compute(input_tensor_, &output_tensor);
|
||||
ASSERT_TRUE(DataType("int16") == output_tensor->type());
|
||||
}
|
||||
|
||||
/// Feature: ToTensor Op
|
||||
/// Description: Check type changing with ToTensor C op to int32
|
||||
/// Expectation: Run successfully
|
||||
TEST_F(MindDataTestToTensorOp, TestToTensorOpInt32) {
|
||||
MS_LOG(INFO) << "Doing MindDataTestToTensorOp::TestToTensorOpInt32.";
|
||||
auto to_tensor_op = std::make_unique<ToTensorOp>("int32");
|
||||
std::shared_ptr<Tensor> output_tensor;
|
||||
Status s = to_tensor_op->Compute(input_tensor_, &output_tensor);
|
||||
ASSERT_TRUE(DataType("int32") == output_tensor->type());
|
||||
}
|
||||
|
||||
/// Feature: ToTensor Op
|
||||
/// Description: Check type changing with ToTensor C op to int64
|
||||
/// Expectation: Run successfully
|
||||
TEST_F(MindDataTestToTensorOp, TestToTensorOpInt64) {
|
||||
MS_LOG(INFO) << "Doing MindDataTestToTensorOp::TestToTensorOpInt64.";
|
||||
auto to_tensor_op = std::make_unique<ToTensorOp>("int64");
|
||||
std::shared_ptr<Tensor> output_tensor;
|
||||
Status s = to_tensor_op->Compute(input_tensor_, &output_tensor);
|
||||
ASSERT_TRUE(DataType("int64") == output_tensor->type());
|
||||
}
|
||||
|
||||
/// Feature: ToTensor Op
|
||||
/// Description: Check type changing with ToTensor C op to float16
|
||||
/// Expectation: Run successfully
|
||||
TEST_F(MindDataTestToTensorOp, TestToTensorOpFloat16) {
|
||||
MS_LOG(INFO) << "Doing MindDataTestToTensorOp::TestToTensorOpFloat16.";
|
||||
auto to_tensor_op = std::make_unique<ToTensorOp>("float16");
|
||||
std::shared_ptr<Tensor> output_tensor;
|
||||
Status s = to_tensor_op->Compute(input_tensor_, &output_tensor);
|
||||
ASSERT_TRUE(DataType("float16") == output_tensor->type());
|
||||
}
|
||||
|
||||
/// Feature: ToTensor Op
|
||||
/// Description: Check type changing with ToTensor C op to float32
|
||||
/// Expectation: Run successfully
|
||||
TEST_F(MindDataTestToTensorOp, TestToTensorOpFloat32) {
|
||||
MS_LOG(INFO) << "Doing MindDataTestToTensorOp::TestToTensorOpFloat32.";
|
||||
auto to_tensor_op = std::make_unique<ToTensorOp>("float32");
|
||||
std::shared_ptr<Tensor> output_tensor;
|
||||
Status s = to_tensor_op->Compute(input_tensor_, &output_tensor);
|
||||
ASSERT_TRUE(DataType("float32") == output_tensor->type());
|
||||
}
|
||||
|
||||
/// Feature: ToTensor Op
|
||||
/// Description: Check type changing with ToTensor C op to float64
|
||||
/// Expectation: Run successfully
|
||||
TEST_F(MindDataTestToTensorOp, TestToTensorOpFloat64) {
|
||||
MS_LOG(INFO) << "Doing MindDataTestToTensorOp::TestToTensorOpFloat64.";
|
||||
auto to_tensor_op = std::make_unique<ToTensorOp>("float64");
|
||||
std::shared_ptr<Tensor> output_tensor;
|
||||
Status s = to_tensor_op->Compute(input_tensor_, &output_tensor);
|
||||
ASSERT_TRUE(DataType("float64") == output_tensor->type());
|
||||
}
|
||||
|
||||
/// Feature: ToTensor Op
|
||||
/// Description: Check type changing with ToTensor C op to float32 with uint32 type input
|
||||
/// Expectation: Catch error for invalid type
|
||||
TEST_F(MindDataTestToTensorOp, TestToTensorOpInputUInt32Invalid) {
|
||||
MS_LOG(INFO) << "Doing MindDataTestToTensorOp::TestToTensorOpInputUInt32Invalid.";
|
||||
|
||||
// Cast uint8 input to invalid uint32 type for ToTensor Op
|
||||
auto type_cast_op = std::make_unique<TypeCastOp>("uint32");
|
||||
std::shared_ptr<Tensor> interim_tensor;
|
||||
Status s_cast = type_cast_op->Compute(input_tensor_, &interim_tensor);
|
||||
ASSERT_OK(s_cast);
|
||||
|
||||
auto to_tensor_op = std::make_unique<ToTensorOp>("float32");
|
||||
std::shared_ptr<Tensor> output_tensor;
|
||||
Status s_to_tensor = to_tensor_op->Compute(interim_tensor, &output_tensor);
|
||||
ASSERT_ERROR(s_to_tensor);
|
||||
}
|
||||
|
||||
/// Feature: ToTensor Op
|
||||
/// Description: Check type changing with ToTensor C op to float32 with uint64 type input
|
||||
/// Expectation: Catch error for invalid type
|
||||
TEST_F(MindDataTestToTensorOp, TestToTensorOpInputUInt64Invalid) {
|
||||
MS_LOG(INFO) << "Doing MindDataTestToTensorOp::TestToTensorOpInputUInt64Invalid.";
|
||||
|
||||
// Cast uint8 input to invalid uint64 type for ToTensor Op
|
||||
auto type_cast_op = std::make_unique<TypeCastOp>("uint64");
|
||||
std::shared_ptr<Tensor> interim_tensor;
|
||||
Status s_cast = type_cast_op->Compute(input_tensor_, &interim_tensor);
|
||||
ASSERT_OK(s_cast);
|
||||
|
||||
auto to_tensor_op = std::make_unique<ToTensorOp>("float32");
|
||||
std::shared_ptr<Tensor> output_tensor;
|
||||
Status s_to_tensor = to_tensor_op->Compute(interim_tensor, &output_tensor);
|
||||
ASSERT_ERROR(s_to_tensor);
|
||||
}
|
||||
|
||||
/// Feature: ToTensor Op
|
||||
/// Description: Check type changing with ToTensor C op to float32 with int64 type input
|
||||
/// Expectation: Catch error for invalid type
|
||||
TEST_F(MindDataTestToTensorOp, TestToTensorOpInputInt64Invalid) {
|
||||
MS_LOG(INFO) << "Doing MindDataTestToTensorOp::TestToTensorOpInputInt64Invalid.";
|
||||
|
||||
// Cast uint8 input to invalid int64 type for ToTensor Op
|
||||
auto type_cast_op = std::make_unique<TypeCastOp>("int64");
|
||||
std::shared_ptr<Tensor> interim_tensor;
|
||||
Status s_cast = type_cast_op->Compute(input_tensor_, &interim_tensor);
|
||||
ASSERT_OK(s_cast);
|
||||
|
||||
auto to_tensor_op = std::make_unique<ToTensorOp>("float32");
|
||||
std::shared_ptr<Tensor> output_tensor;
|
||||
Status s_to_tensor = to_tensor_op->Compute(interim_tensor, &output_tensor);
|
||||
ASSERT_ERROR(s_to_tensor);
|
||||
}
|
||||
|
||||
/// Feature: ToTensor Op
|
||||
/// Description: Check type changing with ToTensor C op to float32 with string type input
|
||||
/// Expectation: Catch error for invalid type
|
||||
TEST_F(MindDataTestToTensorOp, TestToTensorOpInputStringInvalid) {
|
||||
MS_LOG(INFO) << "Doing MindDataTestToTensorOp::TestToTensorOpInputStringInvalid.";
|
||||
|
||||
// Create string tensor and shape as a 3D input
|
||||
std::vector<std::string> strings{"1", "2", "3", "4", "5", "6"};
|
||||
std::shared_ptr<Tensor> string_tensor;
|
||||
Tensor::CreateFromVector(strings, TensorShape({1, 2, 3}), &string_tensor);
|
||||
|
||||
auto to_tensor_op = std::make_unique<ToTensorOp>("float32");
|
||||
std::shared_ptr<Tensor> output_tensor;
|
||||
Status s_to_tensor = to_tensor_op->Compute(string_tensor, &output_tensor);
|
||||
ASSERT_ERROR(s_to_tensor);
|
||||
}
|
Loading…
Reference in New Issue