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