• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2020 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_pad_op.h"
17 
18 #include <random>
19 
20 #include "minddata/dataset/kernels/image/image_utils.h"
21 #include "minddata/dataset/util/status.h"
22 
23 namespace mindspore {
24 namespace dataset {
NormalizePadOp(float mean_r,float mean_g,float mean_b,float std_r,float std_g,float std_b,std::string dtype)25 NormalizePadOp::NormalizePadOp(float mean_r, float mean_g, float mean_b, float std_r, float std_g, float std_b,
26                                std::string dtype) {
27   Status s = Tensor::CreateFromVector<float>({mean_r, mean_g, mean_b}, &mean_);
28   if (s.IsError()) {
29     MS_LOG(ERROR) << "NormalizePad: invalid mean value, got: (" + std::to_string(mean_r) + std::to_string(mean_g) +
30                        std::to_string(mean_b) + ").";
31   }
32   s = Tensor::CreateFromVector<float>({std_r, std_g, std_b}, &std_);
33   if (s.IsError()) {
34     MS_LOG(ERROR) << "NormalizePad: invalid std value, got: (" + std::to_string(std_r) + std::to_string(std_g) +
35                        std::to_string(std_b) + ").";
36   }
37   dtype_ = dtype;
38 }
39 
Compute(const std::shared_ptr<Tensor> & input,std::shared_ptr<Tensor> * output)40 Status NormalizePadOp::Compute(const std::shared_ptr<Tensor> &input, std::shared_ptr<Tensor> *output) {
41   IO_CHECK(input, output);
42   // Doing the Normalization + pad
43   return NormalizePad(input, output, mean_, std_, dtype_);
44 }
45 
Print(std::ostream & out) const46 void NormalizePadOp::Print(std::ostream &out) const {
47   out << "NormalizeOp, mean: " << *(mean_.get()) << std::endl << "std: " << *(std_.get()) << std::endl;
48 }
49 }  // namespace dataset
50 }  // namespace mindspore
51