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

Method LayerSetUp

src/caffe/layers/hdf5_data_layer.cpp:73–126  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

71
72template <typename Dtype>
73void HDF5DataLayer<Dtype>::LayerSetUp(const vector<Blob<Dtype>*>& bottom,
74 const vector<Blob<Dtype>*>& top) {
75 // Refuse transformation parameters since HDF5 is totally generic.
76 CHECK(!this->layer_param_.has_transform_param()) <<
77 this->type() << " does not transform data.";
78 // Read the source to parse the filenames.
79 const string& source = this->layer_param_.hdf5_data_param().source();
80 LOG(INFO) << "Loading list of HDF5 filenames from: " << source;
81 hdf_filenames_.clear();
82 std::ifstream source_file(source.c_str());
83 if (source_file.is_open()) {
84 std::string line;
85 while (source_file >> line) {
86 hdf_filenames_.push_back(line);
87 }
88 } else {
89 LOG(FATAL) << "Failed to open source file: " << source;
90 }
91 source_file.close();
92 num_files_ = hdf_filenames_.size();
93 current_file_ = 0;
94 LOG(INFO) << "Number of HDF5 files: " << num_files_;
95 CHECK_GE(num_files_, 1) << "Must have at least 1 HDF5 filename listed in "
96 << source;
97
98 file_permutation_.clear();
99 file_permutation_.resize(num_files_);
100 // Default to identity permutation.
101 for (int i = 0; i < num_files_; i++) {
102 file_permutation_[i] = i;
103 }
104
105 // Shuffle if needed.
106 if (this->layer_param_.hdf5_data_param().shuffle()) {
107 std::random_shuffle(file_permutation_.begin(), file_permutation_.end());
108 }
109
110 // Load the first HDF5 file and initialize the line counter.
111 LoadHDF5FileData(hdf_filenames_[file_permutation_[current_file_]].c_str());
112 current_row_ = 0;
113
114 // Reshape blobs.
115 const int batch_size = this->layer_param_.hdf5_data_param().batch_size();
116 const int top_size = this->layer_param_.top_size();
117 vector<int> top_shape;
118 for (int i = 0; i < top_size; ++i) {
119 top_shape.resize(hdf_blobs_[i]->num_axes());
120 top_shape[0] = batch_size;
121 for (int j = 1; j < top_shape.size(); ++j) {
122 top_shape[j] = hdf_blobs_[i]->shape(j);
123 }
124 top[i]->Reshape(top_shape);
125 }
126}
127
128template <typename Dtype>
129bool HDF5DataLayer<Dtype>::Skip() {

Callers

nothing calls this directly

Calls 8

typeMethod · 0.95
batch_sizeMethod · 0.80
num_axesMethod · 0.80
shapeMethod · 0.80
sizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
ReshapeMethod · 0.45

Tested by

no test coverage detected