Skip to content

Commit

Permalink
source identification from parallel Caffe breaks the learning of mult…
Browse files Browse the repository at this point in the history
…iple instances of the same net
  • Loading branch information
beniz committed Sep 22, 2015
1 parent c180d0d commit 70fd4f7
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion include/caffe/data_reader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <map>
#include <string>
#include <vector>
#include <thread>

#include "caffe/common.hpp"
#include "caffe/internal_thread.hpp"
Expand Down Expand Up @@ -65,15 +66,19 @@ class DataReader {

// A source is uniquely identified by its layer name + path, in case
// the same database is read from two different locations in the net.
// DD: supplemented with thread id, as this was breaking learning the same
// model several times in parallel with the same instance of the lib.
static inline string source_key(const LayerParameter& param) {
return param.name() + ":" + param.data_param().source();
int tid = idhasher_(std::this_thread::get_id());
return std::to_string(tid) + ":" + param.name() + ":" + param.data_param().source();
}

const shared_ptr<QueuePair> queue_pair_;
shared_ptr<Body> body_;

static map<const string, boost::weak_ptr<DataReader::Body> > bodies_;

static std::hash<std::thread::id> idhasher_;
DISABLE_COPY_AND_ASSIGN(DataReader);
};

Expand Down

0 comments on commit 70fd4f7

Please sign in to comment.