| 54 | // This function is called on prefetch thread |
| 55 | template<typename Dtype> |
| 56 | void DataLayer<Dtype>::load_batch(Batch<Dtype>* batch) { |
| 57 | CPUTimer batch_timer; |
| 58 | batch_timer.Start(); |
| 59 | double read_time = 0; |
| 60 | double trans_time = 0; |
| 61 | CPUTimer timer; |
| 62 | CHECK(batch->data_.count()); |
| 63 | CHECK(this->transformed_data_.count()); |
| 64 | |
| 65 | // Reshape according to the first datum of each batch |
| 66 | // on single input batches allows for inputs of varying dimension. |
| 67 | const int batch_size = this->layer_param_.data_param().batch_size(); |
| 68 | Datum& datum = *(reader_.full().peek()); |
| 69 | // Use data_transformer to infer the expected blob shape from datum. |
| 70 | vector<int> top_shape = this->data_transformer_->InferBlobShape(datum); |
| 71 | this->transformed_data_.Reshape(top_shape); |
| 72 | // Reshape batch according to the batch_size. |
| 73 | top_shape[0] = batch_size; |
| 74 | batch->data_.Reshape(top_shape); |
| 75 | |
| 76 | Dtype* top_data = batch->data_.mutable_cpu_data(); |
| 77 | Dtype* top_label = NULL; // suppress warnings about uninitialized variables |
| 78 | |
| 79 | if (this->output_labels_) { |
| 80 | top_label = batch->label_.mutable_cpu_data(); |
| 81 | } |
| 82 | for (int item_id = 0; item_id < batch_size; ++item_id) { |
| 83 | timer.Start(); |
| 84 | // get a datum |
| 85 | Datum& datum = *(reader_.full().pop("Waiting for data")); |
| 86 | read_time += timer.MicroSeconds(); |
| 87 | timer.Start(); |
| 88 | // Apply data transformations (mirror, scale, crop...) |
| 89 | int offset = batch->data_.offset(item_id); |
| 90 | this->transformed_data_.set_cpu_data(top_data + offset); |
| 91 | this->data_transformer_->Transform(datum, &(this->transformed_data_)); |
| 92 | // Copy label. |
| 93 | if (this->output_labels_) { |
| 94 | top_label[item_id] = datum.label(); |
| 95 | } |
| 96 | trans_time += timer.MicroSeconds(); |
| 97 | |
| 98 | reader_.free().push(const_cast<Datum*>(&datum)); |
| 99 | } |
| 100 | timer.Stop(); |
| 101 | batch_timer.Stop(); |
| 102 | DLOG(INFO) << "Prefetch batch: " << batch_timer.MilliSeconds() << " ms."; |
| 103 | DLOG(INFO) << " Read time: " << read_time / 1000 << " ms."; |
| 104 | DLOG(INFO) << "Transform time: " << trans_time / 1000 << " ms."; |
| 105 | } |
| 106 | |
| 107 | INSTANTIATE_CLASS(DataLayer); |
| 108 | REGISTER_LAYER_CLASS(Data); |
nothing calls this directly
no test coverage detected