Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a leveldb option function in io.hpp/cpp #904

Merged
merged 1 commit into from
Aug 11, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions include/caffe/util/io.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand Down
3 changes: 1 addition & 2 deletions src/caffe/layers/data_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 9 additions & 0 deletions src/caffe/util/io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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(
Expand Down