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.1 kB

5 years ago
5 years ago
5 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /**
  2. * Copyright 2020 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. #include "minddata/dataset/kernels/image/image_utils.h"
  18. // Kernel data headers (in alphabetical order)
  19. #include "minddata/dataset/kernels/data/one_hot_op.h"
  20. namespace mindspore {
  21. namespace dataset {
  22. namespace api {
  23. TensorOperation::TensorOperation() {}
  24. // Transform operations for data.
  25. namespace transforms {
  26. // FUNCTIONS TO CREATE DATA TRANSFORM OPERATIONS
  27. // (In alphabetical order)
  28. // Function to create OneHotOperation.
  29. std::shared_ptr<OneHotOperation> OneHot(int32_t num_classes) {
  30. auto op = std::make_shared<OneHotOperation>(num_classes);
  31. // Input validation
  32. if (!op->ValidateParams()) {
  33. return nullptr;
  34. }
  35. return op;
  36. }
  37. /* ####################################### Validator Functions ############################################ */
  38. /* ####################################### Derived TensorOperation classes ################################# */
  39. // (In alphabetical order)
  40. // OneHotOperation
  41. OneHotOperation::OneHotOperation(int32_t num_classes) : num_classes_(num_classes) {}
  42. bool OneHotOperation::ValidateParams() {
  43. if (num_classes_ < 0) {
  44. MS_LOG(ERROR) << "OneHot: Number of classes cannot be negative. Number of classes: " << num_classes_;
  45. return false;
  46. }
  47. return true;
  48. }
  49. std::shared_ptr<TensorOp> OneHotOperation::Build() { return std::make_shared<OneHotOp>(num_classes_); }
  50. } // namespace transforms
  51. } // namespace api
  52. } // namespace dataset
  53. } // namespace mindspore