Caffe
memory_data_layer.hpp
1 #ifndef CAFFE_MEMORY_DATA_LAYER_HPP_
2 #define CAFFE_MEMORY_DATA_LAYER_HPP_
3 
4 #include <vector>
5 
6 #include "caffe/blob.hpp"
7 #include "caffe/layer.hpp"
8 #include "caffe/proto/caffe.pb.h"
9 
10 #include "caffe/layers/base_data_layer.hpp"
11 
12 namespace caffe {
13 
19 template <typename Dtype>
20 class MemoryDataLayer : public BaseDataLayer<Dtype> {
21  public:
22  explicit MemoryDataLayer(const LayerParameter& param)
23  : BaseDataLayer<Dtype>(param), has_new_data_(false) {}
24  virtual void DataLayerSetUp(const vector<Blob<Dtype>*>& bottom,
25  const vector<Blob<Dtype>*>& top);
26 
27  virtual inline const char* type() const { return "MemoryData"; }
28  virtual inline int ExactNumBottomBlobs() const { return 0; }
29  virtual inline int ExactNumTopBlobs() const { return 2; }
30 
31  virtual void AddDatumVector(const vector<Datum>& datum_vector);
32 #ifdef USE_OPENCV
33  virtual void AddMatVector(const vector<cv::Mat>& mat_vector,
34  const vector<int>& labels);
35 #endif // USE_OPENCV
36 
37  // Reset should accept const pointers, but can't, because the memory
38  // will be given to Blob, which is mutable
39  void Reset(Dtype* data, Dtype* label, int n);
40  void set_batch_size(int new_size);
41 
42  int batch_size() { return batch_size_; }
43  int channels() { return channels_; }
44  int height() { return height_; }
45  int width() { return width_; }
46 
47  protected:
48  virtual void Forward_cpu(const vector<Blob<Dtype>*>& bottom,
49  const vector<Blob<Dtype>*>& top);
50 
51  int batch_size_, channels_, height_, width_, size_;
52  Dtype* data_;
53  Dtype* labels_;
54  int n_;
55  size_t pos_;
56  Blob<Dtype> added_data_;
57  Blob<Dtype> added_label_;
58  bool has_new_data_;
59 };
60 
61 } // namespace caffe
62 
63 #endif // CAFFE_MEMORY_DATA_LAYER_HPP_
virtual void Forward_cpu(const vector< Blob< Dtype > *> &bottom, const vector< Blob< Dtype > *> &top)
Using the CPU device, compute the layer output.
Definition: memory_data_layer.cpp:108
A layer factory that allows one to register layers. During runtime, registered layers can be called b...
Definition: blob.hpp:14
virtual int ExactNumBottomBlobs() const
Returns the exact number of bottom blobs required by the layer, or -1 if no exact number is required...
Definition: memory_data_layer.hpp:28
Provides base for data layers that feed blobs to the Net.
Definition: base_data_layer.hpp:21
virtual int ExactNumTopBlobs() const
Returns the exact number of top blobs required by the layer, or -1 if no exact number is required...
Definition: memory_data_layer.hpp:29
Provides data to the Net from memory.
Definition: memory_data_layer.hpp:20
virtual const char * type() const
Returns the layer type.
Definition: memory_data_layer.hpp:27
A wrapper around SyncedMemory holders serving as the basic computational unit through which Layers...
Definition: blob.hpp:24