• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2019 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/image/normalize_op.h"
17 
18 #include <random>
19 #include <vector>
20 
21 #ifndef ENABLE_ANDROID
22 #include "minddata/dataset/kernels/image/image_utils.h"
23 #else
24 #include "minddata/dataset/kernels/image/lite_image_utils.h"
25 #endif
26 #include "minddata/dataset/util/status.h"
27 
28 namespace mindspore {
29 namespace dataset {
NormalizeOp(const std::vector<float> & mean,const std::vector<float> & std)30 NormalizeOp::NormalizeOp(const std::vector<float> &mean, const std::vector<float> &std) : mean_(mean), std_(std) {
31   // pre-calculate normalized mean to be used later in each Compute
32   for (int64_t i = 0; i < mean.size(); i++) {
33     mean_[i] = mean_[i] / std_[i];
34   }
35 }
36 
Compute(const std::shared_ptr<Tensor> & input,std::shared_ptr<Tensor> * output)37 Status NormalizeOp::Compute(const std::shared_ptr<Tensor> &input, std::shared_ptr<Tensor> *output) {
38   IO_CHECK(input, output);
39   // Doing the Normalization
40   return Normalize(input, output, mean_, std_);
41 }
42 
Print(std::ostream & out) const43 void NormalizeOp::Print(std::ostream &out) const {
44   out << "NormalizeOp, mean: ";
45   for (const auto &m : mean_) {
46     out << m << ", ";
47   }
48   out << "}" << std::endl << "std: ";
49   for (const auto &s : std_) {
50     out << s << ", ";
51   }
52   out << "}" << std::endl;
53 }
54 }  // namespace dataset
55 }  // namespace mindspore
56