| 24 | |
| 25 | template <typename Dtype> |
| 26 | void DataLayer<Dtype>::DataLayerSetUp(const vector<Blob<Dtype>*>& bottom, |
| 27 | const vector<Blob<Dtype>*>& top) { |
| 28 | const int batch_size = this->layer_param_.data_param().batch_size(); |
| 29 | // Read a data point, and use it to initialize the top blob. |
| 30 | Datum& datum = *(reader_.full().peek()); |
| 31 | |
| 32 | // Use data_transformer to infer the expected blob shape from datum. |
| 33 | vector<int> top_shape = this->data_transformer_->InferBlobShape(datum); |
| 34 | this->transformed_data_.Reshape(top_shape); |
| 35 | // Reshape top[0] and prefetch_data according to the batch_size. |
| 36 | top_shape[0] = batch_size; |
| 37 | top[0]->Reshape(top_shape); |
| 38 | for (int i = 0; i < this->PREFETCH_COUNT; ++i) { |
| 39 | this->prefetch_[i].data_.Reshape(top_shape); |
| 40 | } |
| 41 | LOG(INFO) << "output data size: " << top[0]->num() << "," |
| 42 | << top[0]->channels() << "," << top[0]->height() << "," |
| 43 | << top[0]->width(); |
| 44 | // label |
| 45 | if (this->output_labels_) { |
| 46 | vector<int> label_shape(1, batch_size); |
| 47 | top[1]->Reshape(label_shape); |
| 48 | for (int i = 0; i < this->PREFETCH_COUNT; ++i) { |
| 49 | this->prefetch_[i].label_.Reshape(label_shape); |
| 50 | } |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | // This function is called on prefetch thread |
| 55 | template<typename Dtype> |