Caffe
batch_reindex_layer.hpp
1 #ifndef CAFFE_BATCHREINDEX_LAYER_HPP_
2 #define CAFFE_BATCHREINDEX_LAYER_HPP_
3 
4 #include <utility>
5 #include <vector>
6 
7 #include "caffe/blob.hpp"
8 #include "caffe/layer.hpp"
9 #include "caffe/proto/caffe.pb.h"
10 
11 namespace caffe {
12 
20 template <typename Dtype>
21 class BatchReindexLayer : public Layer<Dtype> {
22  public:
23  explicit BatchReindexLayer(const LayerParameter& param)
24  : Layer<Dtype>(param) {}
25  virtual void Reshape(const vector<Blob<Dtype>*>& bottom,
26  const vector<Blob<Dtype>*>& top);
27 
28  virtual inline const char* type() const { return "BatchReindex"; }
29  virtual inline int ExactNumBottomBlobs() const { return 2; }
30  virtual inline int ExactNumTopBlobs() const { return 1; }
31 
32  protected:
45  virtual void Forward_cpu(const vector<Blob<Dtype>*>& bottom,
46  const vector<Blob<Dtype>*>& top);
47  virtual void Forward_gpu(const vector<Blob<Dtype>*>& bottom,
48  const vector<Blob<Dtype>*>& top);
49 
65  virtual void Backward_cpu(const vector<Blob<Dtype>*>& top,
66  const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom);
67  virtual void Backward_gpu(const vector<Blob<Dtype>*>& top,
68  const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom);
69 
70  private:
71  struct pair_sort_first {
72  bool operator()(const std::pair<int, int> &left,
73  const std::pair<int, int> &right) {
74  return left.first < right.first;
75  }
76  };
77  void check_batch_reindex(int initial_num, int final_num,
78  const Dtype* ridx_data);
79 };
80 
81 } // namespace caffe
82 
83 #endif // CAFFE_BATCHREINDEX_LAYER_HPP_
An interface for the units of computation which can be composed into a Net.
Definition: layer.hpp:33
A layer factory that allows one to register layers. During runtime, registered layers can be called b...
Definition: blob.hpp:14
virtual const char * type() const
Returns the layer type.
Definition: batch_reindex_layer.hpp:28
virtual int ExactNumBottomBlobs() const
Returns the exact number of bottom blobs required by the layer, or -1 if no exact number is required...
Definition: batch_reindex_layer.hpp:29
virtual void Forward_cpu(const vector< Blob< Dtype > *> &bottom, const vector< Blob< Dtype > *> &top)
Definition: batch_reindex_layer.cpp:33
virtual void Reshape(const vector< Blob< Dtype > *> &bottom, const vector< Blob< Dtype > *> &top)
Adjust the shapes of top blobs and internal buffers to accommodate the shapes of the bottom blobs...
Definition: batch_reindex_layer.cpp:9
virtual void Backward_gpu(const vector< Blob< Dtype > *> &top, const vector< bool > &propagate_down, const vector< Blob< Dtype > *> &bottom)
Using the GPU device, compute the gradients for any parameters and for the bottom blobs if propagate_...
virtual void Backward_cpu(const vector< Blob< Dtype > *> &top, const vector< bool > &propagate_down, const vector< Blob< Dtype > *> &bottom)
Computes the error gradient w.r.t. the reordered input.
Definition: batch_reindex_layer.cpp:52
Index into the input blob along its first axis.
Definition: batch_reindex_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: batch_reindex_layer.hpp:30
virtual void Forward_gpu(const vector< Blob< Dtype > *> &bottom, const vector< Blob< Dtype > *> &top)
Using the GPU device, compute the layer output. Fall back to Forward_cpu() if unavailable.
A wrapper around SyncedMemory holders serving as the basic computational unit through which Layers...
Definition: blob.hpp:24