• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
24 using namespace mindspore::dataset;
25 using mindspore::LogStream;
26 using mindspore::ExceptionType::NoExceptionType;
27 using mindspore::MsLogLevel::INFO;
28 
29 class MindDataTestRandomPosterizeOp : public UT::CVOP::CVOpCommon {
30 };
31 
32 TEST_F(MindDataTestRandomPosterizeOp, TestOp1) {
33   MS_LOG(INFO) << "Doing testRandomPosterize.";
34 
35   std::shared_ptr<Tensor> output_tensor;
36   std::unique_ptr<RandomPosterizeOp> op(new RandomPosterizeOp({1, 1}));
37   EXPECT_TRUE(op->OneToOne());
38   Status s = op->Compute(input_tensor_, &output_tensor);
39   EXPECT_TRUE(s.IsOk());
40   CheckImageShapeAndData(output_tensor, kRandomPosterize);
41 }
42 
43 TEST_F(MindDataTestRandomPosterizeOp, TestOp2) {
44    // Test Eager RandomPosterize image = (h, w, c)
45   MS_LOG(INFO) << "Doing VisionRandomPosterizeTest.";
46   std::shared_ptr<Tensor> de_tensor;
47   std::string dataset_root_path = "data/dataset";
48   Tensor::CreateFromFile(dataset_root_path + "/testPK/data/class1/0.jpg", &de_tensor);
49   auto image = mindspore::MSTensor(std::make_shared<DETensor>(de_tensor));
50   std::shared_ptr<TensorTransform>  decode_op = std::make_shared<vision::Decode>();
51   std::shared_ptr<TensorTransform> randomposterize_op(new vision::RandomPosterize({3, 5}));
52   auto transform = Execute({decode_op, randomposterize_op});
53   Status rc = transform(image, &image);
54   EXPECT_TRUE(rc.IsOk());
55   EXPECT_EQ(image.Shape().size(), 3);
56   EXPECT_EQ(image.Shape()[2], 3);
57 }
58 
59 TEST_F(MindDataTestRandomPosterizeOp, TestOp3) {
60   // Test Eager RandomSolarize image.size = {2, 2, 2, 1}
61   MS_LOG(INFO) << "Doing VisionRandomSolarizeTest.";
62 
63   std::shared_ptr<Tensor> de_tensor;
64   Tensor::CreateFromVector(std::vector<uint8_t>({0, 25, 120, 0, 38, 2, 10, 13}), TensorShape({2, 2, 2, 1}), &de_tensor);
65   auto image = mindspore::MSTensor(std::make_shared<DETensor>(de_tensor));
66   std::shared_ptr<TensorTransform> randomsolarize_op(new vision::RandomSolarize({12, 25}));
67   auto transform = Execute({randomsolarize_op});
68   Status rc = transform(image, &image);
69   EXPECT_TRUE(rc.IsError());
70 }
71