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.cc 22 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525
  1. /**
  2. * Copyright 2020-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. #include "minddata/dataset/include/vision.h"
  17. #ifdef ENABLE_ACL
  18. #include "minddata/dataset/include/vision_ascend.h"
  19. #include "minddata/dataset/kernels/ir/vision/ascend_vision_ir.h"
  20. #endif
  21. #include "minddata/dataset/include/transforms.h"
  22. #include "minddata/dataset/kernels/ir/vision/vision_ir.h"
  23. #ifndef ENABLE_ANDROID
  24. #include "minddata/dataset/kernels/image/image_utils.h"
  25. #include "utils/log_adapter.h"
  26. #else
  27. #include "mindspore/lite/src/common/log_adapter.h"
  28. #endif
  29. #include "minddata/dataset/kernels/ir/validators.h"
  30. // Kernel image headers (in alphabetical order)
  31. namespace mindspore {
  32. namespace dataset {
  33. // Transform operations for computer vision.
  34. namespace vision {
  35. #ifndef ENABLE_ANDROID
  36. // CONSTRUCTORS FOR API CLASSES TO CREATE VISION TENSOR TRANSFORM OPERATIONS
  37. // (In alphabetical order)
  38. Affine::Affine(float_t degrees, const std::vector<float> &translation, float scale, const std::vector<float> &shear,
  39. InterpolationMode interpolation, const std::vector<uint8_t> &fill_value)
  40. : degrees_(degrees),
  41. translation_(translation),
  42. scale_(scale),
  43. shear_(shear),
  44. interpolation_(interpolation),
  45. fill_value_(fill_value) {}
  46. std::shared_ptr<TensorOperation> Affine::Parse() {
  47. return std::make_shared<AffineOperation>(degrees_, translation_, scale_, shear_, interpolation_, fill_value_);
  48. }
  49. // AutoContrast Transform Operation.
  50. AutoContrast::AutoContrast(float cutoff, std::vector<uint32_t> ignore) : cutoff_(cutoff), ignore_(ignore) {}
  51. std::shared_ptr<TensorOperation> AutoContrast::Parse() {
  52. return std::make_shared<AutoContrastOperation>(cutoff_, ignore_);
  53. }
  54. // BoundingBoxAugment Transform Operation.
  55. BoundingBoxAugment::BoundingBoxAugment(TensorTransform *transform, float ratio) : ratio_(ratio) {
  56. transform_ = transform ? transform->Parse() : nullptr;
  57. }
  58. BoundingBoxAugment::BoundingBoxAugment(const std::shared_ptr<TensorTransform> &transform, float ratio) : ratio_(ratio) {
  59. transform_ = transform ? transform->Parse() : nullptr;
  60. }
  61. BoundingBoxAugment::BoundingBoxAugment(const std::reference_wrapper<TensorTransform> transform, float ratio)
  62. : ratio_(ratio) {
  63. transform_ = transform.get().Parse();
  64. }
  65. std::shared_ptr<TensorOperation> BoundingBoxAugment::Parse() {
  66. return std::make_shared<BoundingBoxAugmentOperation>(transform_, ratio_);
  67. }
  68. #endif // not ENABLE_ANDROID
  69. // CenterCrop Transform Operation.
  70. CenterCrop::CenterCrop(std::vector<int32_t> size) : size_(size) {}
  71. std::shared_ptr<TensorOperation> CenterCrop::Parse() { return std::make_shared<CenterCropOperation>(size_); }
  72. std::shared_ptr<TensorOperation> CenterCrop::Parse(const MapTargetDevice &env) {
  73. if (env == MapTargetDevice::kAscend310) {
  74. #ifdef ENABLE_ACL
  75. std::vector<uint32_t> usize_;
  76. usize_.reserve(size_.size());
  77. std::transform(size_.begin(), size_.end(), std::back_inserter(usize_), [](int32_t i) { return (uint32_t)i; });
  78. return std::make_shared<DvppCropJpegOperation>(usize_);
  79. #endif // ENABLE_ACL
  80. }
  81. return std::make_shared<CenterCropOperation>(size_);
  82. }
  83. // Crop Transform Operation.
  84. Crop::Crop(std::vector<int32_t> coordinates, std::vector<int32_t> size) : coordinates_(coordinates), size_(size) {}
  85. std::shared_ptr<TensorOperation> Crop::Parse() { return std::make_shared<CropOperation>(coordinates_, size_); }
  86. #ifndef ENABLE_ANDROID
  87. // CutMixBatch Transform Operation.
  88. CutMixBatch::CutMixBatch(ImageBatchFormat image_batch_format, float alpha, float prob)
  89. : image_batch_format_(image_batch_format), alpha_(alpha), prob_(prob) {}
  90. std::shared_ptr<TensorOperation> CutMixBatch::Parse() {
  91. return std::make_shared<CutMixBatchOperation>(image_batch_format_, alpha_, prob_);
  92. }
  93. // CutOutOp.
  94. CutOut::CutOut(int32_t length, int32_t num_patches) : length_(length), num_patches_(num_patches) {}
  95. std::shared_ptr<TensorOperation> CutOut::Parse() { return std::make_shared<CutOutOperation>(length_, num_patches_); }
  96. #endif // not ENABLE_ANDROID
  97. // Decode Transform Operation.
  98. Decode::Decode(bool rgb) : rgb_(rgb) {}
  99. std::shared_ptr<TensorOperation> Decode::Parse() { return std::make_shared<DecodeOperation>(rgb_); }
  100. std::shared_ptr<TensorOperation> Decode::Parse(const MapTargetDevice &env) {
  101. if (env == MapTargetDevice::kAscend310) {
  102. #ifdef ENABLE_ACL
  103. return std::make_shared<DvppDecodeJpegOperation>();
  104. #endif // ENABLE_ACL
  105. }
  106. return std::make_shared<DecodeOperation>(rgb_);
  107. }
  108. #ifdef ENABLE_ACL
  109. // DvppDecodeResize Transform Operation.
  110. DvppDecodeResizeJpeg::DvppDecodeResizeJpeg(std::vector<uint32_t> resize) : resize_(resize) {}
  111. std::shared_ptr<TensorOperation> DvppDecodeResizeJpeg::Parse() {
  112. return std::make_shared<DvppDecodeResizeOperation>(resize_);
  113. }
  114. std::shared_ptr<TensorOperation> DvppDecodeResizeJpeg::Parse(const MapTargetDevice &env) {
  115. return std::make_shared<DvppDecodeResizeOperation>(resize_);
  116. }
  117. // DvppDecodeResizeCrop Transform Operation.
  118. DvppDecodeResizeCropJpeg::DvppDecodeResizeCropJpeg(std::vector<uint32_t> crop, std::vector<uint32_t> resize)
  119. : crop_(crop), resize_(resize) {}
  120. std::shared_ptr<TensorOperation> DvppDecodeResizeCropJpeg::Parse() {
  121. return std::make_shared<DvppDecodeResizeCropOperation>(crop_, resize_);
  122. }
  123. std::shared_ptr<TensorOperation> DvppDecodeResizeCropJpeg::Parse(const MapTargetDevice &env) {
  124. return std::make_shared<DvppDecodeResizeCropOperation>(crop_, resize_);
  125. }
  126. // DvppDecodePng Transform Operation.
  127. DvppDecodePng::DvppDecodePng() {}
  128. std::shared_ptr<TensorOperation> DvppDecodePng::Parse() { return std::make_shared<DvppDecodePngOperation>(); }
  129. std::shared_ptr<TensorOperation> DvppDecodePng::Parse(const MapTargetDevice &env) {
  130. return std::make_shared<DvppDecodePngOperation>();
  131. }
  132. #endif // ENABLE_ACL
  133. #ifndef ENABLE_ANDROID
  134. // Equalize Transform Operation.
  135. Equalize::Equalize() {}
  136. std::shared_ptr<TensorOperation> Equalize::Parse() { return std::make_shared<EqualizeOperation>(); }
  137. // HwcToChw Transform Operation.
  138. HWC2CHW::HWC2CHW() {}
  139. std::shared_ptr<TensorOperation> HWC2CHW::Parse() { return std::make_shared<HwcToChwOperation>(); }
  140. // Invert Transform Operation.
  141. Invert::Invert() {}
  142. std::shared_ptr<TensorOperation> Invert::Parse() { return std::make_shared<InvertOperation>(); }
  143. // MixUpBatch Transform Operation.
  144. MixUpBatch::MixUpBatch(float alpha) : alpha_(alpha) {}
  145. std::shared_ptr<TensorOperation> MixUpBatch::Parse() { return std::make_shared<MixUpBatchOperation>(alpha_); }
  146. #endif // not ENABLE_ANDROID
  147. // Normalize Transform Operation.
  148. Normalize::Normalize(std::vector<float> mean, std::vector<float> std) : mean_(mean), std_(std) {}
  149. std::shared_ptr<TensorOperation> Normalize::Parse() { return std::make_shared<NormalizeOperation>(mean_, std_); }
  150. std::shared_ptr<TensorOperation> Normalize::Parse(const MapTargetDevice &env) {
  151. if (env == MapTargetDevice::kAscend310) {
  152. #ifdef ENABLE_ACL
  153. return std::make_shared<DvppNormalizeOperation>(mean_, std_);
  154. #endif
  155. }
  156. return std::make_shared<NormalizeOperation>(mean_, std_);
  157. }
  158. #ifndef ENABLE_ANDROID
  159. // NormalizePad Transform Operation.
  160. NormalizePad::NormalizePad(const std::vector<float> &mean, const std::vector<float> &std, const std::string &dtype)
  161. : mean_(mean), std_(std), dtype_(dtype) {}
  162. std::shared_ptr<TensorOperation> NormalizePad::Parse() {
  163. return std::make_shared<NormalizePadOperation>(mean_, std_, dtype_);
  164. }
  165. // Pad Transform Operation.
  166. Pad::Pad(std::vector<int32_t> padding, std::vector<uint8_t> fill_value, BorderType padding_mode)
  167. : padding_(padding), fill_value_(fill_value), padding_mode_(padding_mode) {}
  168. std::shared_ptr<TensorOperation> Pad::Parse() {
  169. return std::make_shared<PadOperation>(padding_, fill_value_, padding_mode_);
  170. }
  171. // RandomAffine Transform Operation.
  172. RandomAffine::RandomAffine(const std::vector<float_t> &degrees, const std::vector<float_t> &translate_range,
  173. const std::vector<float_t> &scale_range, const std::vector<float_t> &shear_ranges,
  174. InterpolationMode interpolation, const std::vector<uint8_t> &fill_value)
  175. : degrees_(degrees),
  176. translate_range_(translate_range),
  177. scale_range_(scale_range),
  178. shear_ranges_(shear_ranges),
  179. interpolation_(interpolation),
  180. fill_value_(fill_value) {}
  181. std::shared_ptr<TensorOperation> RandomAffine::Parse() {
  182. return std::make_shared<RandomAffineOperation>(degrees_, translate_range_, scale_range_, shear_ranges_,
  183. interpolation_, fill_value_);
  184. }
  185. // RandomColor Transform Operation.
  186. RandomColor::RandomColor(float t_lb, float t_ub) : t_lb_(t_lb), t_ub_(t_ub) {}
  187. std::shared_ptr<TensorOperation> RandomColor::Parse() { return std::make_shared<RandomColorOperation>(t_lb_, t_ub_); }
  188. // RandomColorAdjust Transform Operation.
  189. RandomColorAdjust::RandomColorAdjust(std::vector<float> brightness, std::vector<float> contrast,
  190. std::vector<float> saturation, std::vector<float> hue)
  191. : brightness_(brightness), contrast_(contrast), saturation_(saturation), hue_(hue) {}
  192. std::shared_ptr<TensorOperation> RandomColorAdjust::Parse() {
  193. return std::make_shared<RandomColorAdjustOperation>(brightness_, contrast_, saturation_, hue_);
  194. }
  195. // RandomCrop Transform Operation.
  196. RandomCrop::RandomCrop(std::vector<int32_t> size, std::vector<int32_t> padding, bool pad_if_needed,
  197. std::vector<uint8_t> fill_value, BorderType padding_mode)
  198. : size_(size),
  199. padding_(padding),
  200. pad_if_needed_(pad_if_needed),
  201. fill_value_(fill_value),
  202. padding_mode_(padding_mode) {}
  203. std::shared_ptr<TensorOperation> RandomCrop::Parse() {
  204. return std::make_shared<RandomCropOperation>(size_, padding_, pad_if_needed_, fill_value_, padding_mode_);
  205. }
  206. // RandomCropDecodeResize Transform Operation.
  207. RandomCropDecodeResize::RandomCropDecodeResize(std::vector<int32_t> size, std::vector<float> scale,
  208. std::vector<float> ratio, InterpolationMode interpolation,
  209. int32_t max_attempts)
  210. : size_(size), scale_(scale), ratio_(ratio), interpolation_(interpolation), max_attempts_(max_attempts) {}
  211. std::shared_ptr<TensorOperation> RandomCropDecodeResize::Parse() {
  212. return std::make_shared<RandomCropDecodeResizeOperation>(size_, scale_, ratio_, interpolation_, max_attempts_);
  213. }
  214. // RandomCropWithBBox Transform Operation.
  215. RandomCropWithBBox::RandomCropWithBBox(std::vector<int32_t> size, std::vector<int32_t> padding, bool pad_if_needed,
  216. std::vector<uint8_t> fill_value, BorderType padding_mode)
  217. : size_(size),
  218. padding_(padding),
  219. pad_if_needed_(pad_if_needed),
  220. fill_value_(fill_value),
  221. padding_mode_(padding_mode) {}
  222. std::shared_ptr<TensorOperation> RandomCropWithBBox::Parse() {
  223. return std::make_shared<RandomCropWithBBoxOperation>(size_, padding_, pad_if_needed_, fill_value_, padding_mode_);
  224. }
  225. // RandomHorizontalFlip.
  226. RandomHorizontalFlip::RandomHorizontalFlip(float prob) : probability_(prob) {}
  227. std::shared_ptr<TensorOperation> RandomHorizontalFlip::Parse() {
  228. return std::make_shared<RandomHorizontalFlipOperation>(probability_);
  229. }
  230. // RandomHorizontalFlipWithBBox
  231. RandomHorizontalFlipWithBBox::RandomHorizontalFlipWithBBox(float prob) : probability_(prob) {}
  232. std::shared_ptr<TensorOperation> RandomHorizontalFlipWithBBox::Parse() {
  233. return std::make_shared<RandomHorizontalFlipWithBBoxOperation>(probability_);
  234. }
  235. // RandomPosterize Transform Operation.
  236. RandomPosterize::RandomPosterize(const std::vector<uint8_t> &bit_range) : bit_range_(bit_range) {}
  237. std::shared_ptr<TensorOperation> RandomPosterize::Parse() {
  238. return std::make_shared<RandomPosterizeOperation>(bit_range_);
  239. }
  240. // RandomResize Transform Operation.
  241. RandomResize::RandomResize(std::vector<int32_t> size) : size_(size) {}
  242. std::shared_ptr<TensorOperation> RandomResize::Parse() { return std::make_shared<RandomResizeOperation>(size_); }
  243. // RandomResizeWithBBox Transform Operation.
  244. RandomResizeWithBBox::RandomResizeWithBBox(std::vector<int32_t> size) : size_(size) {}
  245. std::shared_ptr<TensorOperation> RandomResizeWithBBox::Parse() {
  246. return std::make_shared<RandomResizeWithBBoxOperation>(size_);
  247. }
  248. // RandomResizedCrop Transform Operation.
  249. RandomResizedCrop::RandomResizedCrop(std::vector<int32_t> size, std::vector<float> scale, std::vector<float> ratio,
  250. InterpolationMode interpolation, int32_t max_attempts)
  251. : size_(size), scale_(scale), ratio_(ratio), interpolation_(interpolation), max_attempts_(max_attempts) {}
  252. std::shared_ptr<TensorOperation> RandomResizedCrop::Parse() {
  253. return std::make_shared<RandomResizedCropOperation>(size_, scale_, ratio_, interpolation_, max_attempts_);
  254. }
  255. // RandomResizedCrop Transform Operation.
  256. RandomResizedCropWithBBox::RandomResizedCropWithBBox(std::vector<int32_t> size, std::vector<float> scale,
  257. std::vector<float> ratio, InterpolationMode interpolation,
  258. int32_t max_attempts)
  259. : size_(size), scale_(scale), ratio_(ratio), interpolation_(interpolation), max_attempts_(max_attempts) {}
  260. std::shared_ptr<TensorOperation> RandomResizedCropWithBBox::Parse() {
  261. return std::make_shared<RandomResizedCropWithBBoxOperation>(size_, scale_, ratio_, interpolation_, max_attempts_);
  262. }
  263. // RandomRotation Transform Operation.
  264. RandomRotation::RandomRotation(std::vector<float> degrees, InterpolationMode interpolation_mode, bool expand,
  265. std::vector<float> center, std::vector<uint8_t> fill_value)
  266. : degrees_(degrees),
  267. interpolation_mode_(interpolation_mode),
  268. expand_(expand),
  269. center_(center),
  270. fill_value_(fill_value) {}
  271. std::shared_ptr<TensorOperation> RandomRotation::Parse() {
  272. return std::make_shared<RandomRotationOperation>(degrees_, interpolation_mode_, expand_, center_, fill_value_);
  273. }
  274. // RandomSelectSubpolicy Transform Operation.
  275. RandomSelectSubpolicy::RandomSelectSubpolicy(std::vector<std::vector<std::pair<TensorTransform *, double>>> policy) {
  276. for (int32_t i = 0; i < policy.size(); i++) {
  277. std::vector<std::pair<std::shared_ptr<TensorOperation>, double>> subpolicy;
  278. for (int32_t j = 0; j < policy[i].size(); j++) {
  279. TensorTransform *op = policy[i][j].first;
  280. std::shared_ptr<TensorOperation> operation = (op ? op->Parse() : nullptr);
  281. double prob = policy[i][j].second;
  282. subpolicy.emplace_back(std::move(std::make_pair(operation, prob)));
  283. }
  284. policy_.emplace_back(subpolicy);
  285. }
  286. }
  287. RandomSelectSubpolicy::RandomSelectSubpolicy(
  288. std::vector<std::vector<std::pair<std::shared_ptr<TensorTransform>, double>>> policy) {
  289. for (int32_t i = 0; i < policy.size(); i++) {
  290. std::vector<std::pair<std::shared_ptr<TensorOperation>, double>> subpolicy;
  291. for (int32_t j = 0; j < policy[i].size(); j++) {
  292. std::shared_ptr<TensorTransform> op = policy[i][j].first;
  293. std::shared_ptr<TensorOperation> operation = (op ? op->Parse() : nullptr);
  294. double prob = policy[i][j].second;
  295. subpolicy.emplace_back(std::move(std::make_pair(operation, prob)));
  296. }
  297. policy_.emplace_back(subpolicy);
  298. }
  299. }
  300. RandomSelectSubpolicy::RandomSelectSubpolicy(
  301. std::vector<std::vector<std::pair<std::reference_wrapper<TensorTransform>, double>>> policy) {
  302. for (int32_t i = 0; i < policy.size(); i++) {
  303. std::vector<std::pair<std::shared_ptr<TensorOperation>, double>> subpolicy;
  304. for (int32_t j = 0; j < policy[i].size(); j++) {
  305. TensorTransform &op = policy[i][j].first;
  306. std::shared_ptr<TensorOperation> operation = op.Parse();
  307. double prob = policy[i][j].second;
  308. subpolicy.emplace_back(std::move(std::make_pair(operation, prob)));
  309. }
  310. policy_.emplace_back(subpolicy);
  311. }
  312. }
  313. std::shared_ptr<TensorOperation> RandomSelectSubpolicy::Parse() {
  314. return std::make_shared<RandomSelectSubpolicyOperation>(policy_);
  315. }
  316. // RandomSharpness Transform Operation.
  317. RandomSharpness::RandomSharpness(std::vector<float> degrees) : degrees_(degrees) {}
  318. std::shared_ptr<TensorOperation> RandomSharpness::Parse() {
  319. return std::make_shared<RandomSharpnessOperation>(degrees_);
  320. }
  321. // RandomSolarize Transform Operation.
  322. RandomSolarize::RandomSolarize(std::vector<uint8_t> threshold) : threshold_(threshold) {}
  323. std::shared_ptr<TensorOperation> RandomSolarize::Parse() {
  324. return std::make_shared<RandomSolarizeOperation>(threshold_);
  325. }
  326. // RandomVerticalFlip Transform Operation.
  327. RandomVerticalFlip::RandomVerticalFlip(float prob) : probability_(prob) {}
  328. std::shared_ptr<TensorOperation> RandomVerticalFlip::Parse() {
  329. return std::make_shared<RandomVerticalFlipOperation>(probability_);
  330. }
  331. // RandomVerticalFlipWithBBox Transform Operation.
  332. RandomVerticalFlipWithBBox::RandomVerticalFlipWithBBox(float prob) : probability_(prob) {}
  333. std::shared_ptr<TensorOperation> RandomVerticalFlipWithBBox::Parse() {
  334. return std::make_shared<RandomVerticalFlipWithBBoxOperation>(probability_);
  335. }
  336. // Rescale Transform Operation.
  337. Rescale::Rescale(float rescale, float shift) : rescale_(rescale), shift_(shift) {}
  338. std::shared_ptr<TensorOperation> Rescale::Parse() { return std::make_shared<RescaleOperation>(rescale_, shift_); }
  339. #endif // not ENABLE_ANDROID
  340. // Resize Transform Operation.
  341. Resize::Resize(std::vector<int32_t> size, InterpolationMode interpolation)
  342. : size_(size), interpolation_(interpolation) {}
  343. std::shared_ptr<TensorOperation> Resize::Parse() { return std::make_shared<ResizeOperation>(size_, interpolation_); }
  344. std::shared_ptr<TensorOperation> Resize::Parse(const MapTargetDevice &env) {
  345. if (env == MapTargetDevice::kAscend310) {
  346. #ifdef ENABLE_ACL
  347. std::vector<uint32_t> usize_;
  348. usize_.reserve(size_.size());
  349. std::transform(size_.begin(), size_.end(), std::back_inserter(usize_), [](int32_t i) { return (uint32_t)i; });
  350. return std::make_shared<DvppResizeJpegOperation>(usize_);
  351. #endif // ENABLE_ACL
  352. }
  353. return std::make_shared<ResizeOperation>(size_, interpolation_);
  354. }
  355. #ifdef ENABLE_ANDROID
  356. // Rotate Transform Operation.
  357. Rotate::Rotate() {}
  358. std::shared_ptr<TensorOperation> Rotate::Parse() { return std::make_shared<RotateOperation>(); }
  359. #endif // ENABLE_ANDROID
  360. #ifndef ENABLE_ANDROID
  361. // ResizeWithBBox Transform Operation.
  362. ResizeWithBBox::ResizeWithBBox(std::vector<int32_t> size, InterpolationMode interpolation)
  363. : size_(size), interpolation_(interpolation) {}
  364. std::shared_ptr<TensorOperation> ResizeWithBBox::Parse() {
  365. return std::make_shared<ResizeWithBBoxOperation>(size_, interpolation_);
  366. }
  367. // RgbaToBgr Transform Operation.
  368. RGBA2BGR::RGBA2BGR() {}
  369. std::shared_ptr<TensorOperation> RGBA2BGR::Parse() { return std::make_shared<RgbaToBgrOperation>(); }
  370. // RgbaToRgb Transform Operation.
  371. RGBA2RGB::RGBA2RGB() {}
  372. std::shared_ptr<TensorOperation> RGBA2RGB::Parse() { return std::make_shared<RgbaToRgbOperation>(); }
  373. // SoftDvppDecodeRandomCropResizeJpeg Transform Operation.
  374. SoftDvppDecodeRandomCropResizeJpeg::SoftDvppDecodeRandomCropResizeJpeg(std::vector<int32_t> size,
  375. std::vector<float> scale,
  376. std::vector<float> ratio, int32_t max_attempts)
  377. : size_(size), scale_(scale), ratio_(ratio), max_attempts_(max_attempts) {}
  378. std::shared_ptr<TensorOperation> SoftDvppDecodeRandomCropResizeJpeg::Parse() {
  379. return std::make_shared<SoftDvppDecodeRandomCropResizeJpegOperation>(size_, scale_, ratio_, max_attempts_);
  380. }
  381. // SoftDvppDecodeResizeJpeg Transform Operation.
  382. SoftDvppDecodeResizeJpeg::SoftDvppDecodeResizeJpeg(std::vector<int32_t> size) : size_(size) {}
  383. std::shared_ptr<TensorOperation> SoftDvppDecodeResizeJpeg::Parse() {
  384. return std::make_shared<SoftDvppDecodeResizeJpegOperation>(size_);
  385. }
  386. // SwapRedBlue Transform Operation.
  387. SwapRedBlue::SwapRedBlue() {}
  388. std::shared_ptr<TensorOperation> SwapRedBlue::Parse() { return std::make_shared<SwapRedBlueOperation>(); }
  389. // UniformAug Transform Operation.
  390. UniformAugment::UniformAugment(const std::vector<TensorTransform *> &transforms, int32_t num_ops) : num_ops_(num_ops) {
  391. (void)std::transform(
  392. transforms.begin(), transforms.end(), std::back_inserter(transforms_),
  393. [](TensorTransform *op) -> std::shared_ptr<TensorOperation> { return op ? op->Parse() : nullptr; });
  394. }
  395. UniformAugment::UniformAugment(const std::vector<std::shared_ptr<TensorTransform>> &transforms, int32_t num_ops)
  396. : num_ops_(num_ops) {
  397. (void)std::transform(
  398. transforms.begin(), transforms.end(), std::back_inserter(transforms_),
  399. [](std::shared_ptr<TensorTransform> op) -> std::shared_ptr<TensorOperation> { return op ? op->Parse() : nullptr; });
  400. }
  401. UniformAugment::UniformAugment(const std::vector<std::reference_wrapper<TensorTransform>> &transforms, int32_t num_ops)
  402. : num_ops_(num_ops) {
  403. (void)std::transform(transforms.begin(), transforms.end(), std::back_inserter(transforms_),
  404. [](TensorTransform &op) -> std::shared_ptr<TensorOperation> { return op.Parse(); });
  405. }
  406. std::shared_ptr<TensorOperation> UniformAugment::Parse() {
  407. return std::make_shared<UniformAugOperation>(transforms_, num_ops_);
  408. }
  409. #endif // not ENABLE_ANDROID
  410. } // namespace vision
  411. } // namespace dataset
  412. } // namespace mindspore