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
17 #include "minddata/dataset/kernels/ir/vision/random_equalize_ir.h"
18
19 #ifndef ENABLE_ANDROID
20 #include "minddata/dataset/kernels/image/random_equalize_op.h"
21 #endif
22 #include "minddata/dataset/kernels/ir/validators.h"
23 #include "minddata/dataset/util/validators.h"
24
25 namespace mindspore {
26 namespace dataset {
27 namespace vision {
28 #ifndef ENABLE_ANDROID
29 // RandomEqualizeOperation
RandomEqualizeOperation(float prob)30 RandomEqualizeOperation::RandomEqualizeOperation(float prob) : TensorOperation(true), probability_(prob) {}
31
32 RandomEqualizeOperation::~RandomEqualizeOperation() = default;
33
Name() const34 std::string RandomEqualizeOperation::Name() const { return kRandomEqualizeOperation; }
35
ValidateParams()36 Status RandomEqualizeOperation::ValidateParams() {
37 RETURN_IF_NOT_OK(ValidateProbability("RandomEqualize", probability_));
38 return Status::OK();
39 }
40
Build()41 std::shared_ptr<TensorOp> RandomEqualizeOperation::Build() {
42 std::shared_ptr<RandomEqualizeOp> tensor_op = std::make_shared<RandomEqualizeOp>(probability_);
43 return tensor_op;
44 }
45
to_json(nlohmann::json * out_json)46 Status RandomEqualizeOperation::to_json(nlohmann::json *out_json) {
47 RETURN_UNEXPECTED_IF_NULL(out_json);
48 (*out_json)["prob"] = probability_;
49 return Status::OK();
50 }
51
from_json(nlohmann::json op_params,std::shared_ptr<TensorOperation> * operation)52 Status RandomEqualizeOperation::from_json(nlohmann::json op_params, std::shared_ptr<TensorOperation> *operation) {
53 RETURN_UNEXPECTED_IF_NULL(operation);
54 RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "prob", kRandomEqualizeOperation));
55 float prob = op_params["prob"];
56 *operation = std::make_shared<vision::RandomEqualizeOperation>(prob);
57 return Status::OK();
58 }
59 #endif
60 } // namespace vision
61 } // namespace dataset
62 } // namespace mindspore
63