caffe: fix compatibility with glog 0.7.x (#404313)
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
{
|
||||
config,
|
||||
stdenv,
|
||||
lib,
|
||||
fetchFromGitHub,
|
||||
@@ -116,6 +115,8 @@ stdenv.mkDerivation rec {
|
||||
patches =
|
||||
[
|
||||
./darwin.patch
|
||||
./glog-cmake.patch
|
||||
./random-shuffle.patch
|
||||
(fetchpatch {
|
||||
name = "support-opencv4";
|
||||
url = "https://github.com/BVLC/caffe/pull/6638/commits/0a04cc2ccd37ba36843c18fea2d5cbae6e7dd2b5.patch";
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
From 38b81bb53304d7a3f6aed36f7b4e77b6efa78338 Mon Sep 17 00:00:00 2001
|
||||
From: uku <hi@uku.moe>
|
||||
Date: Wed, 14 May 2025 16:55:15 +0200
|
||||
Subject: [PATCH] fix linking against glog 0.7.x
|
||||
|
||||
---
|
||||
cmake/Dependencies.cmake | 2 +-
|
||||
cmake/External/glog.cmake | 4 +--
|
||||
cmake/Modules/FindGlog.cmake | 48 ------------------------------------
|
||||
3 files changed, 3 insertions(+), 51 deletions(-)
|
||||
delete mode 100644 cmake/Modules/FindGlog.cmake
|
||||
|
||||
diff --git a/cmake/Dependencies.cmake b/cmake/Dependencies.cmake
|
||||
index 4a5bac47..88aa123f 100644
|
||||
--- a/cmake/Dependencies.cmake
|
||||
+++ b/cmake/Dependencies.cmake
|
||||
@@ -32,7 +32,7 @@ endif()
|
||||
# ---[ Google-glog
|
||||
include("cmake/External/glog.cmake")
|
||||
list(APPEND Caffe_INCLUDE_DIRS PUBLIC ${GLOG_INCLUDE_DIRS})
|
||||
-list(APPEND Caffe_LINKER_LIBS PUBLIC ${GLOG_LIBRARIES})
|
||||
+list(APPEND Caffe_LINKER_LIBS PUBLIC glog::glog)
|
||||
|
||||
# ---[ Google-gflags
|
||||
include("cmake/External/gflags.cmake")
|
||||
diff --git a/cmake/External/glog.cmake b/cmake/External/glog.cmake
|
||||
index f9d0549c..43414544 100644
|
||||
--- a/cmake/External/glog.cmake
|
||||
+++ b/cmake/External/glog.cmake
|
||||
@@ -5,8 +5,8 @@ if (NOT __GLOG_INCLUDED)
|
||||
set(__GLOG_INCLUDED TRUE)
|
||||
|
||||
# try the system-wide glog first
|
||||
- find_package(Glog)
|
||||
- if (GLOG_FOUND)
|
||||
+ find_package(glog REQUIRED)
|
||||
+ if (glog_FOUND)
|
||||
set(GLOG_EXTERNAL FALSE)
|
||||
else()
|
||||
# fetch and build glog from github
|
||||
diff --git a/cmake/Modules/FindGlog.cmake b/cmake/Modules/FindGlog.cmake
|
||||
deleted file mode 100644
|
||||
index 99abbe47..00000000
|
||||
--- a/cmake/Modules/FindGlog.cmake
|
||||
+++ /dev/null
|
||||
@@ -1,48 +0,0 @@
|
||||
-# - Try to find Glog
|
||||
-#
|
||||
-# The following variables are optionally searched for defaults
|
||||
-# GLOG_ROOT_DIR: Base directory where all GLOG components are found
|
||||
-#
|
||||
-# The following are set after configuration is done:
|
||||
-# GLOG_FOUND
|
||||
-# GLOG_INCLUDE_DIRS
|
||||
-# GLOG_LIBRARIES
|
||||
-# GLOG_LIBRARYRARY_DIRS
|
||||
-
|
||||
-include(FindPackageHandleStandardArgs)
|
||||
-
|
||||
-set(GLOG_ROOT_DIR "" CACHE PATH "Folder contains Google glog")
|
||||
-
|
||||
-if(WIN32)
|
||||
- find_path(GLOG_INCLUDE_DIR glog/logging.h
|
||||
- PATHS ${GLOG_ROOT_DIR}/src/windows)
|
||||
-else()
|
||||
- find_path(GLOG_INCLUDE_DIR glog/logging.h
|
||||
- PATHS ${GLOG_ROOT_DIR})
|
||||
-endif()
|
||||
-
|
||||
-if(MSVC)
|
||||
- find_library(GLOG_LIBRARY_RELEASE libglog_static
|
||||
- PATHS ${GLOG_ROOT_DIR}
|
||||
- PATH_SUFFIXES Release)
|
||||
-
|
||||
- find_library(GLOG_LIBRARY_DEBUG libglog_static
|
||||
- PATHS ${GLOG_ROOT_DIR}
|
||||
- PATH_SUFFIXES Debug)
|
||||
-
|
||||
- set(GLOG_LIBRARY optimized ${GLOG_LIBRARY_RELEASE} debug ${GLOG_LIBRARY_DEBUG})
|
||||
-else()
|
||||
- find_library(GLOG_LIBRARY glog
|
||||
- PATHS ${GLOG_ROOT_DIR}
|
||||
- PATH_SUFFIXES lib lib64)
|
||||
-endif()
|
||||
-
|
||||
-find_package_handle_standard_args(Glog DEFAULT_MSG GLOG_INCLUDE_DIR GLOG_LIBRARY)
|
||||
-
|
||||
-if(GLOG_FOUND)
|
||||
- set(GLOG_INCLUDE_DIRS ${GLOG_INCLUDE_DIR})
|
||||
- set(GLOG_LIBRARIES ${GLOG_LIBRARY})
|
||||
- message(STATUS "Found glog (include: ${GLOG_INCLUDE_DIR}, library: ${GLOG_LIBRARY})")
|
||||
- mark_as_advanced(GLOG_ROOT_DIR GLOG_LIBRARY_RELEASE GLOG_LIBRARY_DEBUG
|
||||
- GLOG_LIBRARY GLOG_INCLUDE_DIR)
|
||||
-endif()
|
||||
--
|
||||
2.49.0
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
From 11e585e52ab92bb9d7a995c5002cb55fbff687b2 Mon Sep 17 00:00:00 2001
|
||||
From: uku <hi@uku.moe>
|
||||
Date: Thu, 15 May 2025 11:10:50 +0200
|
||||
Subject: [PATCH] fix: remove usages of random_shuffle
|
||||
|
||||
---
|
||||
src/caffe/layers/hdf5_data_layer.cpp | 17 ++++++++++++-----
|
||||
1 file changed, 12 insertions(+), 5 deletions(-)
|
||||
|
||||
diff --git a/src/caffe/layers/hdf5_data_layer.cpp b/src/caffe/layers/hdf5_data_layer.cpp
|
||||
index 00716a92..01213691 100644
|
||||
--- a/src/caffe/layers/hdf5_data_layer.cpp
|
||||
+++ b/src/caffe/layers/hdf5_data_layer.cpp
|
||||
@@ -61,7 +61,9 @@ void HDF5DataLayer<Dtype>::LoadHDF5FileData(const char* filename) {
|
||||
|
||||
// Shuffle if needed.
|
||||
if (this->layer_param_.hdf5_data_param().shuffle()) {
|
||||
- std::random_shuffle(data_permutation_.begin(), data_permutation_.end());
|
||||
+ std::random_device rand_device;
|
||||
+ std::default_random_engine rand_engine(rand_device());
|
||||
+ std::shuffle(data_permutation_.begin(), data_permutation_.end(), rand_engine);
|
||||
DLOG(INFO) << "Successfully loaded " << hdf_blobs_[0]->shape(0)
|
||||
<< " rows (shuffled)";
|
||||
} else {
|
||||
@@ -104,7 +106,9 @@ void HDF5DataLayer<Dtype>::LayerSetUp(const vector<Blob<Dtype>*>& bottom,
|
||||
|
||||
// Shuffle if needed.
|
||||
if (this->layer_param_.hdf5_data_param().shuffle()) {
|
||||
- std::random_shuffle(file_permutation_.begin(), file_permutation_.end());
|
||||
+ std::random_device rand_device;
|
||||
+ std::default_random_engine rand_engine(rand_device());
|
||||
+ std::shuffle(file_permutation_.begin(), file_permutation_.end(), rand_engine);
|
||||
}
|
||||
|
||||
// Load the first HDF5 file and initialize the line counter.
|
||||
@@ -137,14 +141,17 @@ bool HDF5DataLayer<Dtype>::Skip() {
|
||||
|
||||
template<typename Dtype>
|
||||
void HDF5DataLayer<Dtype>::Next() {
|
||||
+ std::random_device rand_device;
|
||||
+ std::default_random_engine rand_engine(rand_device());
|
||||
if (++current_row_ == hdf_blobs_[0]->shape(0)) {
|
||||
if (num_files_ > 1) {
|
||||
++current_file_;
|
||||
if (current_file_ == num_files_) {
|
||||
current_file_ = 0;
|
||||
if (this->layer_param_.hdf5_data_param().shuffle()) {
|
||||
- std::random_shuffle(file_permutation_.begin(),
|
||||
- file_permutation_.end());
|
||||
+ std::shuffle(file_permutation_.begin(),
|
||||
+ file_permutation_.end(),
|
||||
+ rand_engine);
|
||||
}
|
||||
DLOG(INFO) << "Looping around to first file.";
|
||||
}
|
||||
@@ -153,7 +160,7 @@ void HDF5DataLayer<Dtype>::Next() {
|
||||
}
|
||||
current_row_ = 0;
|
||||
if (this->layer_param_.hdf5_data_param().shuffle())
|
||||
- std::random_shuffle(data_permutation_.begin(), data_permutation_.end());
|
||||
+ std::shuffle(data_permutation_.begin(), data_permutation_.end(), rand_engine);
|
||||
}
|
||||
offset_++;
|
||||
}
|
||||
--
|
||||
2.49.0
|
||||
|
||||
Reference in New Issue
Block a user