DMLC: Distributed (Deep) Machine Learning Community 是一种库,这里面学习的是其操作(类似于caffe里面的层)里面参数设置,通过继承dmlc里面的Parameter这个类,使用dmlc里面的一些宏定义来实现这个功能,具体例子可以参见下面的例子。
#include<dmlc/parameter.h> #include<iostream> // declare the parameter, normally put it in header file. struct MyParam : public dmlc::Parameter<MyParam> { float learning_rate; int num_hidden; int activation; std::string name; // declare parameters DMLC_DECLARE_PARAMETER(MyParam) { DMLC_DECLARE_FIELD(num_hidden).set_range(0, 1000) .describe("Number of hidden unit in the fully connected layer."); DMLC_DECLARE_FIELD(learning_rate).set_default(0.01f) .describe("Learning rate of SGD optimization."); DMLC_DECLARE_FIELD(activation).add_enum("relu", 1).add_enum("sigmoid", 2) .describe("Activation function type."); DMLC_DECLARE_FIELD(name).set_default("layer") .describe("Name of the net."); } }; // register the parameter, this is normally in a cc file. DMLC_REGISTER_PARAMETER(MyParam); int main() { MyParam param; std::vector<std::pair<std::string, std::string> > param_data = { {"num_hidden", "100"}, {"activation", "relu"}, {"name", "myname"} }; // set the parameters param.Init(param_data); std::cout << param.name << std::endl; param.name="hello"; std::cout << param.name << std::endl; return 0; }