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.

mixup_batch_op_test.cc 2.7 kB

5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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/mixup_batch_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 MindDataTestMixUpBatchOp : public UT::CVOP::CVOpCommon {
  25. protected:
  26. MindDataTestMixUpBatchOp() : CVOpCommon() {}
  27. std::shared_ptr<Tensor> output_tensor_;
  28. };
  29. TEST_F(MindDataTestMixUpBatchOp, TestSuccess) {
  30. MS_LOG(INFO) << "Doing MindDataTestMixUpBatchOp success case";
  31. std::shared_ptr<Tensor> batched_tensor;
  32. std::shared_ptr<Tensor> batched_labels;
  33. Tensor::CreateEmpty(TensorShape({2, input_tensor_->shape()[0], input_tensor_->shape()[1], input_tensor_->shape()[2]}), input_tensor_->type(), &batched_tensor);
  34. for (int i = 0; i < 2; i++) {
  35. batched_tensor->InsertTensor({i}, input_tensor_);
  36. }
  37. Tensor::CreateFromVector(std::vector<uint32_t>({0, 1, 1, 0}), TensorShape({2, 2}), &batched_labels);
  38. std::shared_ptr<MixUpBatchOp> op = std::make_shared<MixUpBatchOp>(1);
  39. TensorRow in;
  40. in.push_back(batched_tensor);
  41. in.push_back(batched_labels);
  42. TensorRow out;
  43. ASSERT_TRUE(op->Compute(in, &out).IsOk());
  44. EXPECT_EQ(in.at(0)->shape()[0], out.at(0)->shape()[0]);
  45. EXPECT_EQ(in.at(0)->shape()[1], out.at(0)->shape()[1]);
  46. EXPECT_EQ(in.at(0)->shape()[2], out.at(0)->shape()[2]);
  47. EXPECT_EQ(in.at(0)->shape()[3], out.at(0)->shape()[3]);
  48. EXPECT_EQ(in.at(1)->shape()[0], out.at(1)->shape()[0]);
  49. EXPECT_EQ(in.at(1)->shape()[1], out.at(1)->shape()[1]);
  50. }
  51. TEST_F(MindDataTestMixUpBatchOp, TestFail) {
  52. // This is a fail case because our labels are not batched and are 1-dimensional
  53. MS_LOG(INFO) << "Doing MindDataTestMixUpBatchOp fail case";
  54. std::shared_ptr<Tensor> labels;
  55. Tensor::CreateFromVector(std::vector<uint32_t>({0, 1, 1, 0}), TensorShape({4}), &labels);
  56. std::shared_ptr<MixUpBatchOp> op = std::make_shared<MixUpBatchOp>(1);
  57. TensorRow in;
  58. in.push_back(input_tensor_);
  59. in.push_back(labels);
  60. TensorRow out;
  61. ASSERT_FALSE(op->Compute(in, &out).IsOk());
  62. }