MCPcopy Create free account
hub / github.com/apache/singa / TrainOnBatch

Method TrainOnBatch

src/model/feed_forward_net.cc:190–205  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

188}
189
190const std::pair<float, float> FeedForwardNet::TrainOnBatch(int epoch,
191 const Tensor& x,
192 const Tensor& y) {
193 int flag = kTrain;
194 const Tensor fea = Forward(flag, x);
195 float loss = loss_->Evaluate(flag, fea, y);
196 float metric = metric_->Evaluate(fea, y);
197 const Tensor grad = loss_->Backward();
198 auto grads = Backward(kTrain, grad / static_cast<float>(x.shape(0)));
199 auto names = GetParamNames();
200 auto values = GetParamValues();
201 for (size_t k = 0; k < grads.size(); k++) {
202 updater_->Apply(epoch, names[k], grads[k], values.at(k));
203 }
204 return std::make_pair(loss, metric);
205}
206
207const Tensor FeedForwardNet::Forward(int flag, const Tensor& data) {
208 Tensor input = data, output;

Callers 1

TrainOneEpochFunction · 0.80

Calls 5

shapeMethod · 0.80
EvaluateMethod · 0.45
BackwardMethod · 0.45
sizeMethod · 0.45
ApplyMethod · 0.45

Tested by

no test coverage detected