39 #ifndef CAFFE_LAYER_FACTORY_H_ 40 #define CAFFE_LAYER_FACTORY_H_ 46 #include "caffe/common.hpp" 47 #include "caffe/layer.hpp" 48 #include "caffe/proto/caffe.pb.h" 52 template <
typename Dtype>
55 template <
typename Dtype>
58 typedef shared_ptr<Layer<Dtype> > (*Creator)(
const LayerParameter&);
59 typedef std::map<string, Creator> CreatorRegistry;
61 static CreatorRegistry& Registry() {
62 static CreatorRegistry* g_registry_ =
new CreatorRegistry();
67 static void AddCreator(
const string& type, Creator creator) {
68 CreatorRegistry& registry = Registry();
69 CHECK_EQ(registry.count(type), 0)
70 <<
"Layer type " << type <<
" already registered.";
71 registry[type] = creator;
75 static shared_ptr<Layer<Dtype> > CreateLayer(
const LayerParameter& param) {
76 if (Caffe::root_solver()) {
77 LOG(INFO) <<
"Creating layer " << param.name();
79 const string& type = param.type();
80 CreatorRegistry& registry = Registry();
81 CHECK_EQ(registry.count(type), 1) <<
"Unknown layer type: " << type
82 <<
" (known types: " << LayerTypeListString() <<
")";
83 return registry[type](param);
86 static vector<string> LayerTypeList() {
87 CreatorRegistry& registry = Registry();
88 vector<string> layer_types;
89 for (
typename CreatorRegistry::iterator iter = registry.begin();
90 iter != registry.end(); ++iter) {
91 layer_types.push_back(iter->first);
101 static string LayerTypeListString() {
102 vector<string> layer_types = LayerTypeList();
103 string layer_types_str;
104 for (vector<string>::iterator iter = layer_types.begin();
105 iter != layer_types.end(); ++iter) {
106 if (iter != layer_types.begin()) {
107 layer_types_str +=
", ";
109 layer_types_str += *iter;
111 return layer_types_str;
116 template <
typename Dtype>
120 shared_ptr<
Layer<Dtype> > (*creator)(
const LayerParameter&)) {
127 #define REGISTER_LAYER_CREATOR(type, creator) \ 128 static LayerRegisterer<float> g_creator_f_##type(#type, creator<float>); \ 129 static LayerRegisterer<double> g_creator_d_##type(#type, creator<double>) \ 131 #define REGISTER_LAYER_CLASS(type) \ 132 template <typename Dtype> \ 133 shared_ptr<Layer<Dtype> > Creator_##type##Layer(const LayerParameter& param) \ 135 return shared_ptr<Layer<Dtype> >(new type##Layer<Dtype>(param)); \ 137 REGISTER_LAYER_CREATOR(type, Creator_##type##Layer) 141 #endif // CAFFE_LAYER_FACTORY_H_ 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
Definition: layer_factory.hpp:117
Definition: layer_factory.hpp:56