| 32 | } |
| 33 | |
| 34 | std::vector<Example> DataLoader::next() { |
| 35 | if (mConfig->numWorkers == 0) { |
| 36 | auto batchIndices = mSampler->next(mConfig->batchSize); |
| 37 | MNN_ASSERT(batchIndices.size() != 0); // the sampler is exhausted, should reset the data loader |
| 38 | if (mConfig->dropLast && batchIndices.size() < mConfig->batchSize) { |
| 39 | MNN_ASSERT(false); // the sampler is exhausted |
| 40 | } |
| 41 | auto batch = mDataset->getBatch(batchIndices); |
| 42 | return batch; |
| 43 | } else { |
| 44 | auto batch = mDataQueue->pop(); |
| 45 | prefetch(1); |
| 46 | return batch; |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | void DataLoader::prefetch(size_t nJobs) { |
| 51 | MNN_ASSERT(mJobs != nullptr); |