• 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 "minddata/dataset/kernels/ir/vision/normalize_ir.h"
17 
18 #include "minddata/dataset/kernels/image/normalize_op.h"
19 
20 #include "minddata/dataset/kernels/ir/validators.h"
21 
22 namespace mindspore {
23 namespace dataset {
24 namespace vision {
25 // NormalizeOperation
NormalizeOperation(const std::vector<float> & mean,const std::vector<float> & std)26 NormalizeOperation::NormalizeOperation(const std::vector<float> &mean, const std::vector<float> &std)
27     : mean_(mean), std_(std) {}
28 
29 NormalizeOperation::~NormalizeOperation() = default;
30 
Name() const31 std::string NormalizeOperation::Name() const { return kNormalizeOperation; }
32 
ValidateParams()33 Status NormalizeOperation::ValidateParams() {
34   RETURN_IF_NOT_OK(ValidateVectorMeanStd("Normalize", mean_, std_));
35   return Status::OK();
36 }
37 
Build()38 std::shared_ptr<TensorOp> NormalizeOperation::Build() { return std::make_shared<NormalizeOp>(mean_, std_); }
39 
to_json(nlohmann::json * out_json)40 Status NormalizeOperation::to_json(nlohmann::json *out_json) {
41   nlohmann::json args;
42   args["mean"] = mean_;
43   args["std"] = std_;
44   *out_json = args;
45   return Status::OK();
46 }
47 
from_json(nlohmann::json op_params,std::shared_ptr<TensorOperation> * operation)48 Status NormalizeOperation::from_json(nlohmann::json op_params, std::shared_ptr<TensorOperation> *operation) {
49   CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("mean") != op_params.end(), "Fail to find mean");
50   CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("std") != op_params.end(), "Fail to find std");
51   std::vector<float> mean = op_params["mean"];
52   std::vector<float> std = op_params["std"];
53   *operation = std::make_shared<vision::NormalizeOperation>(mean, std);
54   return Status::OK();
55 }
56 }  // namespace vision
57 }  // namespace dataset
58 }  // namespace mindspore
59