From 94a4a3f20b1fb12f80e1ae6d7841777806f6f5c2 Mon Sep 17 00:00:00 2001 From: islam_amin Date: Tue, 25 Aug 2020 14:43:13 -0400 Subject: [PATCH] changing affine and posterize apis --- .../dataset/kernels/image/bindings.cc | 2 +- .../ccsrc/minddata/dataset/api/transforms.cc | 77 +++++++++++++----- .../minddata/dataset/include/transforms.h | 23 +++--- .../dataset/kernels/image/random_affine_op.cc | 12 +-- .../kernels/image/random_posterize_op.cc | 10 +-- .../kernels/image/random_posterize_op.h | 11 +-- .../dataset/transforms/vision/c_transforms.py | 24 ++++-- .../dataset/transforms/vision/validators.py | 6 +- tests/ut/cpp/dataset/c_api_transforms_test.cc | 17 ++-- tests/ut/cpp/dataset/random_affine_op_test.cc | 5 +- .../cpp/dataset/random_posterize_op_test.cc | 2 +- .../golden/random_affine_01_c_result.npz | Bin 644 -> 644 bytes .../random_affine_01_default_c_result.npz | Bin 0 -> 644 bytes .../random_posterize_01_default_result_c.npz | Bin 0 -> 644 bytes tests/ut/python/dataset/test_random_affine.py | 45 ++++++++-- .../python/dataset/test_random_posterize.py | 44 ++++++++++ 16 files changed, 202 insertions(+), 76 deletions(-) create mode 100644 tests/ut/data/dataset/golden/random_affine_01_default_c_result.npz create mode 100644 tests/ut/data/dataset/golden/random_posterize_01_default_result_c.npz diff --git a/mindspore/ccsrc/minddata/dataset/api/python/bindings/dataset/kernels/image/bindings.cc b/mindspore/ccsrc/minddata/dataset/api/python/bindings/dataset/kernels/image/bindings.cc index 326b8c0381..bf2cb2ba4e 100644 --- a/mindspore/ccsrc/minddata/dataset/api/python/bindings/dataset/kernels/image/bindings.cc +++ b/mindspore/ccsrc/minddata/dataset/api/python/bindings/dataset/kernels/image/bindings.cc @@ -131,7 +131,7 @@ PYBIND_REGISTER(RandomResizeWithBBoxOp, 1, ([](const py::module *m) { PYBIND_REGISTER(RandomPosterizeOp, 1, ([](const py::module *m) { (void)py::class_>(*m, "RandomPosterizeOp") - .def(py::init()); + .def(py::init>()); })); PYBIND_REGISTER(UniformAugOp, 1, ([](const py::module *m) { diff --git a/mindspore/ccsrc/minddata/dataset/api/transforms.cc b/mindspore/ccsrc/minddata/dataset/api/transforms.cc index 4a92193df8..d46ec291a8 100644 --- a/mindspore/ccsrc/minddata/dataset/api/transforms.cc +++ b/mindspore/ccsrc/minddata/dataset/api/transforms.cc @@ -219,8 +219,8 @@ std::shared_ptr RandomHorizontalFlip(float prob) } // Function to create RandomPosterizeOperation. -std::shared_ptr RandomPosterize(uint8_t min_bit, uint8_t max_bit) { - auto op = std::make_shared(min_bit, max_bit); +std::shared_ptr RandomPosterize(const std::vector &bit_range) { + auto op = std::make_shared(bit_range); // Input validation if (!op->ValidateParams()) { return nullptr; @@ -383,7 +383,7 @@ CutMixBatchOperation::CutMixBatchOperation(ImageBatchFormat image_batch_format, bool CutMixBatchOperation::ValidateParams() { if (alpha_ <= 0) { - MS_LOG(ERROR) << "CutMixBatch: alpha cannot be negative."; + MS_LOG(ERROR) << "CutMixBatch: alpha must be a positive floating value however it is: " << alpha_; return false; } if (prob_ < 0 || prob_ > 1) { @@ -616,7 +616,7 @@ RandomAffineOperation::RandomAffineOperation(const std::vector °rees bool RandomAffineOperation::ValidateParams() { // Degrees if (degrees_.size() != 2) { - MS_LOG(ERROR) << "RandomAffine: degrees vector has incorrect size: degrees.size() = " << degrees_.size(); + MS_LOG(ERROR) << "RandomAffine: degrees expecting size 2, got: degrees.size() = " << degrees_.size(); return false; } if (degrees_[0] > degrees_[1]) { @@ -625,16 +625,43 @@ bool RandomAffineOperation::ValidateParams() { return false; } // Translate - if (translate_range_.size() != 2) { - MS_LOG(ERROR) << "RandomAffine: translate_range vector has incorrect size: translate_range.size() = " + if (translate_range_.size() != 2 && translate_range_.size() != 4) { + MS_LOG(ERROR) << "RandomAffine: translate_range expecting size 2 or 4, got: translate_range.size() = " << translate_range_.size(); return false; } if (translate_range_[0] > translate_range_[1]) { - MS_LOG(ERROR) << "RandomAffine: minimum of translate range is greater than maximum: min = " << translate_range_[0] - << ", max = " << translate_range_[1]; + MS_LOG(ERROR) << "RandomAffine: minimum of translate range on x is greater than maximum: min = " + << translate_range_[0] << ", max = " << translate_range_[1]; return false; } + if (translate_range_[0] < -1 || translate_range_[0] > 1) { + MS_LOG(ERROR) << "RandomAffine: minimum of translate range on x is out of range of [-1, 1], value = " + << translate_range_[0]; + return false; + } + if (translate_range_[1] < -1 || translate_range_[1] > 1) { + MS_LOG(ERROR) << "RandomAffine: maximum of translate range on x is out of range of [-1, 1], value = " + << translate_range_[1]; + return false; + } + if (translate_range_.size() == 4) { + if (translate_range_[2] > translate_range_[3]) { + MS_LOG(ERROR) << "RandomAffine: minimum of translate range on y is greater than maximum: min = " + << translate_range_[2] << ", max = " << translate_range_[3]; + return false; + } + if (translate_range_[2] < -1 || translate_range_[2] > 1) { + MS_LOG(ERROR) << "RandomAffine: minimum of translate range on y is out of range of [-1, 1], value = " + << translate_range_[2]; + return false; + } + if (translate_range_[3] < -1 || translate_range_[3] > 1) { + MS_LOG(ERROR) << "RandomAffine: maximum of translate range on y is out of range of [-1, 1], value = " + << translate_range_[3]; + return false; + } + } // Scale if (scale_range_.size() != 2) { MS_LOG(ERROR) << "RandomAffine: scale_range vector has incorrect size: scale_range.size() = " @@ -647,8 +674,8 @@ bool RandomAffineOperation::ValidateParams() { return false; } // Shear - if (shear_ranges_.size() != 4) { - MS_LOG(ERROR) << "RandomAffine: shear_ranges vector has incorrect size: shear_ranges.size() = " + if (shear_ranges_.size() != 2 && shear_ranges_.size() != 4) { + MS_LOG(ERROR) << "RandomAffine: shear_ranges expecting size 2 or 4, got: shear_ranges.size() = " << shear_ranges_.size(); return false; } @@ -657,7 +684,7 @@ bool RandomAffineOperation::ValidateParams() { << shear_ranges_[0] << ", max = " << shear_ranges_[1]; return false; } - if (shear_ranges_[2] > shear_ranges_[3]) { + if (shear_ranges_.size() == 4 && shear_ranges_[2] > shear_ranges_[3]) { MS_LOG(ERROR) << "RandomAffine: minimum of vertical shear range is greater than maximum: min = " << shear_ranges_[2] << ", max = " << scale_range_[3]; return false; @@ -671,6 +698,12 @@ bool RandomAffineOperation::ValidateParams() { } std::shared_ptr RandomAffineOperation::Build() { + if (shear_ranges_.size() == 2) { + shear_ranges_.resize(4); + } + if (translate_range_.size() == 2) { + translate_range_.resize(4); + } auto tensor_op = std::make_shared(degrees_, translate_range_, scale_range_, shear_ranges_, interpolation_, fill_value_); return tensor_op; @@ -737,27 +770,31 @@ std::shared_ptr RandomHorizontalFlipOperation::Build() { } // RandomPosterizeOperation -RandomPosterizeOperation::RandomPosterizeOperation(uint8_t min_bit, uint8_t max_bit) - : min_bit_(min_bit), max_bit_(max_bit) {} +RandomPosterizeOperation::RandomPosterizeOperation(const std::vector &bit_range) : bit_range_(bit_range) {} bool RandomPosterizeOperation::ValidateParams() { - if (min_bit_ < 1 || min_bit_ > 8) { - MS_LOG(ERROR) << "RandomPosterize: min_bit value is out of range [1-8]: " << min_bit_; + if (bit_range_.size() != 2) { + MS_LOG(ERROR) << "RandomPosterize: bit_range needs to be of size 2 but is of size: " << bit_range_.size(); + return false; + } + if (bit_range_[0] < 1 || bit_range_[0] > 8) { + MS_LOG(ERROR) << "RandomPosterize: min_bit value is out of range [1-8]: " << bit_range_[0]; return false; } - if (max_bit_ < 1 || max_bit_ > 8) { - MS_LOG(ERROR) << "RandomPosterize: max_bit value is out of range [1-8]: " << max_bit_; + if (bit_range_[1] < 1 || bit_range_[1] > 8) { + MS_LOG(ERROR) << "RandomPosterize: max_bit value is out of range [1-8]: " << bit_range_[1]; return false; } - if (max_bit_ < min_bit_) { - MS_LOG(ERROR) << "RandomPosterize: max_bit value is less than min_bit: max =" << max_bit_ << ", min = " << min_bit_; + if (bit_range_[1] < bit_range_[0]) { + MS_LOG(ERROR) << "RandomPosterize: max_bit value is less than min_bit: max =" << bit_range_[1] + << ", min = " << bit_range_[0]; return false; } return true; } std::shared_ptr RandomPosterizeOperation::Build() { - std::shared_ptr tensor_op = std::make_shared(min_bit_, max_bit_); + std::shared_ptr tensor_op = std::make_shared(bit_range_); return tensor_op; } diff --git a/mindspore/ccsrc/minddata/dataset/include/transforms.h b/mindspore/ccsrc/minddata/dataset/include/transforms.h index bcc6452a35..322794cbff 100644 --- a/mindspore/ccsrc/minddata/dataset/include/transforms.h +++ b/mindspore/ccsrc/minddata/dataset/include/transforms.h @@ -161,16 +161,21 @@ std::shared_ptr Pad(std::vector padding, std::vector RandomAffine( - const std::vector °rees, const std::vector &translate_range = {0.0, 0.0}, + const std::vector °rees, const std::vector &translate_range = {0.0, 0.0, 0.0, 0.0}, const std::vector &scale_range = {1.0, 1.0}, const std::vector &shear_ranges = {0.0, 0.0, 0.0, 0.0}, InterpolationMode interpolation = InterpolationMode::kNearestNeighbour, const std::vector &fill_value = {0, 0, 0}); @@ -223,10 +228,9 @@ std::shared_ptr RandomHorizontalFlip(float prob = /// \brief Function to create a RandomPosterize TensorOperation. /// \notes Tensor operation to perform random posterize. -/// \param[in] min_bit - uint8_t representing the minimum bit in range. (Default=8) -/// \param[in] max_bit - uint8_t representing the maximum bit in range. (Default=8) +/// \param[in] bit_range - uint8_t vector representing the minimum and maximum bit in range. (Default={4, 8}) /// \return Shared pointer to the current TensorOperation. -std::shared_ptr RandomPosterize(uint8_t min_bit = 8, uint8_t max_bit = 8); +std::shared_ptr RandomPosterize(const std::vector &bit_range = {4, 8}); /// \brief Function to create a RandomRotation TensorOp /// \notes Rotates the image according to parameters @@ -530,7 +534,7 @@ class RandomHorizontalFlipOperation : public TensorOperation { class RandomPosterizeOperation : public TensorOperation { public: - explicit RandomPosterizeOperation(uint8_t min_bit = 8, uint8_t max_bit = 8); + explicit RandomPosterizeOperation(const std::vector &bit_range = {4, 8}); ~RandomPosterizeOperation() = default; @@ -539,8 +543,7 @@ class RandomPosterizeOperation : public TensorOperation { bool ValidateParams() override; private: - uint8_t min_bit_; - uint8_t max_bit_; + std::vector bit_range_; }; class RandomRotationOperation : public TensorOperation { diff --git a/mindspore/ccsrc/minddata/dataset/kernels/image/random_affine_op.cc b/mindspore/ccsrc/minddata/dataset/kernels/image/random_affine_op.cc index bf2f6a99ce..55ba93895b 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/image/random_affine_op.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/image/random_affine_op.cc @@ -27,7 +27,7 @@ namespace mindspore { namespace dataset { const std::vector RandomAffineOp::kDegreesRange = {0.0, 0.0}; -const std::vector RandomAffineOp::kTranslationPercentages = {0.0, 0.0}; +const std::vector RandomAffineOp::kTranslationPercentages = {0.0, 0.0, 0.0, 0.0}; const std::vector RandomAffineOp::kScaleRange = {1.0, 1.0}; const std::vector RandomAffineOp::kShearRanges = {0.0, 0.0, 0.0, 0.0}; const InterpolationMode RandomAffineOp::kDefInterpolation = InterpolationMode::kNearestNeighbour; @@ -50,14 +50,16 @@ Status RandomAffineOp::Compute(const std::shared_ptr &input, std::shared IO_CHECK(input, output); dsize_t height = input->shape()[0]; dsize_t width = input->shape()[1]; - float_t max_dx = translate_range_[0] * height; - float_t max_dy = translate_range_[1] * width; + float_t min_dx = translate_range_[0] * width; + float_t max_dx = translate_range_[1] * width; + float_t min_dy = translate_range_[2] * height; + float_t max_dy = translate_range_[3] * height; float_t degrees = 0.0; RETURN_IF_NOT_OK(GenerateRealNumber(degrees_range_[0], degrees_range_[1], &rnd_, °rees)); float_t translation_x = 0.0; - RETURN_IF_NOT_OK(GenerateRealNumber(-1 * max_dx, max_dx, &rnd_, &translation_x)); + RETURN_IF_NOT_OK(GenerateRealNumber(min_dx, max_dx, &rnd_, &translation_x)); float_t translation_y = 0.0; - RETURN_IF_NOT_OK(GenerateRealNumber(-1 * max_dy, max_dy, &rnd_, &translation_y)); + RETURN_IF_NOT_OK(GenerateRealNumber(min_dy, max_dy, &rnd_, &translation_y)); float_t scale = 1.0; RETURN_IF_NOT_OK(GenerateRealNumber(scale_range_[0], scale_range_[1], &rnd_, &scale)); float_t shear_x = 0.0; diff --git a/mindspore/ccsrc/minddata/dataset/kernels/image/random_posterize_op.cc b/mindspore/ccsrc/minddata/dataset/kernels/image/random_posterize_op.cc index 3acb727f13..605b5942a0 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/image/random_posterize_op.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/image/random_posterize_op.cc @@ -24,16 +24,16 @@ namespace mindspore { namespace dataset { -const uint8_t RandomPosterizeOp::kMinBit = 8; -const uint8_t RandomPosterizeOp::kMaxBit = 8; +const std::vector RandomPosterizeOp::kBitRange = {4, 8}; -RandomPosterizeOp::RandomPosterizeOp(uint8_t min_bit, uint8_t max_bit) - : PosterizeOp(min_bit), min_bit_(min_bit), max_bit_(max_bit) { +RandomPosterizeOp::RandomPosterizeOp(const std::vector &bit_range) + : PosterizeOp(bit_range[0]), bit_range_(bit_range) { rnd_.seed(GetSeed()); } Status RandomPosterizeOp::Compute(const std::shared_ptr &input, std::shared_ptr *output) { - bit_ = (min_bit_ == max_bit_) ? min_bit_ : std::uniform_int_distribution(min_bit_, max_bit_)(rnd_); + bit_ = (bit_range_[0] == bit_range_[1]) ? bit_range_[0] + : std::uniform_int_distribution(bit_range_[0], bit_range_[1])(rnd_); return PosterizeOp::Compute(input, output); } } // namespace dataset diff --git a/mindspore/ccsrc/minddata/dataset/kernels/image/random_posterize_op.h b/mindspore/ccsrc/minddata/dataset/kernels/image/random_posterize_op.h index 0cfdd15a8b..a965c9ea1a 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/image/random_posterize_op.h +++ b/mindspore/ccsrc/minddata/dataset/kernels/image/random_posterize_op.h @@ -28,13 +28,11 @@ namespace dataset { class RandomPosterizeOp : public PosterizeOp { public: /// Default values - static const uint8_t kMinBit; - static const uint8_t kMaxBit; + static const std::vector kBitRange; /// \brief Constructor - /// \param[in] min_bit: Minimum bit in range - /// \param[in] max_bit: Maximum bit in range - explicit RandomPosterizeOp(uint8_t min_bit = kMinBit, uint8_t max_bit = kMaxBit); + /// \param[in] bit_range: Minimum and maximum bits in range + explicit RandomPosterizeOp(const std::vector &bit_range = kBitRange); ~RandomPosterizeOp() override = default; @@ -45,8 +43,7 @@ class RandomPosterizeOp : public PosterizeOp { /// Member variables private: std::string kRandomPosterizeOp = "RandomPosterizeOp"; - uint8_t min_bit_; - uint8_t max_bit_; + std::vector bit_range_; std::mt19937 rnd_; }; } // namespace dataset diff --git a/mindspore/dataset/transforms/vision/c_transforms.py b/mindspore/dataset/transforms/vision/c_transforms.py index a4959551c5..bccaf4544d 100644 --- a/mindspore/dataset/transforms/vision/c_transforms.py +++ b/mindspore/dataset/transforms/vision/c_transforms.py @@ -64,6 +64,7 @@ DE_C_BORDER_TYPE = {Border.CONSTANT: cde.BorderType.DE_BORDER_CONSTANT, DE_C_IMAGE_BATCH_FORMAT = {ImageBatchFormat.NHWC: cde.ImageBatchFormat.DE_IMAGE_BATCH_FORMAT_NHWC, ImageBatchFormat.NCHW: cde.ImageBatchFormat.DE_IMAGE_BATCH_FORMAT_NCHW} + def parse_padding(padding): if isinstance(padding, numbers.Number): padding = [padding] * 4 @@ -237,11 +238,16 @@ class RandomAffine(cde.RandomAffineOp): degrees (int or float or sequence): Range of the rotation degrees. If degrees is a number, the range will be (-degrees, degrees). If degrees is a sequence, it should be (min, max). - translate (sequence, optional): Sequence (tx, ty) of maximum translation in + translate (sequence, optional): Sequence (tx_min, tx_max, ty_min, ty_max) of minimum/maximum translation in x(horizontal) and y(vertical) directions (default=None). The horizontal and vertical shift is selected randomly from the range: - (-tx*width, tx*width) and (-ty*height, ty*height), respectively. - If None, no translations gets applied. + (tx_min*width, tx_max*width) and (ty_min*height, ty_max*height), respectively. + If a tuple or list of size 2, then a translate parallel to the x axis in the range of + (translate[0], translate[1]) is applied. + If a tuple of list of size 4, then a translate parallel to x axis in the range of + (translate[0], translate[1]) and a translate parallel to y axis in the range of + (translate[2], translate[3]) are applied. + If None, no translation is applied. scale (sequence, optional): Scaling factor interval (default=None, original scale is used). shear (int or float or sequence, optional): Range of shear factor (default=None). If a number 'shear', then a shear parallel to the x axis in the range of (-shear, +shear) is applied. @@ -266,18 +272,18 @@ class RandomAffine(cde.RandomAffineOp): Raises: ValueError: If degrees is negative. - ValueError: If translation value is not between 0 and 1. + ValueError: If translation value is not between -1 and 1. ValueError: If scale is not positive. ValueError: If shear is a number but is not positive. TypeError: If degrees is not a number or a list or a tuple. If degrees is a list or tuple, its length is not 2. - TypeError: If translate is specified but is not list or a tuple of length 2. + TypeError: If translate is specified but is not list or a tuple of length 2 or 4. TypeError: If scale is not a list or tuple of length 2.'' TypeError: If shear is not a list or tuple of length 2 or 4. TypeError: If fill_value is not a single integer or a 3-tuple. Examples: - >>> c_transform.RandomAffine(degrees=15, translate=(0.1, 0.1), scale=(0.9, 1.1)) + >>> c_transform.RandomAffine(degrees=15, translate=(-0.1, 0.1, 0, 0), scale=(0.9, 1.1)) """ @check_random_affine @@ -300,7 +306,7 @@ class RandomAffine(cde.RandomAffineOp): # translation if translate is None: - translate = (0.0, 0.0) + translate = (0.0, 0.0, 0.0, 0.0) # scale if scale is None: @@ -467,7 +473,7 @@ class RandomPosterize(cde.RandomPosterizeOp): bits values should always be in range of [1,8], and include at least one integer values in the given range. It should be in (min, max) or integer format. If min=max, then it is a single fixed - magnitude operation (default=8). + magnitude operation (default=[4,8]). """ @check_posterize @@ -475,7 +481,7 @@ class RandomPosterize(cde.RandomPosterizeOp): self.bits = bits if isinstance(bits, int): bits = (bits, bits) - super().__init__(bits[0], bits[1]) + super().__init__(bits) class RandomVerticalFlip(cde.RandomVerticalFlipOp): diff --git a/mindspore/dataset/transforms/vision/validators.py b/mindspore/dataset/transforms/vision/validators.py index 04824425f7..a9a00717a7 100644 --- a/mindspore/dataset/transforms/vision/validators.py +++ b/mindspore/dataset/transforms/vision/validators.py @@ -523,10 +523,10 @@ def check_random_affine(method): if translate is not None: type_check(translate, (list, tuple), "translate") type_check_list(translate, (int, float), "translate") - if len(translate) != 2: - raise TypeError("translate should be a list or tuple of length 2.") + if len(translate) != 2 and len(translate) != 4: + raise TypeError("translate should be a list or tuple of length 2 or 4.") for i, t in enumerate(translate): - check_value(t, [0.0, 1.0], "translate at {0}".format(i)) + check_value(t, [-1.0, 1.0], "translate at {0}".format(i)) if scale is not None: type_check(scale, (tuple, list), "scale") diff --git a/tests/ut/cpp/dataset/c_api_transforms_test.cc b/tests/ut/cpp/dataset/c_api_transforms_test.cc index fdffbfd1f1..daaaa88ebb 100644 --- a/tests/ut/cpp/dataset/c_api_transforms_test.cc +++ b/tests/ut/cpp/dataset/c_api_transforms_test.cc @@ -620,10 +620,10 @@ TEST_F(MindDataTestPipeline, TestRandomAffineFail) { std::shared_ptr affine = vision::RandomAffine({0.0, 0.0}, {}); EXPECT_EQ(affine, nullptr); // Invalid number of values for translate - affine = vision::RandomAffine({0.0, 0.0}, {1, 1, 1, 1}); + affine = vision::RandomAffine({0.0, 0.0}, {1, 1, 1, 1, 1}); EXPECT_EQ(affine, nullptr); // Invalid number of values for shear - affine = vision::RandomAffine({30.0, 30.0}, {0.0, 0.0}, {2.0, 2.0}, {10.0, 10.0}); + affine = vision::RandomAffine({30.0, 30.0}, {0.0, 0.0}, {2.0, 2.0}, {10.0}); EXPECT_EQ(affine, nullptr); } @@ -642,7 +642,7 @@ TEST_F(MindDataTestPipeline, TestRandomAffineSuccess1) { // Create objects for the tensor ops std::shared_ptr affine = - vision::RandomAffine({30.0, 30.0}, {0.0, 0.0}, {2.0, 2.0}, {10.0, 10.0, 20.0, 20.0}); + vision::RandomAffine({30.0, 30.0}, {-1.0, 1.0, -1.0, 1.0}, {2.0, 2.0}, {10.0, 10.0, 20.0, 20.0}); EXPECT_NE(affine, nullptr); // Create a Map operation on ds @@ -844,13 +844,16 @@ TEST_F(MindDataTestPipeline, TestRandomPosterizeFail) { // Create objects for the tensor ops // Invalid max > 8 - std::shared_ptr posterize = vision::RandomPosterize(1, 9); + std::shared_ptr posterize = vision::RandomPosterize({1, 9}); EXPECT_EQ(posterize, nullptr); // Invalid min < 1 - posterize = vision::RandomPosterize(0, 8); + posterize = vision::RandomPosterize({0, 8}); EXPECT_EQ(posterize, nullptr); // min > max - posterize = vision::RandomPosterize(8, 1); + posterize = vision::RandomPosterize({8, 1}); + EXPECT_EQ(posterize, nullptr); + // empty + posterize = vision::RandomPosterize({}); EXPECT_EQ(posterize, nullptr); } @@ -869,7 +872,7 @@ TEST_F(MindDataTestPipeline, TestRandomPosterizeSuccess1) { // Create objects for the tensor ops std::shared_ptr posterize = - vision::RandomPosterize(1, 4); + vision::RandomPosterize({1, 4}); EXPECT_NE(posterize, nullptr); // Create a Map operation on ds diff --git a/tests/ut/cpp/dataset/random_affine_op_test.cc b/tests/ut/cpp/dataset/random_affine_op_test.cc index 8db93c589a..f95980c732 100644 --- a/tests/ut/cpp/dataset/random_affine_op_test.cc +++ b/tests/ut/cpp/dataset/random_affine_op_test.cc @@ -33,8 +33,9 @@ TEST_F(MindDataTestRandomAffineOp, TestOp1) { MS_LOG(INFO) << "Doing testRandomAffineOp."; std::shared_ptr output_tensor; - std::unique_ptr op(new RandomAffineOp({30.0, 30.0}, {0.0, 0.0}, {2.0, 2.0}, {10.0, 10.0, 20.0, 20.0}, - InterpolationMode::kNearestNeighbour, {255, 0, 0})); + std::unique_ptr op(new RandomAffineOp({30.0, 30.0}, {0.0, 0.0, 0.0, 0.0}, {2.0, 2.0}, + {10.0, 10.0, 20.0, 20.0}, InterpolationMode::kNearestNeighbour, + {255, 0, 0})); EXPECT_TRUE(op->OneToOne()); Status s = op->Compute(input_tensor_, &output_tensor); EXPECT_TRUE(s.IsOk()); diff --git a/tests/ut/cpp/dataset/random_posterize_op_test.cc b/tests/ut/cpp/dataset/random_posterize_op_test.cc index 258d2faffd..8107e28213 100644 --- a/tests/ut/cpp/dataset/random_posterize_op_test.cc +++ b/tests/ut/cpp/dataset/random_posterize_op_test.cc @@ -33,7 +33,7 @@ TEST_F(MindDataTestRandomPosterizeOp, TestOp1) { MS_LOG(INFO) << "Doing testRandomPosterize."; std::shared_ptr output_tensor; - std::unique_ptr op(new RandomPosterizeOp(1, 1)); + std::unique_ptr op(new RandomPosterizeOp({1, 1})); EXPECT_TRUE(op->OneToOne()); Status s = op->Compute(input_tensor_, &output_tensor); EXPECT_TRUE(s.IsOk()); diff --git a/tests/ut/data/dataset/golden/random_affine_01_c_result.npz b/tests/ut/data/dataset/golden/random_affine_01_c_result.npz index 277acd9540c609e13e6490537da0ba79cf86939e..7b54fe62733139a5f9ba504596748265bf25912e 100644 GIT binary patch delta 99 zcmZo+ZDAD(@MdNaVSoTdhVa_Wl^cZ?FbZhd{ytSOHCM9m_Ntp#y;uI4e27s+z+#`n yww4CzGwCN^%3k}q`M~6FKtW-y-EUtSm4>a4Uv3=r=z`Q_EhbqOkU5jRnJfX?@FxNQ delta 99 zcmZo+ZDAD(@MdNaVSoTd29}<#TN{NIFbZ^jzcr^d?E8j)Jl^iL^6Sq`KE$XZ;9tIC y-hV~i?q;bZY3Y}3zb1bJ3ZA_uu#SJ1z_qZsGehe*-_Dw>#U#rDGH0?klO+J3*CkB= diff --git a/tests/ut/data/dataset/golden/random_affine_01_default_c_result.npz b/tests/ut/data/dataset/golden/random_affine_01_default_c_result.npz new file mode 100644 index 0000000000000000000000000000000000000000..b3a52243a4d660ff8dfde41256c43e0c479a7e56 GIT binary patch literal 644 zcmWIWW@Zs#fB;2?J%>!y{xC8yfG{V62t#5~QM`d(UO^=zg8*0%q!1(t0+anheFGvH z8Oj){)l*W7lZ(`?6x3_{)pZoq)AEZ-iW2kU^NUhaLBei{ImM|!@#2icf>a=1!%#=T zNK;3lR)KuL)xeybSDIT;sh6Bzl&Y6onp2VqbZ=rMSA0=wa(-TMNl|HX30ENlL={(F z3PiS$(VL;Qkja@bsgSw7kR_;)Rl}PR2$|Xn*`P{ON-7IdxeD1Mn1J5&w!y{xC8yfG{V62t#5~QM`d(UO^=zg8*0%q!1(t0+anheFGvH z8Oj){)l*W7lZ(`?6x3_{)pZoq)AEZ-iW2kU^NUhaLBei{ImM|!@#2icf>a=1!%#=T zNK;3lR)KuL)xeybSDIT;sh6Bzl&Y6onp2VqbZ=rMSA0=wa(-TMNl|HX30ENlL={(F z3PiS$(VL;Qkja@bsgSw7kR_;)Rl}PR2$|Xn*`P{ON-7IdxeD1Mn1J5&w