• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2021-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_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_ASCEND_VISION_IR_H_
18 #define MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_ASCEND_VISION_IR_H_
19 
20 #include <map>
21 #include <memory>
22 #include <string>
23 #include <utility>
24 #include <vector>
25 
26 #include "include/api/status.h"
27 #include "minddata/dataset/include/dataset/constants.h"
28 #include "minddata/dataset/include/dataset/transforms.h"
29 #include "minddata/dataset/kernels/ir/tensor_operation.h"
30 
31 namespace mindspore {
32 namespace dataset {
33 // Transform operations for computer vision
34 namespace vision {
35 // Char arrays storing name of corresponding classes (in alphabetical order)
36 constexpr char kDvppCropJpegOperation[] = "DvppCropJpeg";
37 constexpr char kDvppDecodeResizeOperation[] = "DvppDecodeResize";
38 constexpr char kDvppDecodeResizeCropOperation[] = "DvppDecodeResizeCrop";
39 constexpr char kDvppDecodeJpegOperation[] = "DvppDecodeJpeg";
40 constexpr char kDvppDecodePngOperation[] = "DvppDecodePng";
41 constexpr char kDvppDecodeVideoOperation[] = "DvppDecodeVideo";
42 constexpr char kDvppNormalizeOperation[] = "DvppNormalize";
43 constexpr char kDvppResizeJpegOperation[] = "DvppResizeJpeg";
44 
45 /* ####################################### Derived TensorOperation classes ################################# */
46 
47 class DvppCropJpegOperation : public TensorOperation {
48  public:
49   explicit DvppCropJpegOperation(const std::vector<uint32_t> &resize);
50 
51   ~DvppCropJpegOperation() override = default;
52 
53   std::shared_ptr<TensorOp> Build() override;
54 
55   Status ValidateParams() override;
56 
Name()57   std::string Name() const override { return kDvppCropJpegOperation; }
58 
59   Status to_json(nlohmann::json *out_json) override;
60 
61   static Status from_json(nlohmann::json op_params, std::shared_ptr<TensorOperation> *operation);
62 
63  private:
64   std::vector<uint32_t> crop_;
65 };
66 
67 class DvppDecodeResizeOperation : public TensorOperation {
68  public:
69   explicit DvppDecodeResizeOperation(const std::vector<uint32_t> &resize);
70 
71   ~DvppDecodeResizeOperation() override = default;
72 
73   std::shared_ptr<TensorOp> Build() override;
74 
75   Status ValidateParams() override;
76 
Name()77   std::string Name() const override { return kDvppDecodeResizeOperation; }
78 
79   Status to_json(nlohmann::json *out_json) override;
80 
81   static Status from_json(nlohmann::json op_params, std::shared_ptr<TensorOperation> *operation);
82 
83  private:
84   std::vector<uint32_t> resize_;
85 };
86 
87 class DvppDecodeResizeCropOperation : public TensorOperation {
88  public:
89   DvppDecodeResizeCropOperation(const std::vector<uint32_t> &crop, const std::vector<uint32_t> &resize);
90 
91   ~DvppDecodeResizeCropOperation() override = default;
92 
93   std::shared_ptr<TensorOp> Build() override;
94 
95   Status ValidateParams() override;
96 
Name()97   std::string Name() const override { return kDvppDecodeResizeCropOperation; }
98 
99   Status to_json(nlohmann::json *out_json) override;
100 
101   static Status from_json(nlohmann::json op_params, std::shared_ptr<TensorOperation> *operation);
102 
103  private:
104   std::vector<uint32_t> crop_;
105   std::vector<uint32_t> resize_;
106 };
107 
108 class DvppDecodeJpegOperation : public TensorOperation {
109  public:
110   ~DvppDecodeJpegOperation() override = default;
111 
112   std::shared_ptr<TensorOp> Build() override;
113 
114   Status ValidateParams() override;
115 
Name()116   std::string Name() const override { return kDvppDecodeJpegOperation; }
117 
118   static Status from_json(nlohmann::json op_params, std::shared_ptr<TensorOperation> *operation);
119 };
120 
121 class DvppDecodeVideoOperation : public TensorOperation {
122  public:
123   DvppDecodeVideoOperation(const std::vector<uint32_t> &size, VdecStreamFormat type, VdecOutputFormat out_format,
124                            const std::string &output);
125 
126   ~DvppDecodeVideoOperation() override = default;
127 
128   std::shared_ptr<TensorOp> Build() override;
129 
130   Status ValidateParams() override;
131 
Name()132   std::string Name() const override { return kDvppDecodeVideoOperation; }
133 
134   Status to_json(nlohmann::json *out_json) override;
135 
136   static Status from_json(nlohmann::json op_params, std::shared_ptr<TensorOperation> *operation);
137 
138  private:
139   std::vector<uint32_t> size_;
140   VdecOutputFormat format_;
141   VdecStreamFormat en_type_;
142   std::string output_;
143 };
144 
145 class DvppDecodePngOperation : public TensorOperation {
146  public:
147   ~DvppDecodePngOperation() override = default;
148 
149   std::shared_ptr<TensorOp> Build() override;
150 
151   Status ValidateParams() override;
152 
Name()153   std::string Name() const override { return kDvppDecodePngOperation; }
154 
155   static Status from_json(nlohmann::json op_params, std::shared_ptr<TensorOperation> *operation);
156 };
157 
158 class DvppNormalizeOperation : public TensorOperation {
159  public:
160   DvppNormalizeOperation(const std::vector<float> &mean, const std::vector<float> &std);
161 
162   ~DvppNormalizeOperation() override = default;
163 
164   std::shared_ptr<TensorOp> Build() override;
165 
166   Status ValidateParams() override;
167 
Name()168   std::string Name() const override { return kDvppNormalizeOperation; }
169 
170   Status to_json(nlohmann::json *out_json) override;
171 
172   static Status from_json(nlohmann::json op_params, std::shared_ptr<TensorOperation> *operation);
173 
174  private:
175   std::vector<float> mean_;
176   std::vector<float> std_;
177 };
178 
179 class DvppResizeJpegOperation : public TensorOperation {
180  public:
181   explicit DvppResizeJpegOperation(const std::vector<uint32_t> &resize);
182 
183   ~DvppResizeJpegOperation() override = default;
184 
185   std::shared_ptr<TensorOp> Build() override;
186 
187   Status ValidateParams() override;
188 
Name()189   std::string Name() const override { return kDvppResizeJpegOperation; }
190 
191   Status to_json(nlohmann::json *out_json) override;
192 
193   static Status from_json(nlohmann::json op_params, std::shared_ptr<TensorOperation> *operation);
194 
195  private:
196   std::vector<uint32_t> resize_;
197 };
198 }  // namespace vision
199 }  // namespace dataset
200 }  // namespace mindspore
201 #endif  // MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_ASCEND_VISION_IR_H_
202