• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2020-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 <algorithm>
17 
18 #include "minddata/dataset/kernels/ir/vision/random_horizontal_flip_ir.h"
19 
20 #ifndef ENABLE_ANDROID
21 #include "minddata/dataset/kernels/image/random_horizontal_flip_op.h"
22 #endif
23 
24 #include "minddata/dataset/kernels/ir/validators.h"
25 
26 namespace mindspore {
27 namespace dataset {
28 namespace vision {
29 #ifndef ENABLE_ANDROID
30 // RandomHorizontalFlipOperation
RandomHorizontalFlipOperation(float prob)31 RandomHorizontalFlipOperation::RandomHorizontalFlipOperation(float prob) : TensorOperation(true), probability_(prob) {}
32 
33 RandomHorizontalFlipOperation::~RandomHorizontalFlipOperation() = default;
34 
Name() const35 std::string RandomHorizontalFlipOperation::Name() const { return kRandomHorizontalFlipOperation; }
36 
ValidateParams()37 Status RandomHorizontalFlipOperation::ValidateParams() {
38   RETURN_IF_NOT_OK(ValidateProbability("RandomHorizontalFlip", probability_));
39   return Status::OK();
40 }
41 
Build()42 std::shared_ptr<TensorOp> RandomHorizontalFlipOperation::Build() {
43   std::shared_ptr<RandomHorizontalFlipOp> tensor_op = std::make_shared<RandomHorizontalFlipOp>(probability_);
44   return tensor_op;
45 }
46 
to_json(nlohmann::json * out_json)47 Status RandomHorizontalFlipOperation::to_json(nlohmann::json *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 RandomHorizontalFlipOperation::from_json(nlohmann::json op_params, std::shared_ptr<TensorOperation> *operation) {
53   CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("prob") != op_params.end(), "Failed to find prob");
54   float prob = op_params["prob"];
55   *operation = std::make_shared<vision::RandomHorizontalFlipOperation>(prob);
56   return Status::OK();
57 }
58 
59 #endif
60 }  // namespace vision
61 }  // namespace dataset
62 }  // namespace mindspore
63