• 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 
17 #ifndef MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IMAGE_RANDOM_AFFINE_OP_H_
18 #define MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IMAGE_RANDOM_AFFINE_OP_H_
19 
20 #include <memory>
21 #include <string>
22 #include <vector>
23 
24 #include "minddata/dataset/core/tensor.h"
25 #include "minddata/dataset/kernels/image/affine_op.h"
26 #include "minddata/dataset/util/status.h"
27 
28 namespace mindspore {
29 namespace dataset {
30 class RandomAffineOp : public AffineOp {
31  public:
32   /// Default values, also used by python_bindings.cc
33   static const std::vector<float_t> kDegreesRange;
34   static const std::vector<float_t> kTranslationPercentages;
35   static const std::vector<float_t> kScaleRange;
36   static const std::vector<float_t> kShearRanges;
37   static const InterpolationMode kDefInterpolation;
38   static const std::vector<uint8_t> kFillValue;
39 
40   explicit RandomAffineOp(std::vector<float_t> degrees, std::vector<float_t> translate_range = kTranslationPercentages,
41                           std::vector<float_t> scale_range = kScaleRange,
42                           std::vector<float_t> shear_ranges = kShearRanges,
43                           InterpolationMode interpolation = kDefInterpolation,
44                           std::vector<uint8_t> fill_value = kFillValue);
45 
46   ~RandomAffineOp() override = default;
47 
Name()48   std::string Name() const override { return kRandomAffineOp; }
49 
50   Status Compute(const std::shared_ptr<Tensor> &input, std::shared_ptr<Tensor> *output) override;
51 
52  private:
53   std::vector<float_t> degrees_range_;    // min_degree, max_degree
54   std::vector<float_t> translate_range_;  // maximum x translation percentage, maximum y translation percentage
55   std::vector<float_t> scale_range_;      // min_scale, max_scale
56   std::vector<float_t> shear_ranges_;     // min_x_shear, max_x_shear, min_y_shear, max_y_shear
57   std::mt19937 rnd_;                      // random device
58 };
59 }  // namespace dataset
60 }  // namespace mindspore
61 
62 #endif  // MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IMAGE_RANDOM_AFFINE_OP_H_
63