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.

transforms.cc 2.8 kB

5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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/transforms.h"
  17. namespace mindspore {
  18. namespace dataset {
  19. // Transform operations for data.
  20. namespace transforms {
  21. // FUNCTIONS TO CREATE DATA TRANSFORM OPERATIONS
  22. // (In alphabetical order)
  23. // Function to create ComposeOperation.
  24. std::shared_ptr<ComposeOperation> Compose(const std::vector<std::shared_ptr<TensorOperation>> &transforms) {
  25. auto op = std::make_shared<ComposeOperation>(transforms);
  26. // Input validation
  27. return op->ValidateParams() ? op : nullptr;
  28. }
  29. // Function to create DuplicateOperation.
  30. std::shared_ptr<DuplicateOperation> Duplicate() {
  31. auto op = std::make_shared<DuplicateOperation>();
  32. // Input validation
  33. return op->ValidateParams() ? op : nullptr;
  34. }
  35. // Function to create OneHotOperation.
  36. std::shared_ptr<OneHotOperation> OneHot(int32_t num_classes) {
  37. auto op = std::make_shared<OneHotOperation>(num_classes);
  38. // Input validation
  39. return op->ValidateParams() ? op : nullptr;
  40. }
  41. // Function to create RandomApplyOperation.
  42. std::shared_ptr<RandomApplyOperation> RandomApply(const std::vector<std::shared_ptr<TensorOperation>> &transforms,
  43. double prob) {
  44. auto op = std::make_shared<RandomApplyOperation>(transforms, prob);
  45. // Input validation
  46. return op->ValidateParams() ? op : nullptr;
  47. }
  48. // Function to create RandomChoiceOperation.
  49. std::shared_ptr<RandomChoiceOperation> RandomChoice(const std::vector<std::shared_ptr<TensorOperation>> &transforms) {
  50. auto op = std::make_shared<RandomChoiceOperation>(transforms);
  51. // Input validation
  52. return op->ValidateParams() ? op : nullptr;
  53. }
  54. // Function to create TypeCastOperation.
  55. std::shared_ptr<TypeCastOperation> TypeCast(std::string data_type) {
  56. auto op = std::make_shared<TypeCastOperation>(data_type);
  57. // Input validation
  58. return op->ValidateParams() ? op : nullptr;
  59. }
  60. #ifndef ENABLE_ANDROID
  61. // Function to create UniqueOperation.
  62. std::shared_ptr<UniqueOperation> Unique() {
  63. auto op = std::make_shared<UniqueOperation>();
  64. // Input validation
  65. return op->ValidateParams() ? op : nullptr;
  66. }
  67. #endif
  68. } // namespace transforms
  69. } // namespace dataset
  70. } // namespace mindspore