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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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 actual callback function for begin, needs to be overridden in the derived class
  31. /// \param cb_param, callback parameter passed in from DatasetOp when calling the callback
  32. /// \return Status
  33. virtual Status DSBegin(const CallbackParam &cb_param) = 0;
  34. /// \brief actual callback function for epoch_begin, needs to be overridden in the derived class
  35. /// \param cb_param, callback parameter passed in from DatasetOp when calling the callback
  36. /// \return Status
  37. virtual Status DSEpochBegin(const CallbackParam &cb_param) = 0;
  38. /// \brief actual callback function for step_begin, needs to be overridden in the derived class
  39. /// \param cb_param, callback parameter passed in from DatasetOp when calling the callback
  40. /// \return Status
  41. virtual Status DSNStepBegin(const CallbackParam &cb_param) = 0;
  42. /// \brief actual callback function for end, needs to be overridden in the derived class
  43. /// \param cb_param, callback parameter passed in from DatasetOp when calling the callback
  44. /// \return Status
  45. virtual Status DSEnd(const CallbackParam &cb_param) = 0;
  46. /// \brief actual callback function epoch_end begin, needs to be overridden in the derived class
  47. /// \param cb_param, callback parameter passed in from DatasetOp when calling the callback
  48. /// \return Status
  49. virtual Status DSEpochEnd(const CallbackParam &cb_param) = 0;
  50. /// \brief actual callback function for step_end, needs to be overridden in the derived class
  51. /// \param cb_param, callback parameter passed in from DatasetOp when calling the callback
  52. /// \return Status
  53. virtual Status DSNStepEnd(const CallbackParam &cb_param) = 0;
  54. /// \brief predicate function, whether begin callback is needed
  55. /// \return bool
  56. virtual bool IsBeginNeeded() = 0;
  57. /// \brief predicate function, whether epoch_begin callback is needed
  58. /// \return bool
  59. virtual bool IsEpochBeginNeeded() = 0;
  60. /// \brief predicate function, whether step_begin callback is needed
  61. /// \return bool
  62. virtual bool IsNStepBeginNeeded() = 0;
  63. /// \brief predicate function, whether end callback is needed
  64. /// \return bool
  65. virtual bool IsEndNeeded() = 0;
  66. /// \brief predicate function, whether epoch_end callback is needed
  67. /// \return bool
  68. virtual bool IsEpochEndNeeded() = 0;
  69. /// \brief predicate function, whether step_end callback is needed
  70. /// \return bool
  71. virtual bool IsNStepEndNeeded() = 0;
  72. /// \brief getter
  73. /// \return step_size
  74. int32_t step_size() const { return step_size_; }
  75. protected:
  76. int32_t step_size_; // step begin/end will be called every step_size_
  77. };
  78. } // namespace dataset
  79. } // namespace mindspore
  80. #endif // MINDSPORE_CCSRC_MINDDATA_DATASET_DS_CALLBACK_H