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