at master 2.7 kB view raw
1From 11e585e52ab92bb9d7a995c5002cb55fbff687b2 Mon Sep 17 00:00:00 2001 2From: uku <hi@uku.moe> 3Date: Thu, 15 May 2025 11:10:50 +0200 4Subject: [PATCH] fix: remove usages of random_shuffle 5 6--- 7 src/caffe/layers/hdf5_data_layer.cpp | 17 ++++++++++++----- 8 1 file changed, 12 insertions(+), 5 deletions(-) 9 10diff --git a/src/caffe/layers/hdf5_data_layer.cpp b/src/caffe/layers/hdf5_data_layer.cpp 11index 00716a92..01213691 100644 12--- a/src/caffe/layers/hdf5_data_layer.cpp 13+++ b/src/caffe/layers/hdf5_data_layer.cpp 14@@ -61,7 +61,9 @@ void HDF5DataLayer<Dtype>::LoadHDF5FileData(const char* filename) { 15 16 // Shuffle if needed. 17 if (this->layer_param_.hdf5_data_param().shuffle()) { 18- std::random_shuffle(data_permutation_.begin(), data_permutation_.end()); 19+ std::random_device rand_device; 20+ std::default_random_engine rand_engine(rand_device()); 21+ std::shuffle(data_permutation_.begin(), data_permutation_.end(), rand_engine); 22 DLOG(INFO) << "Successfully loaded " << hdf_blobs_[0]->shape(0) 23 << " rows (shuffled)"; 24 } else { 25@@ -104,7 +106,9 @@ void HDF5DataLayer<Dtype>::LayerSetUp(const vector<Blob<Dtype>*>& bottom, 26 27 // Shuffle if needed. 28 if (this->layer_param_.hdf5_data_param().shuffle()) { 29- std::random_shuffle(file_permutation_.begin(), file_permutation_.end()); 30+ std::random_device rand_device; 31+ std::default_random_engine rand_engine(rand_device()); 32+ std::shuffle(file_permutation_.begin(), file_permutation_.end(), rand_engine); 33 } 34 35 // Load the first HDF5 file and initialize the line counter. 36@@ -137,14 +141,17 @@ bool HDF5DataLayer<Dtype>::Skip() { 37 38 template<typename Dtype> 39 void HDF5DataLayer<Dtype>::Next() { 40+ std::random_device rand_device; 41+ std::default_random_engine rand_engine(rand_device()); 42 if (++current_row_ == hdf_blobs_[0]->shape(0)) { 43 if (num_files_ > 1) { 44 ++current_file_; 45 if (current_file_ == num_files_) { 46 current_file_ = 0; 47 if (this->layer_param_.hdf5_data_param().shuffle()) { 48- std::random_shuffle(file_permutation_.begin(), 49- file_permutation_.end()); 50+ std::shuffle(file_permutation_.begin(), 51+ file_permutation_.end(), 52+ rand_engine); 53 } 54 DLOG(INFO) << "Looping around to first file."; 55 } 56@@ -153,7 +160,7 @@ void HDF5DataLayer<Dtype>::Next() { 57 } 58 current_row_ = 0; 59 if (this->layer_param_.hdf5_data_param().shuffle()) 60- std::random_shuffle(data_permutation_.begin(), data_permutation_.end()); 61+ std::shuffle(data_permutation_.begin(), data_permutation_.end(), rand_engine); 62 } 63 offset_++; 64 } 65-- 662.49.0 67