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_adjust_sharpness_ir.h"
17
18 #ifndef ENABLE_ANDROID
19 #include "minddata/dataset/kernels/image/random_adjust_sharpness_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 // RandomAdjustSharpnessOperation
RandomAdjustSharpnessOperation(float degree,float prob)29 RandomAdjustSharpnessOperation::RandomAdjustSharpnessOperation(float degree, float prob)
30 : degree_(degree), probability_(prob) {}
31
32 RandomAdjustSharpnessOperation::~RandomAdjustSharpnessOperation() = default;
33
Name() const34 std::string RandomAdjustSharpnessOperation::Name() const { return kRandomAdjustSharpnessOperation; }
35
ValidateParams()36 Status RandomAdjustSharpnessOperation::ValidateParams() {
37 RETURN_IF_NOT_OK(ValidateFloatScalarNonNegative("RandomAdjustSharpness", "degree", degree_));
38 RETURN_IF_NOT_OK(ValidateProbability("RandomAdjustSharpness", probability_));
39 return Status::OK();
40 }
41
Build()42 std::shared_ptr<TensorOp> RandomAdjustSharpnessOperation::Build() {
43 std::shared_ptr<RandomAdjustSharpnessOp> tensor_op = std::make_shared<RandomAdjustSharpnessOp>(degree_, probability_);
44 return tensor_op;
45 }
46
to_json(nlohmann::json * out_json)47 Status RandomAdjustSharpnessOperation::to_json(nlohmann::json *out_json) {
48 RETURN_UNEXPECTED_IF_NULL(out_json);
49 nlohmann::json args;
50 args["degree"] = degree_;
51 args["prob"] = probability_;
52 *out_json = args;
53 return Status::OK();
54 }
55
from_json(nlohmann::json op_params,std::shared_ptr<TensorOperation> * operation)56 Status RandomAdjustSharpnessOperation::from_json(nlohmann::json op_params,
57 std::shared_ptr<TensorOperation> *operation) {
58 RETURN_UNEXPECTED_IF_NULL(operation);
59 RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "degree", kRandomAdjustSharpnessOperation));
60 RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "prob", kRandomAdjustSharpnessOperation));
61 float degree = op_params["degree"];
62 float prob = op_params["prob"];
63 *operation = std::make_shared<vision::RandomAdjustSharpnessOperation>(degree, prob);
64 return Status::OK();
65 }
66 #endif
67 } // namespace vision
68 } // namespace dataset
69 } // namespace mindspore
70