MCPcopy Create free account
hub / github.com/BVLC/caffe / load_batch

Method load_batch

src/caffe/layers/data_layer.cpp:82–131  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

80// This function is called on prefetch thread
81template<typename Dtype>
82void DataLayer<Dtype>::load_batch(Batch<Dtype>* batch) {
83 CPUTimer batch_timer;
84 batch_timer.Start();
85 double read_time = 0;
86 double trans_time = 0;
87 CPUTimer timer;
88 CHECK(batch->data_.count());
89 CHECK(this->transformed_data_.count());
90 const int batch_size = this->layer_param_.data_param().batch_size();
91
92 Datum datum;
93 for (int item_id = 0; item_id < batch_size; ++item_id) {
94 timer.Start();
95 while (Skip()) {
96 Next();
97 }
98 datum.ParseFromString(cursor_->value());
99 read_time += timer.MicroSeconds();
100
101 if (item_id == 0) {
102 // Reshape according to the first datum of each batch
103 // on single input batches allows for inputs of varying dimension.
104 // Use data_transformer to infer the expected blob shape from datum.
105 vector<int> top_shape = this->data_transformer_->InferBlobShape(datum);
106 this->transformed_data_.Reshape(top_shape);
107 // Reshape batch according to the batch_size.
108 top_shape[0] = batch_size;
109 batch->data_.Reshape(top_shape);
110 }
111
112 // Apply data transformations (mirror, scale, crop...)
113 timer.Start();
114 int offset = batch->data_.offset(item_id);
115 Dtype* top_data = batch->data_.mutable_cpu_data();
116 this->transformed_data_.set_cpu_data(top_data + offset);
117 this->data_transformer_->Transform(datum, &(this->transformed_data_));
118 // Copy label.
119 if (this->output_labels_) {
120 Dtype* top_label = batch->label_.mutable_cpu_data();
121 top_label[item_id] = datum.label();
122 }
123 trans_time += timer.MicroSeconds();
124 Next();
125 }
126 timer.Stop();
127 batch_timer.Stop();
128 DLOG(INFO) << "Prefetch batch: " << batch_timer.MilliSeconds() << " ms.";
129 DLOG(INFO) << " Read time: " << read_time / 1000 << " ms.";
130 DLOG(INFO) << "Transform time: " << trans_time / 1000 << " ms.";
131}
132
133INSTANTIATE_CLASS(DataLayer);
134REGISTER_LAYER_CLASS(Data);

Callers

nothing calls this directly

Calls 13

StartMethod · 0.80
countMethod · 0.80
batch_sizeMethod · 0.80
MicroSecondsMethod · 0.80
InferBlobShapeMethod · 0.80
offsetMethod · 0.80
TransformMethod · 0.80
StopMethod · 0.80
MilliSecondsMethod · 0.80
valueMethod · 0.45
ReshapeMethod · 0.45
mutable_cpu_dataMethod · 0.45

Tested by

no test coverage detected