Пример #1
0
AnnotatedDataLayer<Dtype>::AnnotatedDataLayer(const LayerParameter& param)
  : BasePrefetchingDataLayer<Dtype>(param),
    //reader_(param) {
    offset_() {
  db_.reset(db::GetDB(param.data_param().backend()));
  db_->Open(param.data_param().source(), db::READ);
  cursor_.reset(db_->NewCursor());
}
Пример #2
0
DataReader::DataReader(const LayerParameter& param)
    : queue_pair_(new QueuePair(  //
        param.data_param().prefetch() * param.data_param().batch_size())) {
  // Get or create a body
  boost::mutex::scoped_lock lock(bodies_mutex_);
  string key = source_key(param);
  weak_ptr<Body>& weak = bodies_[key];
  body_ = weak.lock();
  if (!body_) {
    body_.reset(new Body(param));
    bodies_[key] = weak_ptr<Body>(body_);
  }
  body_->new_queue_pairs_.push(queue_pair_);
}
size_t BasePrefetchingDataLayer<Ftype, Btype>::parser_threads(const LayerParameter& param) {
  // Check user's override in prototxt file
  size_t parser_threads = param.data_param().parser_threads();
  if (!auto_mode(param) && parser_threads == 0U) {
    parser_threads = 1U;  // input error fix
  }
  // 1 thread for test net
  return (auto_mode(param) || param.phase() == TEST || parser_threads == 0U) ? 1U : parser_threads;
}
Пример #4
0
BasePrefetchingDataLayer<Dtype>::BasePrefetchingDataLayer(
    const LayerParameter& param)
    : BaseDataLayer<Dtype>(param),
      prefetch_(param.data_param().prefetch()),
      prefetch_free_(), prefetch_full_(), prefetch_current_() {
  for (int i = 0; i < prefetch_.size(); ++i) {
    prefetch_[i].reset(new Batch<Dtype>());
    prefetch_free_.push(prefetch_[i].get());
  }
}
Пример #5
0
// 第一个solver里的DataReader reader_初始化的时候,
// 剩下的solvers里的DataReader reader_初始化的时候, 
// 构造函数,传入的是网络的参数、  
// 初始化queue_pair_(里面包含两个阻塞队列free_和full_)  
DataReader::DataReader(const LayerParameter& param)  
    : queue_pair_(new QueuePair(  // 1.往free_里放进去(push)了这么多个Datum. (4 x batch_size) 
        param.data_param().prefetch() * param.data_param().batch_size())) 
{  
    // Get or create a body  
    // 首先创建或者获取一个body实例  
    boost::mutex::scoped_lock lock(bodies_mutex_);  
    string key = source_key(param);// 从网络参数中获取key  
    weak_ptr<Body>& weak = bodies_[key];// bodies_是存放的string到Body的映射  
    body_ = weak.lock();  

    // 如果bodies是空的 
    if (!body_) 
    { 
        // 2.新建一个Body. 见下面分析. 
        body_.reset(new Body(param)); // 则新建Body实例到body_  
        bodies_[key] = weak_ptr<Body>(body_);// 然后存放到bodies_中去  
    }  

    // 如果只有一个source,就只有一个Body对象. Body body_的成员new_queue_pairs里的free_和full_队列中的元素为Datum, 队列长度为 (4 x batch_size) 
    body_->new_queue_pairs_.push(queue_pair_); // 并将queue_pair放入body_中的new_queue_pairs_中去  
}  
Пример #6
0
 // A source is uniquely identified by its layer name + path, in case
 // the same database is read from two different locations in the net.
 static inline string source_key(const LayerParameter& param, bool is_nv_data) {
   return param.name() + ":" +
     (is_nv_data ? param.nvdata_param().source() : param.data_param().source());
 }
Пример #7
0
 // A source is uniquely identified by its layer name + path, in case
 // the same database is read from two different locations in the net.
 static inline string source_key(const LayerParameter& param) {
   return param.name() + ":" + param.data_param().source();
 }
Пример #8
0
DataReader::DataReader(const LayerParameter& param) :param(param),cur_idx(0){
	pair.reset(new QueuePair(param.data_param().prefetch()*param.data_param().batch_size()));
	parseImageset();
	startThread();
}
bool BasePrefetchingDataLayer<Ftype, Btype>::auto_mode(const LayerParameter& param) {
  // Both should be set to positive for manual mode
  const DataParameter& dparam = param.data_param();
  bool auto_mode = !dparam.has_threads() && !dparam.has_parser_threads();
  return auto_mode;
}
Пример #10
0
 explicit DataSiameseLayer(const LayerParameter& param): BaseDataLayer<Dtype>(param), data_param_(param.data_param()) {}