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