• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2022 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_MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IMAGE_RAND_AUGMENT_OP_H_
18 #define MINDSPORE_MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IMAGE_RAND_AUGMENT_OP_H_
19 
20 #include <cstdlib>
21 #include <map>
22 #include <memory>
23 #include <random>
24 #include <string>
25 #include <tuple>
26 #include <utility>
27 #include <vector>
28 
29 #include "minddata/dataset/core/tensor.h"
30 #include "minddata/dataset/kernels/tensor_op.h"
31 #ifndef ENABLE_ANDROID
32 #include "minddata/dataset/kernels/image/image_utils.h"
33 #else
34 #include "minddata/dataset/kernels/image/lite_image_utils.h"
35 #endif
36 #include "minddata/dataset/util/status.h"
37 
38 typedef std::map<std::string, std::tuple<std::vector<float>, bool>> Space;
39 
40 namespace mindspore {
41 namespace dataset {
42 class RandAugmentOp : public RandomTensorOp {
43  public:
44   RandAugmentOp(int32_t num_ops, int32_t magnitude, int32_t num_magnitude_bins, InterpolationMode interpolation,
45                 std::vector<uint8_t> fill_value);
46 
47   ~RandAugmentOp() override = default;
48 
49   Status Compute(const std::shared_ptr<Tensor> &input, std::shared_ptr<Tensor> *output) override;
50 
Name()51   std::string Name() const override { return kRandAugmentOp; }
52 
53  private:
54   static Space GetSpace(int32_t num_bins, const std::vector<dsize_t> &image_size);
55 
56   int32_t RandInt(int32_t low, int32_t high);
57 
58   int num_ops_;
59   int magnitude_;
60   int num_magnitude_bins_;
61   InterpolationMode interpolation_;
62   std::vector<uint8_t> fill_value_;
63 };
64 }  // namespace dataset
65 }  // namespace mindspore
66 #endif  // MINDSPORE_MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IMAGE_RAND_AUGMENT_OP_H_
67