阿对对队的一次提交尝试(进行了小部分的代码评注) #8
|
|
@ -31,6 +31,7 @@ class CallbackImpl;
|
|||
|
||||
using GraphPoint = std::pair<int, float>;
|
||||
|
||||
/// The TrainCallBackData class defines a set of parameters for training callbacks.
|
||||
struct TrainCallBackData {
|
||||
TrainCallBackData(bool train_mode, int epoch, int step, Model *model): train_mode_(train_mode), epoch_(epoch),
|
||||
step_(step), model_(model) {}
|
||||
|
|
@ -41,6 +42,7 @@ struct TrainCallBackData {
|
|||
Model *model_; /**< pointer to the Model object */
|
||||
};
|
||||
|
||||
/// The CallbackRetValue class represents whether to continue looping in training.
|
||||
enum CallbackRetValue : uint32_t {
|
||||
kContinue = 0,
|
||||
kStopTraining = 1,
|
||||
|
|
@ -48,6 +50,8 @@ enum CallbackRetValue : uint32_t {
|
|||
kUnknownRetValue = 0xFFFFFFFF
|
||||
};
|
||||
|
||||
/// TrainCallBack is the training callback class in MindSpore Lite.
|
||||
/// In MindSpore, the callback function is actually not a function but a class.
|
||||
class TrainCallBack {
|
||||
public:
|
||||
virtual ~TrainCallBack() = default;
|
||||
|
|
@ -88,6 +92,8 @@ class TrainCallBack {
|
|||
virtual void StepEnd(const TrainCallBackData &cb_data) {}
|
||||
|
||||
protected:
|
||||
/// Due to TrainCallBack being used for implementing callbacks during the training process, the Model class and ModelImpl class need to access its private methods.
|
||||
/// This is achieved through the use of friend classes.
|
||||
friend class Model;
|
||||
friend class ModelImpl;
|
||||
CallbackImpl* callback_impl_ = nullptr;
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/// Prevent multiple inclusion of header files
|
||||
#ifndef MINDSPORE_INCLUDE_API_METRICS_METRICS_H
|
||||
#define MINDSPORE_INCLUDE_API_METRICS_METRICS_H
|
||||
#include <vector>
|
||||
|
|
@ -24,11 +25,19 @@ class MetricsImpl;
|
|||
class ModelImpl;
|
||||
class MSTensor;
|
||||
|
||||
/// Metrics are indicators used to evaluate the performance of a model.
|
||||
class Metrics {
|
||||
public:
|
||||
virtual ~Metrics() = default;
|
||||
/// Virtual destructor
|
||||
virtual ~Metrics() = default;
|
||||
virtual void Clear() {}
|
||||
|
||||
/// Eval() is a method for evaluating the model.
|
||||
/// This method returns a floating-point number that represents the evaluation result of the model using the specified metrics.
|
||||
/// Default return 0.0 .
|
||||
virtual float Eval() { return 0.0; }
|
||||
|
||||
|
||||
virtual void Update(std::vector<MSTensor *> inputs, std::vector<MSTensor *> outputs) {}
|
||||
protected:
|
||||
friend class Model;
|
||||
|
|
|
|||
Loading…
Reference in New Issue