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.

ds_callback.h 3.9 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. #ifndef MINDSPORE_CCSRC_MINDDATA_DATASET_DS_CALLBACK_H
  17. #define MINDSPORE_CCSRC_MINDDATA_DATASET_DS_CALLBACK_H
  18. #include <memory>
  19. #include <utility>
  20. #include <vector>
  21. #include "minddata/dataset/callback/callback_param.h"
  22. #include "minddata/dataset/util/status.h"
  23. namespace mindspore {
  24. namespace dataset {
  25. class DSCallback {
  26. public:
  27. /// \brief constructor of DSCallback, this is the base class for all front end specific callbacks
  28. /// \param step_size number of steps to call DSNStepBegin()
  29. explicit DSCallback(int32_t step_size = 1) : step_size_(step_size) {}
  30. /// \brief Destructor
  31. ~DSCallback() = default;
  32. /// \brief actual callback function for begin, needs to be overridden in the derived class
  33. /// \param cb_param, callback parameter passed in from DatasetOp when calling the callback
  34. /// \return Status
  35. virtual Status DSBegin(const CallbackParam &cb_param) = 0;
  36. /// \brief actual callback function for epoch_begin, needs to be overridden in the derived class
  37. /// \param cb_param, callback parameter passed in from DatasetOp when calling the callback
  38. /// \return Status
  39. virtual Status DSEpochBegin(const CallbackParam &cb_param) = 0;
  40. /// \brief actual callback function for step_begin, needs to be overridden in the derived class
  41. /// \param cb_param, callback parameter passed in from DatasetOp when calling the callback
  42. /// \return Status
  43. virtual Status DSNStepBegin(const CallbackParam &cb_param) = 0;
  44. /// \brief actual callback function for end, needs to be overridden in the derived class
  45. /// \param cb_param, callback parameter passed in from DatasetOp when calling the callback
  46. /// \return Status
  47. virtual Status DSEnd(const CallbackParam &cb_param) = 0;
  48. /// \brief actual callback function epoch_end begin, needs to be overridden in the derived class
  49. /// \param cb_param, callback parameter passed in from DatasetOp when calling the callback
  50. /// \return Status
  51. virtual Status DSEpochEnd(const CallbackParam &cb_param) = 0;
  52. /// \brief actual callback function for step_end, needs to be overridden in the derived class
  53. /// \param cb_param, callback parameter passed in from DatasetOp when calling the callback
  54. /// \return Status
  55. virtual Status DSNStepEnd(const CallbackParam &cb_param) = 0;
  56. /// \brief predicate function, whether begin callback is needed
  57. /// \return bool
  58. virtual bool IsBeginNeeded() = 0;
  59. /// \brief predicate function, whether epoch_begin callback is needed
  60. /// \return bool
  61. virtual bool IsEpochBeginNeeded() = 0;
  62. /// \brief predicate function, whether step_begin callback is needed
  63. /// \return bool
  64. virtual bool IsNStepBeginNeeded() = 0;
  65. /// \brief predicate function, whether end callback is needed
  66. /// \return bool
  67. virtual bool IsEndNeeded() = 0;
  68. /// \brief predicate function, whether epoch_end callback is needed
  69. /// \return bool
  70. virtual bool IsEpochEndNeeded() = 0;
  71. /// \brief predicate function, whether step_end callback is needed
  72. /// \return bool
  73. virtual bool IsNStepEndNeeded() = 0;
  74. /// \brief getter
  75. /// \return step_size
  76. int32_t step_size() const { return step_size_; }
  77. protected:
  78. int32_t step_size_; // step begin/end will be called every step_size_
  79. };
  80. } // namespace dataset
  81. } // namespace mindspore
  82. #endif // MINDSPORE_CCSRC_MINDDATA_DATASET_DS_CALLBACK_H