|
10 | 10 | #include <fstream> // NOLINT(readability/streams)
|
11 | 11 | #include <string>
|
12 | 12 | #include <vector>
|
| 13 | +#include <algorithm> |
| 14 | +#include <random> |
13 | 15 |
|
14 | 16 | #include "hdf5.h"
|
15 | 17 | #include "hdf5_hl.h"
|
@@ -62,7 +64,13 @@ void HDF5DataLayer<Dtype>::LoadHDF5FileData(const char* filename) {
|
62 | 64 |
|
63 | 65 | // Shuffle if needed.
|
64 | 66 | if (this->layer_param_.hdf5_data_param().shuffle()) {
|
| 67 | +#if __cplusplus < 201703L |
65 | 68 | std::random_shuffle(data_permutation_.begin(), data_permutation_.end());
|
| 69 | +#else |
| 70 | + std::random_device rd; |
| 71 | + std::mt19937 g(rd()); |
| 72 | + std::shuffle(data_permutation_.begin(), data_permutation_.end(), g); |
| 73 | +#endif |
66 | 74 | DLOG(INFO) << "Successfully loaded " << hdf_blobs_[0]->shape(0)
|
67 | 75 | << " rows (shuffled)";
|
68 | 76 | } else {
|
@@ -105,7 +113,13 @@ void HDF5DataLayer<Dtype>::LayerSetUp(const vector<Blob<Dtype>*>& bottom,
|
105 | 113 |
|
106 | 114 | // Shuffle if needed.
|
107 | 115 | if (this->layer_param_.hdf5_data_param().shuffle()) {
|
| 116 | +#if __cplusplus < 201703L |
108 | 117 | std::random_shuffle(file_permutation_.begin(), file_permutation_.end());
|
| 118 | +#else |
| 119 | + std::random_device rd; |
| 120 | + std::mt19937 g(rd()); |
| 121 | + std::shuffle(file_permutation_.begin(), file_permutation_.end(), g); |
| 122 | +#endif |
109 | 123 | }
|
110 | 124 |
|
111 | 125 | // Load the first HDF5 file and initialize the line counter.
|
@@ -144,17 +158,30 @@ void HDF5DataLayer<Dtype>::Next() {
|
144 | 158 | if (current_file_ == num_files_) {
|
145 | 159 | current_file_ = 0;
|
146 | 160 | if (this->layer_param_.hdf5_data_param().shuffle()) {
|
| 161 | +#if __cplusplus < 201703L |
147 | 162 | std::random_shuffle(file_permutation_.begin(),
|
148 | 163 | file_permutation_.end());
|
| 164 | +#else |
| 165 | + std::random_device rd; |
| 166 | + std::mt19937 g(rd()); |
| 167 | + std::shuffle(file_permutation_.begin(), file_permutation_.end(), g); |
| 168 | +#endif |
149 | 169 | }
|
150 | 170 | DLOG(INFO) << "Looping around to first file.";
|
151 | 171 | }
|
152 | 172 | LoadHDF5FileData(
|
153 | 173 | hdf_filenames_[file_permutation_[current_file_]].c_str());
|
154 | 174 | }
|
155 | 175 | current_row_ = 0;
|
156 |
| - if (this->layer_param_.hdf5_data_param().shuffle()) |
| 176 | + if (this->layer_param_.hdf5_data_param().shuffle()){ |
| 177 | +#if __cplusplus < 201703L |
157 | 178 | std::random_shuffle(data_permutation_.begin(), data_permutation_.end());
|
| 179 | +#else |
| 180 | + std::random_device rd; |
| 181 | + std::mt19937 g(rd()); |
| 182 | + std::shuffle(data_permutation_.begin(), data_permutation_.end(), g); |
| 183 | +#endif |
| 184 | + } |
158 | 185 | }
|
159 | 186 | offset_++;
|
160 | 187 | }
|
|
0 commit comments