| 276 | } |
| 277 | |
| 278 | const 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 | |
| 299 | const Tensor FeedForwardNet::PredictOnBatch(const Tensor& x) { |
| 300 | return Forward(kEval, x); |
nothing calls this directly
no test coverage detected