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

Method Predict

src/model/feed_forward_net.cc:278–297  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

276}
277
278const Tensor FeedForwardNet::Predict(const Tensor& x, size_t batchsize) {
279 CHECK_GE(x.shape(0), batchsize);
280 int num_extra_samples = (int)(x.shape(0) % batchsize);
281 const auto outshape = layers_.back()->GetOutputSampleShape();
282 Tensor y(Shape{x.shape(0), Product(outshape)}, x.device());
283 for (size_t b = 0; b < x.shape(0) / batchsize; b++) {
284 int start = (int)(b * batchsize), end = (int)(start + batchsize);
285 const Tensor bx = CopyRows(x, start, end);
286 CopyDataToFrom(&y, PredictOnBatch(bx), batchsize * y.shape(1),
287 start * y.shape(1), 0);
288 }
289 if (num_extra_samples > 0) {
290 int start = (int)(x.shape(0) - batchsize), end = (int)(x.shape(0));
291 const Tensor bx = CopyRows(x, start, end);
292 CopyDataToFrom(&y, PredictOnBatch(bx), num_extra_samples * y.shape(1),
293 (x.shape(0) - num_extra_samples) * y.shape(1),
294 (batchsize - num_extra_samples) * y.shape(1));
295 }
296 return y;
297}
298
299const Tensor FeedForwardNet::PredictOnBatch(const Tensor& x) {
300 return Forward(kEval, x);

Callers

nothing calls this directly

Calls 6

ProductFunction · 0.85
CopyRowsFunction · 0.85
CopyDataToFromFunction · 0.85
shapeMethod · 0.80
deviceMethod · 0.80
GetOutputSampleShapeMethod · 0.45

Tested by

no test coverage detected