the previous submit did not include the layer factory (blush)
authorYangqing Jia <jiayq84@gmail.com>
Mon, 23 Sep 2013 22:31:55 +0000 (15:31 -0700)
committerYangqing Jia <jiayq84@gmail.com>
Mon, 23 Sep 2013 22:31:55 +0000 (15:31 -0700)
src/caffe/layer_factory.hpp [new file with mode: 0644]

diff --git a/src/caffe/layer_factory.hpp b/src/caffe/layer_factory.hpp
new file mode 100644 (file)
index 0000000..a8e9989
--- /dev/null
@@ -0,0 +1,44 @@
+#ifndef CAFFE_LAYER_FACTORY_HPP_
+#define CAFFE_LAYER_FACTORY_HPP_
+
+#include "caffe/layer.hpp"
+#include "caffe/vision_layers.hpp"
+#include "caffe/proto/layer_param.pb.h"
+
+
+namespace caffe {
+
+
+// A function to get a specific layer from the specification given in
+// LayerParameter. Ideally this would be replaced by a factory pattern,
+// but we will leave it this way for now.
+template <typename Dtype>
+Layer<Dtype>* GetLayer(const LayerParameter& param) {
+  const std::string& type = param.type();
+  if (type == "conv") {
+    return new ConvolutionLayer<Dtype>(param);
+  } else if (type == "dropout") {
+    return new DropoutLayer<Dtype>(param);
+  } else if (type == "im2col") {
+    return new Im2colLayer<Dtype>(param);
+  } else if (type == "innerproduct") {
+    return new InnerProductLayer<Dtype>(param);
+  } else if (type == "lrn") {
+    return new LRNLayer<Dtype>(param);
+  } else if (type == "padding") {
+    return new PaddingLayer<Dtype>(param);
+  } else if (type == "pool") {
+    return new PoolingLayer<Dtype>(param);
+  } else if (type == "relu") {
+    return new ReLULayer<Dtype>(param);
+  } else {
+    LOG(FATAL) << "Unknown filler name: " << type;
+  }
+  // just to suppress old compiler warnings.
+  return (Layer<Dtype>*)(NULL);
+}
+
+
+}  // namespace caffe
+
+#endif  // CAFFE_LAYER_FACTORY_HPP_