Caffe
include
caffe
data_reader.hpp
1
#ifndef CAFFE_DATA_READER_HPP_
2
#define CAFFE_DATA_READER_HPP_
3
4
#include <map>
5
#include <string>
6
#include <vector>
7
8
#include "caffe/common.hpp"
9
#include "caffe/internal_thread.hpp"
10
#include "caffe/util/blocking_queue.hpp"
11
#include "caffe/util/db.hpp"
12
13
namespace
caffe
{
14
23
class
DataReader
{
24
public
:
25
explicit
DataReader
(
const
LayerParameter& param);
26
~
DataReader
();
27
28
inline
BlockingQueue<Datum*>
& free()
const
{
29
return
queue_pair_->free_;
30
}
31
inline
BlockingQueue<Datum*>
& full()
const
{
32
return
queue_pair_->full_;
33
}
34
35
protected
:
36
// Queue pairs are shared between a body and its readers
37
class
QueuePair
{
38
public
:
39
explicit
QueuePair
(
int
size);
40
~
QueuePair
();
41
42
BlockingQueue<Datum*>
free_;
43
BlockingQueue<Datum*>
full_;
44
45
DISABLE_COPY_AND_ASSIGN(
QueuePair
);
46
};
47
48
// A single body is created per source
49
class
Body
:
public
InternalThread
{
50
public
:
51
explicit
Body
(
const
LayerParameter& param);
52
virtual
~
Body
();
53
54
protected
:
55
void
InternalThreadEntry();
56
void
read_one(
db::Cursor
* cursor,
QueuePair
* qp);
57
58
const
LayerParameter param_;
59
BlockingQueue<shared_ptr<QueuePair>
> new_queue_pairs_;
60
61
friend
class
DataReader
;
62
63
DISABLE_COPY_AND_ASSIGN(
Body
);
64
};
65
66
// A source is uniquely identified by its layer name + path, in case
67
// the same database is read from two different locations in the net.
68
static
inline
string
source_key(
const
LayerParameter& param) {
69
return
param.name() +
":"
+ param.data_param().source();
70
}
71
72
const
shared_ptr<QueuePair> queue_pair_;
73
shared_ptr<Body> body_;
74
75
static
map<const string, boost::weak_ptr<DataReader::Body> > bodies_;
76
77
DISABLE_COPY_AND_ASSIGN(
DataReader
);
78
};
79
80
}
// namespace caffe
81
82
#endif // CAFFE_DATA_READER_HPP_
caffe
A layer factory that allows one to register layers. During runtime, registered layers can be called b...
Definition:
blob.hpp:14
caffe::DataReader::Body
Definition:
data_reader.hpp:49
caffe::DataReader::QueuePair
Definition:
data_reader.hpp:37
caffe::InternalThread
Definition:
internal_thread.hpp:19
caffe::BlockingQueue
Definition:
blocking_queue.hpp:10
caffe::DataReader
Reads data from a source to queues available to data layers. A single reading thread is created per s...
Definition:
data_reader.hpp:23
caffe::db::Cursor
Definition:
db.hpp:13
Generated on Fri Dec 9 2016 02:06:23 for Caffe by
1.8.12