You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

vision_ascend.h 10 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. /**
  2. * Copyright 2021 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_INCLUDE_VISION_ASCEND_H_
  17. #define MINDSPORE_CCSRC_MINDDATA_DATASET_INCLUDE_VISION_ASCEND_H_
  18. #include <map>
  19. #include <memory>
  20. #include <string>
  21. #include <utility>
  22. #include <vector>
  23. #include "include/api/status.h"
  24. #include "minddata/dataset/include/constants.h"
  25. #include "minddata/dataset/include/transforms.h"
  26. namespace mindspore {
  27. namespace dataset {
  28. // Transform operations for performing computer vision.
  29. namespace vision {
  30. // Char arrays storing name of corresponding classes (in alphabetical order)
  31. constexpr char kDvppCropJpegOperation[] = "DvppCropJpeg";
  32. constexpr char kDvppDecodeResizeOperation[] = "DvppDecodeResize";
  33. constexpr char kDvppDecodeResizeCropOperation[] = "DvppDecodeResizeCrop";
  34. constexpr char kDvppDecodeJpegOperation[] = "DvppDecodeJpeg";
  35. constexpr char kDvppDecodePngOperation[] = "DvppDecodePng";
  36. constexpr char kDvppResizeJpegOperation[] = "DvppResizeJpeg";
  37. class DvppCropJpegOperation;
  38. class DvppDecodeResizeOperation;
  39. class DvppDecodeResizeCropOperation;
  40. class DvppDecodeJpegOperation;
  41. class DvppDecodePngOperation;
  42. class DvppResizeJpegOperation;
  43. /// \brief Function to create a DvppCropJpeg TensorOperation.
  44. /// \notes Tensor operation to crop JPEG image using the simulation algorithm of Ascend series
  45. /// chip DVPP module. It is recommended to use this algorithm in the following scenarios:
  46. /// When training, the DVPP of the Ascend chip is not used,
  47. /// and the DVPP of the Ascend chip is used during inference,
  48. /// and the accuracy of inference is lower than the accuracy of training;
  49. /// and the input image size should be in range [32*32, 2048*2048].
  50. /// Only images with an even resolution can be output. The output of odd resolution is not supported.
  51. /// \param[in] crop vector representing the output size of the final crop image.
  52. /// \param[in] size A vector representing the output size of the intermediate resized image.
  53. /// If size is a single value, the shape will be a square. If size has 2 values, it should be (height, width).
  54. /// \return Shared pointer to the current TensorOperation.
  55. std::shared_ptr<DvppCropJpegOperation> DvppCropJpeg(std::vector<uint32_t> crop = {256, 256});
  56. /// \brief Function to create a DvppDecodeResizeJpeg TensorOperation.
  57. /// \notes Tensor operation to decode and resize JPEG image using the simulation algorithm of Ascend series
  58. /// chip DVPP module. It is recommended to use this algorithm in the following scenarios:
  59. /// When training, the DVPP of the Ascend chip is not used,
  60. /// and the DVPP of the Ascend chip is used during inference,
  61. /// and the accuracy of inference is lower than the accuracy of training;
  62. /// and the input image size should be in range [32*32, 2048*2048].
  63. /// Only images with an even resolution can be output. The output of odd resolution is not supported.
  64. /// \param[in] crop vector representing the output size of the final crop image.
  65. /// \param[in] size A vector representing the output size of the intermediate resized image.
  66. /// If size is a single value, smaller edge of the image will be resized to this value with
  67. /// the same image aspect ratio. If size has 2 values, it should be (height, width).
  68. /// \return Shared pointer to the current TensorOperation.
  69. std::shared_ptr<DvppDecodeResizeOperation> DvppDecodeResizeJpeg(std::vector<uint32_t> resize = {256, 256});
  70. /// \brief Function to create a DvppDecodeResizeCropJpeg TensorOperation.
  71. /// \notes Tensor operation to decode and resize JPEG image using the simulation algorithm of Ascend series
  72. /// chip DVPP module. It is recommended to use this algorithm in the following scenarios:
  73. /// When training, the DVPP of the Ascend chip is not used,
  74. /// and the DVPP of the Ascend chip is used during inference,
  75. /// and the accuracy of inference is lower than the accuracy of training;
  76. /// and the input image size should be in range [32*32, 2048*2048].
  77. /// Only images with an even resolution can be output. The output of odd resolution is not supported.
  78. /// \param[in] crop vector representing the output size of the final crop image.
  79. /// \param[in] Resize vector representing the output size of the intermediate resized image.
  80. /// If size is a single value, smaller edge of the image will be resized to the value with
  81. /// the same image aspect ratio. If size has 2 values, it should be (height, width).
  82. /// \return Shared pointer to the current TensorOperation.
  83. std::shared_ptr<DvppDecodeResizeCropOperation> DvppDecodeResizeCropJpeg(std::vector<uint32_t> crop = {224, 224},
  84. std::vector<uint32_t> resize = {256, 256});
  85. /// \brief Function to create a DvppDecodeJpeg TensorOperation.
  86. /// \notes Tensor operation to decode JPEG image using the simulation algorithm of Ascend series
  87. /// chip DVPP module. It is recommended to use this algorithm in the following scenarios:
  88. /// When training, the DVPP of the Ascend chip is not used,
  89. /// and the DVPP of the Ascend chip is used during inference,
  90. /// and the accuracy of inference is lower than the accuracy of training;
  91. /// and the input image size should be in range [32*32, 2048*2048].
  92. /// Only images with an even resolution can be output. The output of odd resolution is not supported.
  93. /// \return Shared pointer to the current TensorOperation.
  94. std::shared_ptr<DvppDecodeJpegOperation> DvppDecodeJpeg();
  95. /// \brief Function to create a DvppDecodePng TensorOperation.
  96. /// \notes Tensor operation to decode PNG image using the simulation algorithm of Ascend series
  97. /// chip DVPP module. It is recommended to use this algorithm in the following scenarios:
  98. /// When training, the DVPP of the Ascend chip is not used,
  99. /// and the DVPP of the Ascend chip is used during inference,
  100. /// and the accuracy of inference is lower than the accuracy of training;
  101. /// and the input image size should be in range [32*32, 2048*2048].
  102. /// Only images with an even resolution can be output. The output of odd resolution is not supported.
  103. /// \return Shared pointer to the current TensorOperation.
  104. std::shared_ptr<DvppDecodePngOperation> DvppDecodePng();
  105. /// \brief Function to create a DvppResizeJpeg TensorOperation.
  106. /// \notes Tensor operation to resize JPEG image using Ascend series chip DVPP module.
  107. /// It is recommended to use this algorithm in the following scenarios:
  108. /// When training, the DVPP of the Ascend chip is not used,
  109. /// and the DVPP of the Ascend chip is used during inference,
  110. /// and the accuracy of inference is lower than the accuracy of training;
  111. /// and the input image size should be in range [32*32, 2048*2048].
  112. /// Only images with an even resolution can be output. The output of odd resolution is not supported.
  113. /// \param[in] resize vector represents the shape of image after resize.
  114. /// \return Shared pointer to the current TensorOperation.
  115. std::shared_ptr<DvppResizeJpegOperation> DvppResizeJpeg(std::vector<uint32_t> resize = {256, 256});
  116. class DvppCropJpegOperation : public TensorOperation {
  117. public:
  118. explicit DvppCropJpegOperation(const std::vector<uint32_t> &resize);
  119. ~DvppCropJpegOperation() = default;
  120. std::shared_ptr<TensorOp> Build() override;
  121. Status ValidateParams() override;
  122. std::string Name() const override { return kDvppCropJpegOperation; }
  123. private:
  124. std::vector<uint32_t> crop_;
  125. };
  126. class DvppDecodeResizeOperation : public TensorOperation {
  127. public:
  128. explicit DvppDecodeResizeOperation(const std::vector<uint32_t> &resize);
  129. ~DvppDecodeResizeOperation() = default;
  130. std::shared_ptr<TensorOp> Build() override;
  131. Status ValidateParams() override;
  132. std::string Name() const override { return kDvppDecodeResizeOperation; }
  133. private:
  134. std::vector<uint32_t> resize_;
  135. };
  136. class DvppDecodeResizeCropOperation : public TensorOperation {
  137. public:
  138. explicit DvppDecodeResizeCropOperation(const std::vector<uint32_t> &crop, const std::vector<uint32_t> &resize);
  139. ~DvppDecodeResizeCropOperation() = default;
  140. std::shared_ptr<TensorOp> Build() override;
  141. Status ValidateParams() override;
  142. std::string Name() const override { return kDvppDecodeResizeCropOperation; }
  143. private:
  144. std::vector<uint32_t> crop_;
  145. std::vector<uint32_t> resize_;
  146. };
  147. class DvppDecodeJpegOperation : public TensorOperation {
  148. public:
  149. ~DvppDecodeJpegOperation() = default;
  150. std::shared_ptr<TensorOp> Build() override;
  151. Status ValidateParams() override;
  152. std::string Name() const override { return kDvppDecodeJpegOperation; }
  153. };
  154. class DvppDecodePngOperation : public TensorOperation {
  155. public:
  156. ~DvppDecodePngOperation() = default;
  157. std::shared_ptr<TensorOp> Build() override;
  158. Status ValidateParams() override;
  159. std::string Name() const override { return kDvppDecodePngOperation; }
  160. };
  161. class DvppResizeJpegOperation : public TensorOperation {
  162. public:
  163. explicit DvppResizeJpegOperation(const std::vector<uint32_t> &resize);
  164. ~DvppResizeJpegOperation() = default;
  165. std::shared_ptr<TensorOp> Build() override;
  166. Status ValidateParams() override;
  167. std::string Name() const override { return kDvppResizeJpegOperation; }
  168. private:
  169. std::vector<uint32_t> resize_;
  170. };
  171. } // namespace vision
  172. } // namespace dataset
  173. } // namespace mindspore
  174. #endif // MINDSPORE_CCSRC_MINDDATA_DATASET_INCLUDE_VISION_ASCEND_H_