| 25 | // Load data and label from HDF5 filename into the class property blobs. |
| 26 | template <typename Dtype> |
| 27 | void HDF5DataLayer<Dtype>::LoadHDF5FileData(const char* filename) { |
| 28 | DLOG(INFO) << "Loading HDF5 file: " << filename; |
| 29 | hid_t file_id = H5Fopen(filename, H5F_ACC_RDONLY, H5P_DEFAULT); |
| 30 | if (file_id < 0) { |
| 31 | LOG(FATAL) << "Failed opening HDF5 file: " << filename; |
| 32 | } |
| 33 | |
| 34 | int top_size = this->layer_param_.top_size(); |
| 35 | hdf_blobs_.resize(top_size); |
| 36 | |
| 37 | const int MIN_DATA_DIM = 1; |
| 38 | const int MAX_DATA_DIM = INT_MAX; |
| 39 | |
| 40 | for (int i = 0; i < top_size; ++i) { |
| 41 | hdf_blobs_[i] = shared_ptr<Blob<Dtype> >(new Blob<Dtype>()); |
| 42 | // Allow reshape here, as we are loading data not params |
| 43 | hdf5_load_nd_dataset(file_id, this->layer_param_.top(i).c_str(), |
| 44 | MIN_DATA_DIM, MAX_DATA_DIM, hdf_blobs_[i].get(), true); |
| 45 | } |
| 46 | |
| 47 | herr_t status = H5Fclose(file_id); |
| 48 | CHECK_GE(status, 0) << "Failed to close HDF5 file: " << filename; |
| 49 | |
| 50 | // MinTopBlobs==1 guarantees at least one top blob |
| 51 | CHECK_GE(hdf_blobs_[0]->num_axes(), 1) << "Input must have at least 1 axis."; |
| 52 | const int num = hdf_blobs_[0]->shape(0); |
| 53 | for (int i = 1; i < top_size; ++i) { |
| 54 | CHECK_EQ(hdf_blobs_[i]->shape(0), num); |
| 55 | } |
| 56 | // Default to identity permutation. |
| 57 | data_permutation_.clear(); |
| 58 | data_permutation_.resize(hdf_blobs_[0]->shape(0)); |
| 59 | for (int i = 0; i < hdf_blobs_[0]->shape(0); i++) |
| 60 | data_permutation_[i] = i; |
| 61 | |
| 62 | // Shuffle if needed. |
| 63 | if (this->layer_param_.hdf5_data_param().shuffle()) { |
| 64 | std::random_shuffle(data_permutation_.begin(), data_permutation_.end()); |
| 65 | DLOG(INFO) << "Successfully loaded " << hdf_blobs_[0]->shape(0) |
| 66 | << " rows (shuffled)"; |
| 67 | } else { |
| 68 | DLOG(INFO) << "Successfully loaded " << hdf_blobs_[0]->shape(0) << " rows"; |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | template <typename Dtype> |
| 73 | void HDF5DataLayer<Dtype>::LayerSetUp(const vector<Blob<Dtype>*>& bottom, |