• 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 #ifndef MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IMAGE_RESIZE_OP_H_
17 #define MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IMAGE_RESIZE_OP_H_
18 
19 #include <memory>
20 #include <vector>
21 #include <string>
22 
23 #include "minddata/dataset/core/tensor.h"
24 #ifndef ENABLE_ANDROID
25 #include "minddata/dataset/kernels/image/image_utils.h"
26 #else
27 #include "minddata/dataset/kernels/image/lite_image_utils.h"
28 #endif
29 #include "minddata/dataset/kernels/tensor_op.h"
30 #include "minddata/dataset/util/status.h"
31 
32 namespace mindspore {
33 namespace dataset {
34 class ResizeOp : public TensorOp {
35  public:
36   // Default values, also used by python_bindings.cc
37   static const int32_t kDefWidth;
38   static const InterpolationMode kDefInterpolation;
39 
40   // Resizes the image to the output specified size. If only one value is provided,
41   // the it will resize the smaller size and maintains the aspect ratio.
42   // @param size1: the first size of output. If only this parameter is provided
43   // the smaller dimension will be resized to this and then the other dimension changes
44   // such that the aspect ratio is maintained.
45   // @param size2: the second size of output. If this is also provided, the output size
46   // will be (size1, size2)
47   // @param InterpolationMode: the interpolation mode being used.
48   explicit ResizeOp(int32_t size1, int32_t size2 = kDefWidth, InterpolationMode interpolation = kDefInterpolation)
size1_(size1)49       : size1_(size1), size2_(size2), interpolation_(interpolation) {}
50 
51   ResizeOp(const ResizeOp &rhs) = default;
52 
53   ResizeOp(ResizeOp &&rhs) = default;
54 
55   ~ResizeOp() override = default;
56 
Print(std::ostream & out)57   void Print(std::ostream &out) const override { out << Name() << ": " << size1_ << " " << size2_; }
58 
59   Status Compute(const std::shared_ptr<Tensor> &input, std::shared_ptr<Tensor> *output) override;
60   Status OutputShape(const std::vector<TensorShape> &inputs, std::vector<TensorShape> &outputs) override;
61 
Name()62   std::string Name() const override { return kResizeOp; }
63 
64  protected:
65   int32_t size1_;
66   int32_t size2_;
67   InterpolationMode interpolation_;
68 };
69 }  // namespace dataset
70 }  // namespace mindspore
71 
72 #endif  // MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IMAGE_RESIZE_OP_H_
73