Define split layer (merge trick)
authorEvan Shelhamer <shelhamer@imaginarynumber.net>
Wed, 26 Feb 2014 22:56:37 +0000 (14:56 -0800)
committerEvan Shelhamer <shelhamer@imaginarynumber.net>
Wed, 26 Feb 2014 22:56:37 +0000 (14:56 -0800)
Originally authored by Jeff Donahue, but this commit was needed for
historical reasons.

include/caffe/vision_layers.hpp
src/caffe/layer_factory.cpp

index 47909a2..1861535 100644 (file)
@@ -126,6 +126,27 @@ class DropoutLayer : public NeuronLayer<Dtype> {
 
 
 template <typename Dtype>
+class SplitLayer : public Layer<Dtype> {
+ public:
+  explicit SplitLayer(const LayerParameter& param)
+      : Layer<Dtype>(param) {}
+  virtual void SetUp(const vector<Blob<Dtype>*>& bottom,
+      vector<Blob<Dtype>*>* top);
+
+ protected:
+  virtual void Forward_cpu(const vector<Blob<Dtype>*>& bottom,
+      vector<Blob<Dtype>*>* top);
+  virtual void Forward_gpu(const vector<Blob<Dtype>*>& bottom,
+      vector<Blob<Dtype>*>* top);
+  virtual Dtype Backward_cpu(const vector<Blob<Dtype>*>& top,
+      const bool propagate_down, vector<Blob<Dtype>*>* bottom);
+  virtual Dtype Backward_gpu(const vector<Blob<Dtype>*>& top,
+      const bool propagate_down, vector<Blob<Dtype>*>* bottom);
+  int count_;
+};
+
+
+template <typename Dtype>
 class FlattenLayer : public Layer<Dtype> {
  public:
   explicit FlattenLayer(const LayerParameter& param)
index cb65e8f..ff69c91 100644 (file)
@@ -55,6 +55,8 @@ Layer<Dtype>* GetLayer(const LayerParameter& param) {
     return new SoftmaxLayer<Dtype>(param);
   } else if (type == "softmax_loss") {
     return new SoftmaxWithLossLayer<Dtype>(param);
+  } else if (type == "split") {
+    return new SplitLayer<Dtype>(param);
   } else if (type == "multinomial_logistic_loss") {
     return new MultinomialLogisticLossLayer<Dtype>(param);
   } else {