• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2021-2023 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/ir/vision/ascend_vision_ir.h"
17 
18 #include <algorithm>
19 
20 #include "minddata/dataset/kernels/image/dvpp/ascend310/dvpp_crop_jpeg_op.h"
21 #include "minddata/dataset/kernels/image/dvpp/ascend310/dvpp_decode_jpeg_op.h"
22 #include "minddata/dataset/kernels/image/dvpp/ascend310/dvpp_decode_png_op.h"
23 #include "minddata/dataset/kernels/image/dvpp/ascend310/dvpp_decode_resize_crop_jpeg_op.h"
24 #include "minddata/dataset/kernels/image/dvpp/ascend310/dvpp_decode_resize_jpeg_op.h"
25 #include "minddata/dataset/kernels/image/dvpp/ascend310/dvpp_decode_video_op.h"
26 #include "minddata/dataset/kernels/image/dvpp/ascend310/dvpp_normalize_op.h"
27 #include "minddata/dataset/kernels/image/dvpp/ascend310/dvpp_resize_jpeg_op.h"
28 #include "minddata/dataset/util/path.h"
29 #include "minddata/dataset/util/validators.h"
30 
31 namespace mindspore {
32 namespace dataset {
33 // Transform operations for computer vision
34 namespace vision {
35 /* ####################################### Derived TensorOperation classes ################################# */
36 // DvppCropOperation
DvppCropJpegOperation(const std::vector<uint32_t> & crop)37 DvppCropJpegOperation::DvppCropJpegOperation(const std::vector<uint32_t> &crop) : crop_(crop) {}
38 
ValidateParams()39 Status DvppCropJpegOperation::ValidateParams() {
40   // size
41   if (crop_.empty() || crop_.size() > 2) {
42     std::string err_msg =
43       "DvppCropJpeg: Crop resolution must be a vector of one or two elements, got: " + std::to_string(crop_.size());
44     LOG_AND_RETURN_STATUS_SYNTAX_ERROR(err_msg);
45   }
46   if (*min_element(crop_.begin(), crop_.end()) < 32 || *max_element(crop_.begin(), crop_.end()) > 2048) {
47     std::string err_msg = "Dvpp module supports crop image with resolution in range [32, 2048], got crop Parameters: ";
48     if (crop_.size() == 2) {
49       MS_LOG(ERROR) << err_msg << "[" << crop_[0] << ", " << crop_[1] << "]";
50     } else {
51       MS_LOG(ERROR) << err_msg << "[" << crop_[0] << ", " << crop_[0] << "]";
52     }
53     LOG_AND_RETURN_STATUS_SYNTAX_ERROR(err_msg);
54   }
55   return Status::OK();
56 }
57 
Build()58 std::shared_ptr<TensorOp> DvppCropJpegOperation::Build() {
59   // If size is a single value, the smaller edge of the image will be
60   // resized to this value with the same image aspect ratio.
61   uint32_t cropHeight;
62   uint32_t cropWidth;
63   // User specified the width value.
64   if (crop_.size() == 1) {
65     cropHeight = crop_[0];
66     cropWidth = crop_[0];
67   } else {
68     cropHeight = crop_[0];
69     cropWidth = crop_[1];
70   }
71   std::shared_ptr<DvppCropJpegOp> tensor_op = std::make_shared<DvppCropJpegOp>(cropHeight, cropWidth);
72   return tensor_op;
73 }
74 
to_json(nlohmann::json * out_json)75 Status DvppCropJpegOperation::to_json(nlohmann::json *out_json) {
76   RETURN_UNEXPECTED_IF_NULL(out_json);
77   nlohmann::json args;
78   args["size"] = crop_;
79   *out_json = args;
80   return Status::OK();
81 }
82 
from_json(nlohmann::json op_params,std::shared_ptr<TensorOperation> * operation)83 Status DvppCropJpegOperation::from_json(nlohmann::json op_params, std::shared_ptr<TensorOperation> *operation) {
84   RETURN_UNEXPECTED_IF_NULL(operation);
85   RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "size", kDvppCropJpegOperation));
86   std::vector<uint32_t> resize = op_params["size"];
87   *operation = std::make_shared<vision::DvppCropJpegOperation>(resize);
88   return Status::OK();
89 }
90 
91 // DvppDecodeResizeOperation
DvppDecodeResizeOperation(const std::vector<uint32_t> & resize)92 DvppDecodeResizeOperation::DvppDecodeResizeOperation(const std::vector<uint32_t> &resize) : resize_(resize) {}
93 
ValidateParams()94 Status DvppDecodeResizeOperation::ValidateParams() {
95   // size
96   if (resize_.empty() || resize_.size() > 2) {
97     std::string err_msg = "DvppDecodeResizeJpeg: resize resolution must be a vector of one or two elements, got: " +
98                           std::to_string(resize_.size());
99     LOG_AND_RETURN_STATUS_SYNTAX_ERROR(err_msg);
100   }
101   if (*min_element(resize_.begin(), resize_.end()) < 32 || *max_element(resize_.begin(), resize_.end()) > 2048) {
102     std::string err_msg =
103       "Dvpp module supports resize image with resolution in range [32, 2048], got resize Parameters: ";
104     if (resize_.size() == 2) {
105       MS_LOG(ERROR) << err_msg << "[" << resize_[0] << ", " << resize_[1] << "]";
106     } else {
107       MS_LOG(ERROR) << err_msg << "[" << resize_[0] << ", " << resize_[0] << "]";
108     }
109     LOG_AND_RETURN_STATUS_SYNTAX_ERROR(err_msg);
110   }
111   return Status::OK();
112 }
113 
Build()114 std::shared_ptr<TensorOp> DvppDecodeResizeOperation::Build() {
115   // If size is a single value, the smaller edge of the image will be
116   // resized to this value with the same image aspect ratio.
117   uint32_t resizeHeight;
118   uint32_t resizeWidth;
119   // User specified the width value.
120   if (resize_.size() == 1) {
121     resizeHeight = resize_[0];
122     resizeWidth = 0;
123   } else {
124     resizeHeight = resize_[0];
125     resizeWidth = resize_[1];
126   }
127   std::shared_ptr<DvppDecodeResizeJpegOp> tensor_op =
128     std::make_shared<DvppDecodeResizeJpegOp>(resizeHeight, resizeWidth);
129   return tensor_op;
130 }
131 
to_json(nlohmann::json * out_json)132 Status DvppDecodeResizeOperation::to_json(nlohmann::json *out_json) {
133   RETURN_UNEXPECTED_IF_NULL(out_json);
134   nlohmann::json args;
135   args["size"] = resize_;
136   *out_json = args;
137   return Status::OK();
138 }
139 
from_json(nlohmann::json op_params,std::shared_ptr<TensorOperation> * operation)140 Status DvppDecodeResizeOperation::from_json(nlohmann::json op_params, std::shared_ptr<TensorOperation> *operation) {
141   RETURN_UNEXPECTED_IF_NULL(operation);
142   RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "size", kDvppDecodeResizeOperation));
143   std::vector<uint32_t> resize = op_params["size"];
144   *operation = std::make_shared<vision::DvppDecodeResizeOperation>(resize);
145   return Status::OK();
146 }
147 
148 // DvppDecodeVideoOperation
DvppDecodeVideoOperation(const std::vector<uint32_t> & size,VdecStreamFormat type,VdecOutputFormat out_format,const std::string & output)149 DvppDecodeVideoOperation::DvppDecodeVideoOperation(const std::vector<uint32_t> &size, VdecStreamFormat type,
150                                                    VdecOutputFormat out_format, const std::string &output)
151     : size_(size), format_(out_format), en_type_(type), output_(output) {}
152 
ValidateParams()153 Status DvppDecodeVideoOperation::ValidateParams() {
154   // check size_
155   constexpr auto kTwoElements = 2;
156   if (size_.size() != kTwoElements) {
157     std::string err_msg =
158       "DvppDecodeVideo: Video frame size must be a vector of two elements, got: " + std::to_string(size_.size());
159     LOG_AND_RETURN_STATUS_SYNTAX_ERROR(err_msg);
160   }
161   // check height and width
162   uint32_t height;
163   uint32_t width;
164   height = size_[0];
165   width = size_[1];
166 
167   if ((width < kFrameWidthMin) || (width > kFrameWidthMax)) {
168     std::string err_msg = "DvppDecodeVideo: video frame width " + std::to_string(width) +
169                           " is invalid, the legal range is [" + std::to_string(kFrameWidthMin) + ", " +
170                           std::to_string(kFrameWidthMax) + "]";
171     LOG_AND_RETURN_STATUS_SYNTAX_ERROR(err_msg);
172   }
173 
174   if ((height < kFrameHeightMin) || (height > kFrameHeightMax)) {
175     std::string err_msg = "DvppDecodeVideo: video frame height " + std::to_string(height) +
176                           " is invalid, the legal range is [" + std::to_string(kFrameHeightMin) + ", " +
177                           std::to_string(kFrameHeightMax) + "]";
178     LOG_AND_RETURN_STATUS_SYNTAX_ERROR(err_msg);
179   }
180 
181   if (en_type_ < VdecStreamFormat::kH265MainLevel || en_type_ > VdecStreamFormat::kH264HighLevel) {
182     std::string err_msg = "DvppDecodeVideo: Invalid VdecStreamFormat, check input value of enum.";
183     LOG_AND_RETURN_STATUS_SYNTAX_ERROR(err_msg);
184   }
185   if (format_ < VdecOutputFormat::kYuvSemiplanar420 || format_ > VdecOutputFormat::kYvuSemiplanar420) {
186     std::string err_msg = "DvppDecodeVideo: Invalid VdecOutputFormat, check input value of enum.";
187     LOG_AND_RETURN_STATUS_SYNTAX_ERROR(err_msg);
188   }
189 
190   // check and normalize output path
191   Path output(output_);
192   if (!output.Exists()) {
193     RETURN_IF_NOT_OK(output.CreateDirectories());
194   }
195   if (!output.IsDirectory()) {
196     std::string err_msg = "DvppDecodeVideo: Invalid out path, check path: " + output.ToString();
197     LOG_AND_RETURN_STATUS_SYNTAX_ERROR(err_msg);
198   }
199   output_ = output.ToString();
200   return Status::OK();
201 }
202 
Build()203 std::shared_ptr<TensorOp> DvppDecodeVideoOperation::Build() {
204   uint32_t height;
205   uint32_t width;
206   height = size_[0];
207   width = size_[1];
208   auto tensor_op = std::make_shared<DvppDecodeVideoOp>(width, height, en_type_, format_, output_);
209   return tensor_op;
210 }
211 
to_json(nlohmann::json * out_json)212 Status DvppDecodeVideoOperation::to_json(nlohmann::json *out_json) {
213   RETURN_UNEXPECTED_IF_NULL(out_json);
214   nlohmann::json args;
215   args["size"] = size_;
216   args["en_type"] = en_type_;
217   args["out_format"] = format_;
218   args["output"] = output_;
219   *out_json = args;
220   return Status::OK();
221 }
222 
from_json(nlohmann::json op_params,std::shared_ptr<TensorOperation> * operation)223 Status DvppDecodeVideoOperation::from_json(nlohmann::json op_params, std::shared_ptr<TensorOperation> *operation) {
224   RETURN_UNEXPECTED_IF_NULL(operation);
225   RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "size", kDvppDecodeVideoOperation));
226   RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "en_type", kDvppDecodeVideoOperation));
227   RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "out_format", kDvppDecodeVideoOperation));
228   RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "output", kDvppDecodeVideoOperation));
229 
230   std::vector<uint32_t> size = op_params["size"];
231   auto type = static_cast<VdecStreamFormat>(op_params["en_type"]);
232   auto out_format = static_cast<VdecOutputFormat>(op_params["out_format"]);
233   std::string output = op_params["output"];
234 
235   *operation = std::make_shared<vision::DvppDecodeVideoOperation>(size, type, out_format, output);
236   return Status::OK();
237 }
238 
239 // DvppDecodeResizeCropOperation
DvppDecodeResizeCropOperation(const std::vector<uint32_t> & crop,const std::vector<uint32_t> & resize)240 DvppDecodeResizeCropOperation::DvppDecodeResizeCropOperation(const std::vector<uint32_t> &crop,
241                                                              const std::vector<uint32_t> &resize)
242     : crop_(crop), resize_(resize) {}
243 
ValidateParams()244 Status DvppDecodeResizeCropOperation::ValidateParams() {
245   // size
246   if (crop_.empty() || crop_.size() > 2) {
247     std::string err_msg = "DvppDecodeResizeCropJpeg: crop resolution must be a vector of one or two elements, got: " +
248                           std::to_string(crop_.size());
249     LOG_AND_RETURN_STATUS_SYNTAX_ERROR(err_msg);
250   }
251   if (resize_.empty() || resize_.size() > 2) {
252     std::string err_msg = "DvppDecodeResizeCropJpeg: resize resolution must be a vector of one or two elements, got: " +
253                           std::to_string(resize_.size());
254     LOG_AND_RETURN_STATUS_SYNTAX_ERROR(err_msg);
255   }
256   if (*min_element(crop_.begin(), crop_.end()) < 32 || *max_element(crop_.begin(), crop_.end()) > 2048) {
257     std::string err_msg = "Dvpp module supports crop image with resolution in range [32, 2048], got Crop Parameters: ";
258     if (crop_.size() == 2) {
259       MS_LOG(ERROR) << err_msg << "[" << crop_[0] << ", " << crop_[1] << "]";
260     } else {
261       MS_LOG(ERROR) << err_msg << "[" << crop_[0] << ", " << crop_[0] << "]";
262     }
263     LOG_AND_RETURN_STATUS_SYNTAX_ERROR(err_msg);
264   }
265   if (*min_element(resize_.begin(), resize_.end()) < 32 || *max_element(resize_.begin(), resize_.end()) > 2048) {
266     std::string err_msg =
267       "Dvpp module supports resize image with resolution in range [32, 2048], got Crop Parameters: ";
268     if (resize_.size() == 2) {
269       MS_LOG(ERROR) << err_msg << "[" << resize_[0] << ", " << resize_[1] << "]";
270     } else {
271       MS_LOG(ERROR) << err_msg << "[" << resize_[0] << "]";
272     }
273     LOG_AND_RETURN_STATUS_SYNTAX_ERROR(err_msg);
274   }
275   if (crop_.size() < resize_.size()) {
276     if (crop_[0] > std::min(resize_[0], resize_[1])) {
277       std::string err_msg =
278         "Each value of crop parameter must be smaller than corresponding resize parameter, for example: x[0] <= "
279         "y[0],  and x[1] <= y[1], please verify your input parameters.";
280       LOG_AND_RETURN_STATUS_SYNTAX_ERROR(err_msg);
281     }
282   }
283   if (crop_.size() > resize_.size()) {
284     if (std::max(crop_[0], crop_[1]) > resize_[0]) {
285       std::string err_msg =
286         "Each value of crop parameter must be smaller than corresponding resize parameter, for example: x[0] <= "
287         "y[0],  and x[1] <= y[1], please verify your input parameters.";
288       LOG_AND_RETURN_STATUS_SYNTAX_ERROR(err_msg);
289     }
290   }
291   if (crop_.size() == resize_.size()) {
292     for (int32_t i = 0; i < crop_.size(); ++i) {
293       if (crop_[i] > resize_[i]) {
294         std::string err_msg =
295           "Each value of crop parameter must be smaller than corresponding resize parameter, for example: x[0] <= "
296           "y[0],  and x[1] <= y[1], please verify your input parameters.";
297         LOG_AND_RETURN_STATUS_SYNTAX_ERROR(err_msg);
298       }
299     }
300   }
301   return Status::OK();
302 }
303 
Build()304 std::shared_ptr<TensorOp> DvppDecodeResizeCropOperation::Build() {
305   // If size is a single value, the smaller edge of the image will be
306   // resized to this value with the same image aspect ratio.
307   uint32_t cropHeight;
308   uint32_t cropWidth;
309   uint32_t resizeHeight;
310   uint32_t resizeWidth;
311   if (crop_.size() == 1) {
312     cropHeight = crop_[0];
313     cropWidth = crop_[0];
314   } else {
315     cropHeight = crop_[0];
316     cropWidth = crop_[1];
317   }
318   // User specified the width value.
319   if (resize_.size() == 1) {
320     resizeHeight = resize_[0];
321     resizeWidth = 0;
322   } else {
323     resizeHeight = resize_[0];
324     resizeWidth = resize_[1];
325   }
326   std::shared_ptr<DvppDecodeResizeCropJpegOp> tensor_op =
327     std::make_shared<DvppDecodeResizeCropJpegOp>(cropHeight, cropWidth, resizeHeight, resizeWidth);
328   return tensor_op;
329 }
330 
to_json(nlohmann::json * out_json)331 Status DvppDecodeResizeCropOperation::to_json(nlohmann::json *out_json) {
332   RETURN_UNEXPECTED_IF_NULL(out_json);
333   nlohmann::json args;
334   args["crop_size"] = crop_;
335   args["resize_size"] = resize_;
336   *out_json = args;
337   return Status::OK();
338 }
339 
from_json(nlohmann::json op_params,std::shared_ptr<TensorOperation> * operation)340 Status DvppDecodeResizeCropOperation::from_json(nlohmann::json op_params, std::shared_ptr<TensorOperation> *operation) {
341   RETURN_UNEXPECTED_IF_NULL(operation);
342   RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "crop_size", kDvppDecodeResizeCropOperation));
343   RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "resize_size", kDvppDecodeResizeCropOperation));
344   std::vector<uint32_t> crop = op_params["crop_size"];
345   std::vector<uint32_t> resize = op_params["resize_size"];
346   *operation = std::make_shared<vision::DvppDecodeResizeCropOperation>(crop, resize);
347   return Status::OK();
348 }
349 
350 // DvppDecodeJPEG
ValidateParams()351 Status DvppDecodeJpegOperation::ValidateParams() { return Status::OK(); }
352 
Build()353 std::shared_ptr<TensorOp> DvppDecodeJpegOperation::Build() { return std::make_shared<DvppDecodeJpegOp>(); }
354 
from_json(nlohmann::json op_params,std::shared_ptr<TensorOperation> * operation)355 Status DvppDecodeJpegOperation::from_json(nlohmann::json op_params, std::shared_ptr<TensorOperation> *operation) {
356   RETURN_UNEXPECTED_IF_NULL(operation);
357   *operation = std::make_shared<vision::DvppDecodeJpegOperation>();
358   return Status::OK();
359 }
360 
361 // DvppDecodePNG
ValidateParams()362 Status DvppDecodePngOperation::ValidateParams() { return Status::OK(); }
363 
Build()364 std::shared_ptr<TensorOp> DvppDecodePngOperation::Build() { return std::make_shared<DvppDecodePngOp>(); }
365 
from_json(nlohmann::json op_params,std::shared_ptr<TensorOperation> * operation)366 Status DvppDecodePngOperation::from_json(nlohmann::json op_params, std::shared_ptr<TensorOperation> *operation) {
367   RETURN_UNEXPECTED_IF_NULL(operation);
368   *operation = std::make_shared<vision::DvppDecodePngOperation>();
369   return Status::OK();
370 }
371 
372 // DvppNormalize
DvppNormalizeOperation(const std::vector<float> & mean,const std::vector<float> & std)373 DvppNormalizeOperation::DvppNormalizeOperation(const std::vector<float> &mean, const std::vector<float> &std)
374     : mean_(mean), std_(std) {}
375 
ValidateParams()376 Status DvppNormalizeOperation::ValidateParams() {
377   constexpr auto kMaxElement = 256.0;
378   if (mean_.size() != 3) {
379     std::string err_msg = "DvppNormalization:: mean expecting size 3, got size: " + std::to_string(mean_.size());
380     LOG_AND_RETURN_STATUS_SYNTAX_ERROR(err_msg);
381   }
382   if (std_.size() != 3) {
383     std::string err_msg = "DvppNormalization: std expecting size 3, got size: " + std::to_string(std_.size());
384     LOG_AND_RETURN_STATUS_SYNTAX_ERROR(err_msg);
385   }
386   if (*min_element(mean_.begin(), mean_.end()) < 0.0 || *max_element(mean_.begin(), mean_.end()) > kMaxElement) {
387     std::string err_msg =
388       "Normalization can take parameters in range [0, 256] according to math theory of mean and sigma, got mean "
389       "vector" +
390       std::to_string(std_.size());
391     LOG_AND_RETURN_STATUS_SYNTAX_ERROR(err_msg);
392   }
393   if (*min_element(std_.begin(), std_.end()) < 0.0 || *max_element(std_.begin(), std_.end()) > kMaxElement) {
394     std::string err_msg =
395       "Normalization can take parameters in range [0, 256] according to math theory of mean and sigma, got mean "
396       "vector" +
397       std::to_string(std_.size());
398     LOG_AND_RETURN_STATUS_SYNTAX_ERROR(err_msg);
399   }
400   return Status::OK();
401 }
402 
Build()403 std::shared_ptr<TensorOp> DvppNormalizeOperation::Build() {
404   std::shared_ptr<DvppNormalizeOp> tensor_op = std::make_shared<DvppNormalizeOp>(mean_, std_);
405   return tensor_op;
406 }
407 
to_json(nlohmann::json * out_json)408 Status DvppNormalizeOperation::to_json(nlohmann::json *out_json) {
409   RETURN_UNEXPECTED_IF_NULL(out_json);
410   nlohmann::json args;
411   std::vector<uint32_t> enlarge_mean_;
412   std::vector<uint32_t> enlarge_std_;
413   constexpr auto kEnlarge = 10000.;
414   (void)std::transform(mean_.begin(), mean_.end(), std::back_inserter(enlarge_mean_),
415                        [&kEnlarge](float i) -> uint32_t { return static_cast<uint32_t>(kEnlarge * i); });
416   (void)std::transform(std_.begin(), std_.end(), std::back_inserter(enlarge_std_),
417                        [&kEnlarge](float j) -> uint32_t { return static_cast<uint32_t>(kEnlarge * j); });
418   args["mean"] = enlarge_mean_;
419   args["std"] = enlarge_std_;
420   *out_json = args;
421   return Status::OK();
422 }
423 
from_json(nlohmann::json op_params,std::shared_ptr<TensorOperation> * operation)424 Status DvppNormalizeOperation::from_json(nlohmann::json op_params, std::shared_ptr<TensorOperation> *operation) {
425   RETURN_UNEXPECTED_IF_NULL(operation);
426   RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "mean", kDvppNormalizeOperation));
427   RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "std", kDvppNormalizeOperation));
428   std::vector<float> mean = op_params["mean"];
429   std::vector<float> std = op_params["std"];
430   *operation = std::make_shared<vision::DvppNormalizeOperation>(mean, std);
431   return Status::OK();
432 }
433 
434 // DvppResizeOperation
DvppResizeJpegOperation(const std::vector<uint32_t> & resize)435 DvppResizeJpegOperation::DvppResizeJpegOperation(const std::vector<uint32_t> &resize) : resize_(resize) {}
436 
ValidateParams()437 Status DvppResizeJpegOperation::ValidateParams() {
438   // size
439   constexpr int32_t kValidResizeSize = 2;
440   if (resize_.size() != 1 && resize_.size() != kValidResizeSize) {
441     std::string err_msg = "DvppResizeJpeg: resize resolution must be a vector of one or two elements, got: " +
442                           std::to_string(resize_.size());
443     LOG_AND_RETURN_STATUS_SYNTAX_ERROR(err_msg);
444   }
445   if (*min_element(resize_.begin(), resize_.end()) < 32 || *max_element(resize_.begin(), resize_.end()) > 2048) {
446     std::string err_msg =
447       "Dvpp module supports resize image with resolution in range [32, 2048], got resize Parameters: ";
448     if (resize_.size() == 2) {
449       MS_LOG(ERROR) << err_msg << "[" << resize_[0] << ", " << resize_[1] << "]";
450     } else {
451       MS_LOG(ERROR) << err_msg << "[" << resize_[0] << ", " << resize_[0] << "]";
452     }
453     LOG_AND_RETURN_STATUS_SYNTAX_ERROR(err_msg);
454   }
455   return Status::OK();
456 }
457 
Build()458 std::shared_ptr<TensorOp> DvppResizeJpegOperation::Build() {
459   // If size is a single value, the smaller edge of the image will be
460   // resized to this value with the same image aspect ratio.
461   uint32_t resizeHeight;
462   uint32_t resizeWidth;
463   // User specified the width value.
464   if (resize_.size() == 1) {
465     resizeHeight = resize_[0];
466     resizeWidth = 0;
467   } else {
468     resizeHeight = resize_[0];
469     resizeWidth = resize_[1];
470   }
471   std::shared_ptr<DvppResizeJpegOp> tensor_op = std::make_shared<DvppResizeJpegOp>(resizeHeight, resizeWidth);
472   return tensor_op;
473 }
474 
to_json(nlohmann::json * out_json)475 Status DvppResizeJpegOperation::to_json(nlohmann::json *out_json) {
476   RETURN_UNEXPECTED_IF_NULL(out_json);
477   nlohmann::json args;
478   args["size"] = resize_;
479   *out_json = args;
480   return Status::OK();
481 }
482 
from_json(nlohmann::json op_params,std::shared_ptr<TensorOperation> * operation)483 Status DvppResizeJpegOperation::from_json(nlohmann::json op_params, std::shared_ptr<TensorOperation> *operation) {
484   RETURN_UNEXPECTED_IF_NULL(operation);
485   RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "size", kDvppResizeJpegOperation));
486   std::vector<uint32_t> resize = op_params["size"];
487   *operation = std::make_shared<vision::DvppResizeJpegOperation>(resize);
488   return Status::OK();
489 }
490 }  // namespace vision
491 }  // namespace dataset
492 }  // namespace mindspore
493