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.

normalize_op_test.cc 2.1 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /**
  2. * Copyright 2019 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 "dataset/kernels/image/normalize_op.h"
  19. #include "dataset/core/cv_tensor.h"
  20. #include "utils/log_adapter.h"
  21. #include <opencv2/opencv.hpp>
  22. using namespace mindspore::dataset;
  23. using mindspore::MsLogLevel::INFO;
  24. using mindspore::ExceptionType::NoExceptionType;
  25. using mindspore::LogStream;
  26. class MindDataTestNormalizeOP : public UT::CVOP::CVOpCommon {
  27. public:
  28. MindDataTestNormalizeOP() : CVOpCommon() {}
  29. };
  30. TEST_F(MindDataTestNormalizeOP, TestOp) {
  31. MS_LOG(INFO) << "Doing TestNormalizeOp::TestOp2.";
  32. std::shared_ptr<Tensor> output_tensor;
  33. // Numbers are from the resnet50 model implementation
  34. float mean[3] = {121.0, 115.0, 100.0};
  35. float std[3] = {70.0, 68.0, 71.0};
  36. // Normalize Op
  37. std::unique_ptr<NormalizeOp> op(new NormalizeOp(mean[0], mean[1], mean[2], std[0], std[1], std[2]));
  38. EXPECT_TRUE(op->OneToOne());
  39. Status s = op->Compute(input_tensor_, &output_tensor);
  40. EXPECT_TRUE(s.IsOk());
  41. std::string output_filename = GetFilename();
  42. output_filename.replace(output_filename.end() - 8, output_filename.end(), "imagefolder/normalizeOpOut.yml");
  43. std::shared_ptr<CVTensor> p = CVTensor::AsCVTensor(output_tensor);
  44. cv::Mat cv_output_image;
  45. cv_output_image = p->mat();
  46. MS_LOG(DEBUG) << "Storing output file to : " << output_filename << std::endl;
  47. cv::FileStorage file(output_filename, cv::FileStorage::WRITE);
  48. file << "imageData" << cv_output_image;
  49. }