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.

crop_op_test.cc 2.5 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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/crop_op.h"
  19. #include "utils/log_adapter.h"
  20. using namespace mindspore::dataset;
  21. using mindspore::MsLogLevel::INFO;
  22. using mindspore::ExceptionType::NoExceptionType;
  23. using mindspore::LogStream;
  24. class MindDataTestCropOp : public UT::CVOP::CVOpCommon {
  25. protected:
  26. MindDataTestCropOp() : CVOpCommon() {}
  27. std::shared_ptr<Tensor> output_tensor_;
  28. };
  29. TEST_F(MindDataTestCropOp, TestOp1) {
  30. MS_LOG(INFO) << "Doing testCrop.";
  31. // Crop params
  32. int crop_height = 18;
  33. int crop_width = 12;
  34. std::unique_ptr<CropOp> op(new CropOp(0, 0, crop_height, crop_width));
  35. EXPECT_TRUE(op->OneToOne());
  36. Status s = op->Compute(input_tensor_, &output_tensor_);
  37. size_t actual = 0;
  38. if (s == Status::OK()) {
  39. actual = output_tensor_->shape()[0] * output_tensor_->shape()[1] * output_tensor_->shape()[2];
  40. }
  41. EXPECT_EQ(crop_height, output_tensor_->shape()[1]);
  42. EXPECT_EQ(actual, crop_height * crop_width * 3);
  43. EXPECT_EQ(s, Status::OK());
  44. }
  45. TEST_F(MindDataTestCropOp, TestOp2) {
  46. MS_LOG(INFO) << "Doing testCrop negative coordinates.";
  47. // Crop params
  48. unsigned int crop_height = 10;
  49. unsigned int crop_width = 10;
  50. std::unique_ptr<CropOp> op(
  51. new CropOp(-10, -10, crop_height, crop_width));
  52. EXPECT_TRUE(op->OneToOne());
  53. Status s = op->Compute(input_tensor_, &output_tensor_);
  54. EXPECT_EQ(false, s.IsOk());
  55. MS_LOG(INFO) << "testCrop coordinate exception end.";
  56. }
  57. TEST_F(MindDataTestCropOp, TestOp3) {
  58. MS_LOG(INFO) << "Doing testCrop size too large.";
  59. // Crop params
  60. unsigned int crop_height = 1200000;
  61. unsigned int crop_width = 1200000;
  62. std::unique_ptr<CropOp> op(
  63. new CropOp(0, 0, crop_height, crop_width));
  64. EXPECT_TRUE(op->OneToOne());
  65. Status s = op->Compute(input_tensor_, &output_tensor_);
  66. EXPECT_EQ(false, s.IsOk());
  67. MS_LOG(INFO) << "testCrop size exception end.";
  68. }