• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2021-2023 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/random_lighting_ir.h"
17 
18 #ifndef ENABLE_ANDROID
19 #include "minddata/dataset/kernels/image/random_lighting_op.h"
20 #endif
21 #include "minddata/dataset/kernels/ir/validators.h"
22 #include "minddata/dataset/util/validators.h"
23 
24 namespace mindspore {
25 namespace dataset {
26 namespace vision {
27 #ifndef ENABLE_ANDROID
28 // RandomLightingOperation.
RandomLightingOperation(float alpha)29 RandomLightingOperation::RandomLightingOperation(float alpha) : TensorOperation(true), alpha_(alpha) {}
30 
31 RandomLightingOperation::~RandomLightingOperation() = default;
32 
Name() const33 std::string RandomLightingOperation::Name() const { return kRandomLightingOperation; }
34 
ValidateParams()35 Status RandomLightingOperation::ValidateParams() {
36   RETURN_IF_NOT_OK(ValidateFloatScalarNonNegative("RandomLighting", "alpha", alpha_));
37   return Status::OK();
38 }
39 
Build()40 std::shared_ptr<TensorOp> RandomLightingOperation::Build() {
41   std::shared_ptr<RandomLightingOp> tensor_op = std::make_shared<RandomLightingOp>(alpha_);
42   return tensor_op;
43 }
44 
to_json(nlohmann::json * out_json)45 Status RandomLightingOperation::to_json(nlohmann::json *out_json) {
46   RETURN_UNEXPECTED_IF_NULL(out_json);
47   nlohmann::json args;
48   args["alpha"] = alpha_;
49   *out_json = args;
50   return Status::OK();
51 }
52 
from_json(nlohmann::json op_params,std::shared_ptr<TensorOperation> * operation)53 Status RandomLightingOperation::from_json(nlohmann::json op_params, std::shared_ptr<TensorOperation> *operation) {
54   RETURN_UNEXPECTED_IF_NULL(operation);
55   RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "alpha", kRandomLightingOperation));
56   float alpha = op_params["alpha"];
57   *operation = std::make_shared<vision::RandomLightingOperation>(alpha);
58   return Status::OK();
59 }
60 #endif
61 }  // namespace vision
62 }  // namespace dataset
63 }  // namespace mindspore
64