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_invert_ir.h"
17
18 #ifndef ENABLE_ANDROID
19 #include "minddata/dataset/kernels/image/random_invert_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 // RandomInvertOperation
RandomInvertOperation(float prob)29 RandomInvertOperation::RandomInvertOperation(float prob) : TensorOperation(true), probability_(prob) {}
30
31 RandomInvertOperation::~RandomInvertOperation() = default;
32
Name() const33 std::string RandomInvertOperation::Name() const { return kRandomInvertOperation; }
34
ValidateParams()35 Status RandomInvertOperation::ValidateParams() {
36 RETURN_IF_NOT_OK(ValidateProbability("RandomInvert", probability_));
37 return Status::OK();
38 }
39
Build()40 std::shared_ptr<TensorOp> RandomInvertOperation::Build() {
41 std::shared_ptr<RandomInvertOp> tensor_op = std::make_shared<RandomInvertOp>(probability_);
42 return tensor_op;
43 }
44
to_json(nlohmann::json * out_json)45 Status RandomInvertOperation::to_json(nlohmann::json *out_json) {
46 RETURN_UNEXPECTED_IF_NULL(out_json);
47 (*out_json)["prob"] = probability_;
48 return Status::OK();
49 }
50
from_json(nlohmann::json op_params,std::shared_ptr<TensorOperation> * operation)51 Status RandomInvertOperation::from_json(nlohmann::json op_params, std::shared_ptr<TensorOperation> *operation) {
52 RETURN_UNEXPECTED_IF_NULL(operation);
53 RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "prob", kRandomInvertOperation));
54 float prob = op_params["prob"];
55 *operation = std::make_shared<vision::RandomInvertOperation>(prob);
56 return Status::OK();
57 }
58 #endif
59 } // namespace vision
60 } // namespace dataset
61 } // namespace mindspore
62