From: Yangqing Jia Date: Mon, 11 Aug 2014 16:16:51 +0000 (-0700) Subject: Add a leveldb option function in io.hpp/cpp X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b1d6da5740a3031a633d7fa6e4c0f7fa4dc77ebf;p=platform%2Fupstream%2Fcaffe.git Add a leveldb option function in io.hpp/cpp --- diff --git a/include/caffe/util/io.hpp b/include/caffe/util/io.hpp index cdf4d9e..8ff8b0c 100644 --- a/include/caffe/util/io.hpp +++ b/include/caffe/util/io.hpp @@ -12,6 +12,11 @@ #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 void hdf5_load_nd_dataset_helper( diff --git a/src/caffe/layers/data_layer.cpp b/src/caffe/layers/data_layer.cpp index c089c9b..8f17c45 100644 --- a/src/caffe/layers/data_layer.cpp +++ b/src/caffe/layers/data_layer.cpp @@ -173,9 +173,8 @@ void DataLayer::SetUp(const vector*>& 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); diff --git a/src/caffe/util/io.cpp b/src/caffe/util/io.cpp index fd7454d..48952a5 100644 --- a/src/caffe/util/io.cpp +++ b/src/caffe/util/io.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include @@ -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 void hdf5_load_nd_dataset_helper(