• 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/mixup_batch_ir.h"
19 
20 #ifndef ENABLE_ANDROID
21 #include "minddata/dataset/kernels/image/mixup_batch_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 // MixUpOperation
MixUpBatchOperation(float alpha)31 MixUpBatchOperation::MixUpBatchOperation(float alpha) : alpha_(alpha) {}
32 
33 MixUpBatchOperation::~MixUpBatchOperation() = default;
34 
Name() const35 std::string MixUpBatchOperation::Name() const { return kMixUpBatchOperation; }
36 
ValidateParams()37 Status MixUpBatchOperation::ValidateParams() {
38   RETURN_IF_NOT_OK(ValidateFloatScalarPositive("MixUpBatch", "alpha", alpha_));
39   return Status::OK();
40 }
41 
Build()42 std::shared_ptr<TensorOp> MixUpBatchOperation::Build() { return std::make_shared<MixUpBatchOp>(alpha_); }
43 
to_json(nlohmann::json * out_json)44 Status MixUpBatchOperation::to_json(nlohmann::json *out_json) {
45   (*out_json)["alpha"] = alpha_;
46   return Status::OK();
47 }
48 
from_json(nlohmann::json op_params,std::shared_ptr<TensorOperation> * operation)49 Status MixUpBatchOperation::from_json(nlohmann::json op_params, std::shared_ptr<TensorOperation> *operation) {
50   CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("alpha") != op_params.end(), "Failed to find alpha");
51   float alpha = op_params["alpha"];
52   *operation = std::make_shared<vision::MixUpBatchOperation>(alpha);
53   return Status::OK();
54 }
55 
56 #endif
57 }  // namespace vision
58 }  // namespace dataset
59 }  // namespace mindspore
60