| 27 | |
| 28 | template <typename Dtype> |
| 29 | void DataLayer<Dtype>::DataLayerSetUp(const vector<Blob<Dtype>*>& bottom, |
| 30 | const vector<Blob<Dtype>*>& top) { |
| 31 | const int batch_size = this->layer_param_.data_param().batch_size(); |
| 32 | // Read a data point, and use it to initialize the top blob. |
| 33 | Datum datum; |
| 34 | datum.ParseFromString(cursor_->value()); |
| 35 | |
| 36 | // Use data_transformer to infer the expected blob shape from datum. |
| 37 | vector<int> top_shape = this->data_transformer_->InferBlobShape(datum); |
| 38 | this->transformed_data_.Reshape(top_shape); |
| 39 | // Reshape top[0] and prefetch_data according to the batch_size. |
| 40 | top_shape[0] = batch_size; |
| 41 | top[0]->Reshape(top_shape); |
| 42 | for (int i = 0; i < this->prefetch_.size(); ++i) { |
| 43 | this->prefetch_[i]->data_.Reshape(top_shape); |
| 44 | } |
| 45 | LOG_IF(INFO, Caffe::root_solver()) |
| 46 | << "output data size: " << top[0]->num() << "," |
| 47 | << top[0]->channels() << "," << top[0]->height() << "," |
| 48 | << top[0]->width(); |
| 49 | // label |
| 50 | if (this->output_labels_) { |
| 51 | vector<int> label_shape(1, batch_size); |
| 52 | top[1]->Reshape(label_shape); |
| 53 | for (int i = 0; i < this->prefetch_.size(); ++i) { |
| 54 | this->prefetch_[i]->label_.Reshape(label_shape); |
| 55 | } |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | template <typename Dtype> |
| 60 | bool DataLayer<Dtype>::Skip() { |