Skip to content

Commit

Permalink
Merge pull request BVLC#9 from BVLC/master
Browse files Browse the repository at this point in the history
update from updstream
  • Loading branch information
bittnt committed May 16, 2016
2 parents e3b84e1 + bb0c1a5 commit c07d634
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 19 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ endif()
project(Caffe C CXX)

# ---[ Caffe version
set(CAFFE_TARGET_VERSION "1.0.0-rc3")
set(CAFFE_TARGET_SOVERSION "1.0.0-rc3")
set(CAFFE_TARGET_VERSION "1.0.0-rc3" CACHE STRING "Caffe logical version")
set(CAFFE_TARGET_SOVERSION "1.0.0-rc3" CACHE STRING "Caffe soname version")
add_definitions(-DCAFFE_VERSION=${CAFFE_TARGET_VERSION})

# ---[ Using cmake scripts and modules
Expand Down
45 changes: 45 additions & 0 deletions include/caffe/layers/parameter_layer.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#ifndef CAFFE_PARAMETER_LAYER_HPP_
#define CAFFE_PARAMETER_LAYER_HPP_

#include <vector>

#include "caffe/layer.hpp"

namespace caffe {

template <typename Dtype>
class ParameterLayer : public Layer<Dtype> {
public:
explicit ParameterLayer(const LayerParameter& param)
: Layer<Dtype>(param) {}
virtual void LayerSetUp(const vector<Blob<Dtype>*>& bottom,
const vector<Blob<Dtype>*>& top) {
if (this->blobs_.size() > 0) {
LOG(INFO) << "Skipping parameter initialization";
} else {
this->blobs_.resize(1);
this->blobs_[0].reset(new Blob<Dtype>());
this->blobs_[0]->Reshape(this->layer_param_.parameter_param().shape());
}
top[0]->Reshape(this->layer_param_.parameter_param().shape());
}
virtual void Reshape(const vector<Blob<Dtype>*>& bottom,
const vector<Blob<Dtype>*>& top) { }
virtual inline const char* type() const { return "Parameter"; }
virtual inline int ExactNumBottomBlobs() const { return 0; }
virtual inline int ExactNumTopBlobs() const { return 1; }

protected:
virtual void Forward_cpu(const vector<Blob<Dtype>*>& bottom,
const vector<Blob<Dtype>*>& top) {
top[0]->ShareData(*(this->blobs_[0]));
top[0]->ShareDiff(*(this->blobs_[0]));
}
virtual void Backward_cpu(const vector<Blob<Dtype>*>& top,
const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom)
{ }
};

} // namespace caffe

#endif
2 changes: 1 addition & 1 deletion python/caffe/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def array_to_blobproto(arr, diff=None):
return blob


def arraylist_to_blobprotovecor_str(arraylist):
def arraylist_to_blobprotovector_str(arraylist):
"""Converts a list of arrays to a serialized blobprotovec, which could be
then passed to a network for processing.
"""
Expand Down
8 changes: 8 additions & 0 deletions src/caffe/layers/parameter_layer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include "caffe/layers/parameter_layer.hpp"

namespace caffe {

INSTANTIATE_CLASS(ParameterLayer);
REGISTER_LAYER_CLASS(Parameter);

} // namespace caffe
38 changes: 22 additions & 16 deletions src/caffe/util/db_lmdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace caffe { namespace db {
void LMDB::Open(const string& source, Mode mode) {
MDB_CHECK(mdb_env_create(&mdb_env_));
if (mode == NEW) {
CHECK_EQ(mkdir(source.c_str(), 0744), 0) << "mkdir " << source << "failed";
CHECK_EQ(mkdir(source.c_str(), 0744), 0) << "mkdir " << source << " failed";
}
int flags = 0;
if (mode == READ) {
Expand Down Expand Up @@ -62,36 +62,42 @@ void LMDBTransaction::Commit() {
MDB_CHECK(mdb_txn_begin(mdb_env_, NULL, 0, &mdb_txn));
MDB_CHECK(mdb_dbi_open(mdb_txn, NULL, 0, &mdb_dbi));

bool out_of_memory = false;
for (int i = 0; i < keys.size(); i++) {
mdb_key.mv_size = keys[i].size();
mdb_key.mv_data = const_cast<char*>(keys[i].data());
mdb_data.mv_size = values[i].size();
mdb_data.mv_data = const_cast<char*>(values[i].data());

// Add data to the transaction
int put_rc = mdb_put(mdb_txn, mdb_dbi, &mdb_key, &mdb_data, 0);
if (put_rc == MDB_MAP_FULL) {
out_of_memory = true;
break;
} else {
// Failed for some other reason
MDB_CHECK(put_rc);
// Out of memory - double the map size and retry
mdb_txn_abort(mdb_txn);
mdb_dbi_close(mdb_env_, mdb_dbi);
DoubleMapSize();
Commit();
return;
}
// May have failed for some other reason
MDB_CHECK(put_rc);
}

if (!out_of_memory) {
// Commit the transaction
MDB_CHECK(mdb_txn_commit(mdb_txn));
mdb_dbi_close(mdb_env_, mdb_dbi);
keys.clear();
values.clear();
} else {
// Double the map size and retry
mdb_txn_abort(mdb_txn);
// Commit the transaction
int commit_rc = mdb_txn_commit(mdb_txn);
if (commit_rc == MDB_MAP_FULL) {
// Out of memory - double the map size and retry
mdb_dbi_close(mdb_env_, mdb_dbi);
DoubleMapSize();
Commit();
return;
}
// May have failed for some other reason
MDB_CHECK(commit_rc);

// Cleanup after successful commit
mdb_dbi_close(mdb_env_, mdb_dbi);
keys.clear();
values.clear();
}

void LMDBTransaction::DoubleMapSize() {
Expand Down

0 comments on commit c07d634

Please sign in to comment.