19 #ifndef SINGA_MODEL_LOSS_H_ 20 #define SINGA_MODEL_LOSS_H_ 22 #include "singa/proto/model.pb.h" 23 #include "singa/core/tensor.h" 34 void Setup(
const string &conf) {
36 loss.ParseFromString(conf);
40 virtual void ToDevice(std::shared_ptr<Device> device) {}
42 virtual void Setup(
const LossConf &conf) {}
54 return Sum<float>(loss) / (1.0f * loss.
Size());
70 const Tensor& target)
override;
78 std::stack<Tensor> buf_;
100 const Tensor& target)
override;
109 std::stack<Tensor> buf_;
114 #endif // SINGA_MODEL_LOSS_H_ virtual Tensor Forward(int flag, const Tensor &prediction, const Tensor &target)=0
Compute the loss values for each sample/instance given the prediction and the target.
Softmax + cross entropy for multi-category classification.
Definition: loss.h:84
virtual Tensor Backward()=0
Compute the gradients of the loss values w.r.t. the prediction.
A Tensor instance is a multi-dimensional array resident on a Device (default device is the host CPU)...
Definition: tensor.h:56
The base loss class, which declares the APIs for computing the objective score (loss) for a pair of p...
Definition: loss.h:31
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements...
Definition: common.h:48
size_t Size() const
Return number of total elements.
Definition: tensor.h:128
MSE is for mean squared error or squared euclidean distance.
Definition: loss.h:63
float Evaluate(int flag, const Tensor &prediction, const Tensor &target)
Average loss values for all samples in the mini-batch It calls Forward() internally.
Definition: loss.h:52
virtual void Setup(const LossConf &conf)
Set meta fields from user configurations.
Definition: loss.h:42