From 3322e65da9db2625d390de0be3d7b9e4e64331f5 Mon Sep 17 00:00:00 2001 From: Adel Shafiei Date: Fri, 24 Apr 2020 15:21:43 -0400 Subject: [PATCH] added ut for uniform augment C++ op --- .../ccsrc/mindrecord/common/shard_utils.cc | 2 +- mindspore/ccsrc/mindrecord/io/shard_reader.cc | 2 +- .../ut/python/dataset/test_uniform_augment.py | 62 +++++++++++++++++++ 3 files changed, 64 insertions(+), 2 deletions(-) diff --git a/mindspore/ccsrc/mindrecord/common/shard_utils.cc b/mindspore/ccsrc/mindrecord/common/shard_utils.cc index 51de0c5f6..edeabb3cd 100644 --- a/mindspore/ccsrc/mindrecord/common/shard_utils.cc +++ b/mindspore/ccsrc/mindrecord/common/shard_utils.cc @@ -39,7 +39,7 @@ std::vector StringSplit(const std::string &field, char separator) { } s_pos = e_pos + 1; } - return std::move(res); + return res; } bool ValidateFieldName(const std::string &str) { diff --git a/mindspore/ccsrc/mindrecord/io/shard_reader.cc b/mindspore/ccsrc/mindrecord/io/shard_reader.cc index 4cbb2b376..804613e40 100644 --- a/mindspore/ccsrc/mindrecord/io/shard_reader.cc +++ b/mindspore/ccsrc/mindrecord/io/shard_reader.cc @@ -914,7 +914,7 @@ vector ShardReader::GetAllColumns() { } else { columns = selected_columns_; } - return std::move(columns); + return columns; } MSRStatus ShardReader::CreateTasksByBlock(const std::vector> &row_group_summary, diff --git a/tests/ut/python/dataset/test_uniform_augment.py b/tests/ut/python/dataset/test_uniform_augment.py index ce0490336..ea9905611 100644 --- a/tests/ut/python/dataset/test_uniform_augment.py +++ b/tests/ut/python/dataset/test_uniform_augment.py @@ -18,6 +18,7 @@ import matplotlib.pyplot as plt from mindspore import log as logger import mindspore.dataset.engine as de import mindspore.dataset.transforms.vision.py_transforms as F +import mindspore.dataset.transforms.vision.c_transforms as C DATA_DIR = "../data/dataset/testImageNetData/train/" @@ -101,7 +102,68 @@ def test_uniform_augment(plot=False, num_ops=2): if plot: visualize(images_original, images_ua) +def test_cpp_uniform_augment(plot=False, num_ops=2): + """ + Test UniformAugment + """ + logger.info("Test CPP UniformAugment") + + # Original Images + ds = de.ImageFolderDatasetV2(dataset_dir=DATA_DIR, shuffle=False) + + transforms_original = [C.Decode(), C.Resize(size=[224, 224]), + F.ToTensor()] + + ds_original = ds.map(input_columns="image", + operations=transforms_original) + + ds_original = ds_original.batch(512) + + for idx, (image,label) in enumerate(ds_original): + if idx == 0: + images_original = np.transpose(image, (0, 2, 3, 1)) + else: + images_original = np.append(images_original, + np.transpose(image, (0, 2, 3, 1)), + axis=0) + + + # UniformAugment Images + ds = de.ImageFolderDatasetV2(dataset_dir=DATA_DIR, shuffle=False) + transforms_ua = [C.RandomCrop(size=[224, 224], padding=[32, 32, 32, 32]), + C.RandomHorizontalFlip(), + C.RandomVerticalFlip(), + C.RandomColorAdjust(), + C.RandomRotation(degrees=45)] + + uni_aug = C.UniformAugment(operations=transforms_ua, num_ops=num_ops) + + transforms_all = [C.Decode(), C.Resize(size=[224, 224]), + uni_aug, + F.ToTensor()] + + ds_ua = ds.map(input_columns="image", + operations=transforms_all, num_parallel_workers=1) + + ds_ua = ds_ua.batch(512) + + for idx, (image,label) in enumerate(ds_ua): + if idx == 0: + images_ua = np.transpose(image, (0, 2, 3, 1)) + else: + images_ua = np.append(images_ua, + np.transpose(image, (0, 2, 3, 1)), + axis=0) + if plot: + visualize(images_original, images_ua) + + num_samples = images_original.shape[0] + mse = np.zeros(num_samples) + for i in range(num_samples): + mse[i] = np.mean((images_ua[i] - images_original[i]) ** 2) + logger.info("MSE= {}".format(str(np.mean(mse)))) if __name__ == "__main__": test_uniform_augment(num_ops=1) + test_cpp_uniform_augment(num_ops=1) -- GitLab