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.

ir_vision_test.cc 3.3 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /**
  2. * Copyright 2021 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 <memory>
  17. #include <string>
  18. #include "common/common.h"
  19. #include "minddata/dataset/include/datasets.h"
  20. #include "minddata/dataset/include/transforms.h"
  21. #include "minddata/dataset/include/vision.h"
  22. #include "minddata/dataset/kernels/ir/vision/vision_ir.h"
  23. using namespace mindspore::dataset;
  24. class MindDataTestIRVision : public UT::DatasetOpTesting {
  25. public:
  26. MindDataTestIRVision() = default;
  27. };
  28. TEST_F(MindDataTestIRVision, TestAutoContrastIRFail1) {
  29. MS_LOG(INFO) << "Doing MindDataTestIRVision-TestAutoContrastIRFail1.";
  30. // Testing invalid cutoff < 0
  31. std::shared_ptr<TensorOperation> auto_contrast1(new vision::AutoContrastOperation(-1.0,{}));
  32. ASSERT_NE(auto_contrast1, nullptr);
  33. Status rc1 = auto_contrast1->ValidateParams();
  34. EXPECT_ERROR(rc1);
  35. // Testing invalid cutoff > 100
  36. std::shared_ptr<TensorOperation> auto_contrast2(new vision::AutoContrastOperation(110.0, {10, 20}));
  37. ASSERT_NE(auto_contrast2, nullptr);
  38. Status rc2 = auto_contrast2->ValidateParams();
  39. EXPECT_ERROR(rc2);
  40. }
  41. TEST_F(MindDataTestIRVision, TestNormalizeFail) {
  42. MS_LOG(INFO) << "Doing MindDataTestIRVision-TestNormalizeFail with invalid parameters.";
  43. // std value at 0.0
  44. std::shared_ptr<TensorOperation> normalize1(new vision::NormalizeOperation({121.0, 115.0, 100.0}, {0.0, 68.0, 71.0}));
  45. ASSERT_NE(normalize1, nullptr);
  46. Status rc1 = normalize1->ValidateParams();
  47. EXPECT_ERROR(rc1);
  48. // mean out of range
  49. std::shared_ptr<TensorOperation> normalize2(new vision::NormalizeOperation({121.0, 0.0, 100.0}, {256.0, 68.0, 71.0}));
  50. ASSERT_NE(normalize2, nullptr);
  51. Status rc2 = normalize2->ValidateParams();
  52. EXPECT_ERROR(rc2);
  53. // mean out of range
  54. std::shared_ptr<TensorOperation> normalize3(new vision::NormalizeOperation({256.0, 0.0, 100.0}, {70.0, 68.0, 71.0}));
  55. ASSERT_NE(normalize3, nullptr);
  56. Status rc3 = normalize3->ValidateParams();
  57. EXPECT_ERROR(rc3);
  58. // mean out of range
  59. std::shared_ptr<TensorOperation> normalize4(new vision::NormalizeOperation({-1.0, 0.0, 100.0}, {70.0, 68.0, 71.0}));
  60. ASSERT_NE(normalize4, nullptr);
  61. Status rc4 = normalize4->ValidateParams();
  62. EXPECT_ERROR(rc4);
  63. // normalize with 2 values (not 3 values) for mean
  64. std::shared_ptr<TensorOperation> normalize5(new vision::NormalizeOperation({121.0, 115.0}, {70.0, 68.0, 71.0}));
  65. ASSERT_NE(normalize5, nullptr);
  66. Status rc5 = normalize5->ValidateParams();
  67. EXPECT_ERROR(rc5);
  68. // normalize with 2 values (not 3 values) for standard deviation
  69. std::shared_ptr<TensorOperation> normalize6(new vision::NormalizeOperation({121.0, 115.0, 100.0}, {68.0, 71.0}));
  70. ASSERT_NE(normalize6, nullptr);
  71. Status rc6 = normalize6->ValidateParams();
  72. EXPECT_ERROR(rc6);
  73. }