caffe_option(ALLOW_LMDB_NOLOCK "Allow MDB_NOLOCK when reading LMDB files (only if necessary)" OFF)
caffe_option(USE_OPENMP "Link with OpenMP (when your BLAS wants OpenMP and you get linker errors)" OFF)
+# This code is taken from https://github.com/sh1r0/caffe-android-lib
+caffe_option(USE_HDF5 "Build with hdf5" ON)
+
# ---[ Dependencies
include(cmake/Dependencies.cmake)
LIBRARIES := cudart cublas curand
endif
-LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_hl hdf5
+LIBRARIES += glog gflags protobuf boost_system boost_filesystem m
# handle IO dependencies
USE_LEVELDB ?= 1
USE_LMDB ?= 1
+# This code is taken from https://github.com/sh1r0/caffe-android-lib
+USE_HDF5 ?= 1
USE_OPENCV ?= 1
ifeq ($(USE_LEVELDB), 1)
ifeq ($(USE_LMDB), 1)
LIBRARIES += lmdb
endif
+# This code is taken from https://github.com/sh1r0/caffe-android-lib
+ifeq ($(USE_HDF5), 1)
+ LIBRARIES += hdf5_hl hdf5
+endif
ifeq ($(USE_OPENCV), 1)
LIBRARIES += opencv_core opencv_highgui opencv_imgproc
COMMON_FLAGS += -DALLOW_LMDB_NOLOCK
endif
endif
+# This code is taken from https://github.com/sh1r0/caffe-android-lib
+ifeq ($(USE_HDF5), 1)
+ COMMON_FLAGS += -DUSE_HDF5
+endif
# CPU-only configuration
ifeq ($(CPU_ONLY), 1)
# USE_OPENCV := 0
# USE_LEVELDB := 0
# USE_LMDB := 0
+# This code is taken from https://github.com/sh1r0/caffe-android-lib
+# USE_HDF5 := 0
# uncomment to allow MDB_NOLOCK when reading LMDB files (only if necessary)
# You should not set this flag if you will be reading LMDBs with any
set(HAVE_CUDA FALSE)
endif()
+ set(HDF5_IMPORTED OFF)
+ foreach(_lib ${HDF5_LIBRARIES} ${HDF5_HL_LIBRARIES})
+ if(TARGET ${_lib})
+ set(HDF5_IMPORTED ON)
+ endif()
+ endforeach()
+
+ # This code is taken from https://github.com/sh1r0/caffe-android-lib
+ if(USE_HDF5)
+ list(APPEND Caffe_DEFINITIONS -DUSE_HDF5)
+ endif()
+
if(NOT HAVE_CUDNN)
set(HAVE_CUDNN FALSE)
endif()
list(APPEND Caffe_INCLUDE_DIRS PUBLIC ${HDF5_INCLUDE_DIRS})
list(APPEND Caffe_LINKER_LIBS PUBLIC ${HDF5_LIBRARIES} ${HDF5_HL_LIBRARIES})
+# This code is taken from https://github.com/sh1r0/caffe-android-lib
+if(USE_HDF5)
+ find_package(HDF5 COMPONENTS HL REQUIRED)
+ include_directories(SYSTEM ${HDF5_INCLUDE_DIRS} ${HDF5_HL_INCLUDE_DIR})
+ list(APPEND Caffe_LINKER_LIBS ${HDF5_LIBRARIES} ${HDF5_HL_LIBRARIES})
+ add_definitions(-DUSE_HDF5)
+endif()
+
# ---[ LMDB
if(USE_LMDB)
find_package(LMDB REQUIRED)
caffe_status(" USE_LMDB : ${USE_LMDB}")
caffe_status(" USE_NCCL : ${USE_NCCL}")
caffe_status(" ALLOW_LMDB_NOLOCK : ${ALLOW_LMDB_NOLOCK}")
+ # This code is taken from https://github.com/sh1r0/caffe-android-lib
+ caffe_status(" USE_HDF5 : ${USE_HDF5}")
caffe_status("")
caffe_status("Dependencies:")
caffe_status(" BLAS : " APPLE THEN "Yes (vecLib)" ELSE "Yes (${BLAS})")
+#ifdef USE_HDF5
#ifndef CAFFE_UTIL_HDF5_H_
#define CAFFE_UTIL_HDF5_H_
} // namespace caffe
#endif // CAFFE_UTIL_HDF5_H_
+#endif // USE_HDF5
+#ifdef USE_HDF5
/*
TODO:
- load file in a separate thread ("prefetch")
REGISTER_LAYER_CLASS(HDF5Data);
} // namespace caffe
+#endif // USE_HDF5
+#ifdef USE_HDF5
/*
TODO:
- only load parts of the file, in accordance with a prototxt param "max_mem"
INSTANTIATE_LAYER_GPU_FUNCS(HDF5DataLayer);
} // namespace caffe
+#endif // USE_HDF5
+#ifdef USE_HDF5
#include <vector>
#include "hdf5.h"
REGISTER_LAYER_CLASS(HDF5Output);
} // namespace caffe
+#endif // USE_HDF5
+#ifdef USE_HDF5
#include <vector>
#include "hdf5.h"
INSTANTIATE_LAYER_GPU_FUNCS(HDF5OutputLayer);
} // namespace caffe
+#endif // USE_HDF5
#include <utility>
#include <vector>
+#ifdef USE_HDF5
#include "hdf5.h"
+#endif // USE_HDF5
#include "caffe/common.hpp"
#include "caffe/layer.hpp"
template <typename Dtype>
void Net<Dtype>::CopyTrainedLayersFromHDF5(const string trained_filename) {
+#ifdef USE_HDF5
hid_t file_hid = H5Fopen(trained_filename.c_str(), H5F_ACC_RDONLY,
H5P_DEFAULT);
CHECK_GE(file_hid, 0) << "Couldn't open " << trained_filename;
}
H5Gclose(data_hid);
H5Fclose(file_hid);
+#else
+ LOG(FATAL) << "CopyTrainedLayersFromHDF5 requires hdf5;"
+ << " compile with USE_HDF5.";
+#endif // USE_HDF5
}
template <typename Dtype>
template <typename Dtype>
void Net<Dtype>::ToHDF5(const string& filename, bool write_diff) const {
+// This code is taken from https://github.com/sh1r0/caffe-android-lib
+#ifdef USE_HDF5
hid_t file_hid = H5Fcreate(filename.c_str(), H5F_ACC_TRUNC, H5P_DEFAULT,
H5P_DEFAULT);
CHECK_GE(file_hid, 0)
H5Gclose(diff_hid);
}
H5Fclose(file_hid);
+// This code is taken from https://github.com/sh1r0/caffe-android-lib
+#else
+ LOG(FATAL) << "ToHDF5 requires hdf5; compile with USE_HDF5.";
+#endif // USE_HDF5
}
template <typename Dtype>
template <typename Dtype>
void SGDSolver<Dtype>::SnapshotSolverStateToHDF5(
const string& model_filename) {
+// This code is taken from https://github.com/sh1r0/caffe-android-lib
+#ifdef USE_HDF5
string snapshot_filename =
Solver<Dtype>::SnapshotFilename(".solverstate.h5");
LOG(INFO) << "Snapshotting solver state to HDF5 file " << snapshot_filename;
}
H5Gclose(history_hid);
H5Fclose(file_hid);
+// This code is taken from https://github.com/sh1r0/caffe-android-lib
+#else
+ LOG(FATAL) << "SnapshotSolverStateToHDF5 requires hdf5;"
+ << " compile with USE_HDF5.";
+#endif // USE_HDF5
}
template <typename Dtype>
template <typename Dtype>
void SGDSolver<Dtype>::RestoreSolverStateFromHDF5(const string& state_file) {
+#ifdef USE_HDF5
hid_t file_hid = H5Fopen(state_file.c_str(), H5F_ACC_RDONLY, H5P_DEFAULT);
CHECK_GE(file_hid, 0) << "Couldn't open solver state file " << state_file;
this->iter_ = hdf5_load_int(file_hid, "iter");
}
H5Gclose(history_hid);
H5Fclose(file_hid);
+#else
+ LOG(FATAL) << "RestoreSolverStateFromHDF5 requires hdf5;"
+ << " compile with USE_HDF5.";
+#endif // USE_HDF5
}
INSTANTIATE_CLASS(SGDSolver);
+#ifdef USE_HDF5
#include <string>
#include <vector>
}
} // namespace caffe
+#endif // USE_HDF5
+#ifdef USE_HDF5
#include <string>
#include <vector>
}
} // namespace caffe
+#endif // USE_HDF5
+#ifdef USE_HDF5
#include "caffe/util/hdf5.hpp"
#include <string>
}
} // namespace caffe
+#endif // USE_HDF5