Add a leveldb option function in io.hpp/cpp
authorYangqing Jia <jiayq@google.com>
Mon, 11 Aug 2014 16:16:51 +0000 (09:16 -0700)
committerYangqing Jia <jiayq@google.com>
Mon, 11 Aug 2014 16:16:51 +0000 (09:16 -0700)
include/caffe/util/io.hpp
src/caffe/layers/data_layer.cpp
src/caffe/util/io.cpp

index cdf4d9e..8ff8b0c 100644 (file)
 
 #define HDF5_NUM_DIMS 4
 
+namespace leveldb {
+// Forward declaration for leveldb::Options to be used in GetlevelDBOptions().
+class Options;
+}
+
 namespace caffe {
 
 using ::google::protobuf::Message;
@@ -70,6 +75,7 @@ inline bool ReadImageToDatum(const string& filename, const int label,
   return ReadImageToDatum(filename, label, 0, 0, datum);
 }
 
+leveldb::Options GetLevelDBOptions();
 
 template <typename Dtype>
 void hdf5_load_nd_dataset_helper(
index c089c9b..8f17c45 100644 (file)
@@ -173,9 +173,8 @@ void DataLayer<Dtype>::SetUp(const vector<Blob<Dtype>*>& bottom,
   case DataParameter_DB_LEVELDB:
     {
     leveldb::DB* db_temp;
-    leveldb::Options options;
+    leveldb::Options options = GetLevelDBOptions();
     options.create_if_missing = false;
-    options.max_open_files = 100;
     LOG(INFO) << "Opening leveldb " << this->layer_param_.data_param().source();
     leveldb::Status status = leveldb::DB::Open(
         options, this->layer_param_.data_param().source(), &db_temp);
index fd7454d..48952a5 100644 (file)
@@ -2,6 +2,7 @@
 #include <google/protobuf/io/coded_stream.h>
 #include <google/protobuf/io/zero_copy_stream_impl.h>
 #include <google/protobuf/text_format.h>
+#include <leveldb/db.h>
 #include <opencv2/core/core.hpp>
 #include <opencv2/highgui/highgui.hpp>
 #include <opencv2/highgui/highgui_c.h>
@@ -108,6 +109,14 @@ bool ReadImageToDatum(const string& filename, const int label,
   return true;
 }
 
+leveldb::Options GetLevelDBOptions() {
+  // In default, we will return the leveldb option and set the max open files
+  // in order to avoid using up the operating system's limit.
+  leveldb::Options options;
+  options.max_open_files = 100;
+  return options;
+}
+
 // Verifies format of data stored in HDF5 file and reshapes blob accordingly.
 template <typename Dtype>
 void hdf5_load_nd_dataset_helper(