You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

random_posterize_op_test.cc 2.9 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /**
  2. * Copyright 2020 Huawei Technologies Co., Ltd
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #include "common/common.h"
  17. #include "common/cvop_common.h"
  18. #include "minddata/dataset/kernels/image/random_posterize_op.h"
  19. #include "minddata/dataset/include/dataset/execute.h"
  20. #include "minddata/dataset/include/dataset/vision.h"
  21. #include "minddata/dataset/core/cv_tensor.h"
  22. #include "utils/log_adapter.h"
  23. using namespace mindspore::dataset;
  24. using mindspore::LogStream;
  25. using mindspore::ExceptionType::NoExceptionType;
  26. using mindspore::MsLogLevel::INFO;
  27. class MindDataTestRandomPosterizeOp : public UT::CVOP::CVOpCommon {
  28. };
  29. TEST_F(MindDataTestRandomPosterizeOp, TestOp1) {
  30. MS_LOG(INFO) << "Doing testRandomPosterize.";
  31. std::shared_ptr<Tensor> output_tensor;
  32. std::unique_ptr<RandomPosterizeOp> op(new RandomPosterizeOp({1, 1}));
  33. EXPECT_TRUE(op->OneToOne());
  34. Status s = op->Compute(input_tensor_, &output_tensor);
  35. EXPECT_TRUE(s.IsOk());
  36. CheckImageShapeAndData(output_tensor, kRandomPosterize);
  37. }
  38. TEST_F(MindDataTestRandomPosterizeOp, TestOp2) {
  39. // Test Eager RandomPosterize image = (h, w, c)
  40. MS_LOG(INFO) << "Doing VisionRandomPosterizeTest.";
  41. std::shared_ptr<Tensor> de_tensor;
  42. std::string dataset_root_path = "data/dataset";
  43. Tensor::CreateFromFile(dataset_root_path + "/testPK/data/class1/0.jpg", &de_tensor);
  44. auto image = mindspore::MSTensor(std::make_shared<DETensor>(de_tensor));
  45. std::shared_ptr<TensorTransform> decode_op = std::make_shared<vision::Decode>();
  46. std::shared_ptr<TensorTransform> randomposterize_op(new vision::RandomPosterize({3, 5}));
  47. auto transform = Execute({decode_op, randomposterize_op});
  48. Status rc = transform(image, &image);
  49. EXPECT_TRUE(rc.IsOk());
  50. EXPECT_EQ(image.Shape().size(), 3);
  51. EXPECT_EQ(image.Shape()[2], 3);
  52. }
  53. TEST_F(MindDataTestRandomPosterizeOp, TestOp3) {
  54. // Test Eager RandomSolarize image.size = {2, 2, 2, 1}
  55. MS_LOG(INFO) << "Doing VisionRandomSolarizeTest.";
  56. std::shared_ptr<Tensor> de_tensor;
  57. Tensor::CreateFromVector(std::vector<uint8_t>({0, 25, 120, 0, 38, 2, 10, 13}), TensorShape({2, 2, 2, 1}), &de_tensor);
  58. auto image = mindspore::MSTensor(std::make_shared<DETensor>(de_tensor));
  59. std::shared_ptr<TensorTransform> randomsolarize_op(new vision::RandomSolarize({12, 25}));
  60. auto transform = Execute({randomsolarize_op});
  61. Status rc = transform(image, &image);
  62. EXPECT_TRUE(rc.IsError());
  63. }