• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "minddata/dataset/kernels/ir/vision/adjust_gamma_ir.h"
17 
18 #ifndef ENABLE_ANDROID
19 #include "minddata/dataset/kernels/image/adjust_gamma_op.h"
20 #endif
21 
22 #include "minddata/dataset/kernels/ir/validators.h"
23 
24 namespace mindspore {
25 namespace dataset {
26 namespace vision {
27 #ifndef ENABLE_ANDROID
28 
29 // AdjustGammaOperation
AdjustGammaOperation(float gamma,float gain)30 AdjustGammaOperation::AdjustGammaOperation(float gamma, float gain) : gamma_(gamma), gain_(gain) {}
31 
ValidateParams()32 Status AdjustGammaOperation::ValidateParams() {
33   // gamma
34   RETURN_IF_NOT_OK(ValidateFloatScalarNonNegative("AdjustGamma", "gamma", gamma_));
35   return Status::OK();
36 }
37 
Build()38 std::shared_ptr<TensorOp> AdjustGammaOperation::Build() {
39   std::shared_ptr<AdjustGammaOp> tensor_op = std::make_shared<AdjustGammaOp>(gamma_, gain_);
40   return tensor_op;
41 }
42 
to_json(nlohmann::json * out_json)43 Status AdjustGammaOperation::to_json(nlohmann::json *out_json) {
44   nlohmann::json args;
45   args["gamma"] = gamma_;
46   args["gain"] = gain_;
47   *out_json = args;
48   return Status::OK();
49 }
50 
from_json(nlohmann::json op_params,std::shared_ptr<TensorOperation> * operation)51 Status AdjustGammaOperation::from_json(nlohmann::json op_params, std::shared_ptr<TensorOperation> *operation) {
52   CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("gamma") != op_params.end(), "Failed to find gamma");
53   CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("gain") != op_params.end(), "Failed to find gain");
54   float gamma = op_params["gamma"];
55   float gain = op_params["gain"];
56   *operation = std::make_shared<vision::AdjustGammaOperation>(gamma, gain);
57   return Status::OK();
58 }
59 #endif
60 }  // namespace vision
61 }  // namespace dataset
62 }  // namespace mindspore
63