Caffe源码解析caffe.cpp
2016-12-28 16:19
423 查看
当了解Caffe相关的模型结构,并跑出相对应的模型,想要进一步了解Caffe结构,就需要对Caffe中的源码了解,这样才能更好的了解Caffe工具,为以后实现个性化定制Caffe做好准备。以下工作主要说明Caffe.cpp如何对相应的train、test、time、device_query进行调用。
在Caffe源码的基础上,对其中的代码进行分离,达到更好的了解!Caffe调用相应的函数是基于函数指针实现,具体可以参考http://blog.csdn.net/zff1988927/article/details/53908351 ,在里面有具体的解析。
#include "iostream"
#include "map"
#include "string"
typedef int(*BrewFunction)(); //定义函数指针!
typedef std::map<std::string, BrewFunction> BrewMap; //函数指针对应容器!
BrewMap g_brew_map; //定义指针全局变量!
static BrewFunction GetBrewFunction(const std::string & name) //返回函数相应指针!
{
int a = g_brew_map.count(name); //判断其中是否有相应的参数!
if (a)
return g_brew_map[name];
}
//#define RegisterBrewFunction(func) \
// namespace {\
//class __Registerer_##func{ \
//public: /* NOLINT */ \
// __Registerer_##func() {\
// g_brew_map[#func] = &func; \
//} \
//}; \
// __Registerer_##func g_registerer_##func; \
//}
#define RegisterBrewFunction(func) g_brew_map[#func]=&func; //宏定义,替代Caffe中上面的定义。
int train() //简化Caffe训练函数!
{
printf("%s", "开始训练");
return 2;
}
//RegisterBrewFunction(train);
int test() //简化Caffe测试函数,以下类似!
{
printf("%s", "开始测试");
return 2;
}
//RegisterBrewFunction(test);
int device_query()
{
printf("%s", "显示CPU、GPU设备");
return 2;
}
//RegisterBrewFunction(device_query);
int time()
{
printf("%s", "打印时间");
return 2;
}
//RegisterBrewFunction(time);
int main()
{
RegisterBrewFunction(train);
RegisterBrewFunction(test);
RegisterBrewFunction(device_query);
RegisterBrewFunction(time);
return GetBrewFunction("train")();
}
在Caffe源码的基础上,对其中的代码进行分离,达到更好的了解!Caffe调用相应的函数是基于函数指针实现,具体可以参考http://blog.csdn.net/zff1988927/article/details/53908351 ,在里面有具体的解析。
#include "iostream"
#include "map"
#include "string"
typedef int(*BrewFunction)(); //定义函数指针!
typedef std::map<std::string, BrewFunction> BrewMap; //函数指针对应容器!
BrewMap g_brew_map; //定义指针全局变量!
static BrewFunction GetBrewFunction(const std::string & name) //返回函数相应指针!
{
int a = g_brew_map.count(name); //判断其中是否有相应的参数!
if (a)
return g_brew_map[name];
}
//#define RegisterBrewFunction(func) \
// namespace {\
//class __Registerer_##func{ \
//public: /* NOLINT */ \
// __Registerer_##func() {\
// g_brew_map[#func] = &func; \
//} \
//}; \
// __Registerer_##func g_registerer_##func; \
//}
#define RegisterBrewFunction(func) g_brew_map[#func]=&func; //宏定义,替代Caffe中上面的定义。
int train() //简化Caffe训练函数!
{
printf("%s", "开始训练");
return 2;
}
//RegisterBrewFunction(train);
int test() //简化Caffe测试函数,以下类似!
{
printf("%s", "开始测试");
return 2;
}
//RegisterBrewFunction(test);
int device_query()
{
printf("%s", "显示CPU、GPU设备");
return 2;
}
//RegisterBrewFunction(device_query);
int time()
{
printf("%s", "打印时间");
return 2;
}
//RegisterBrewFunction(time);
int main()
{
RegisterBrewFunction(train);
RegisterBrewFunction(test);
RegisterBrewFunction(device_query);
RegisterBrewFunction(time);
return GetBrewFunction("train")();
}
相关文章推荐
- caffe源码解析 — net.cpp
- caffe源码解析之blob.hpp或blob.cpp
- caffe源码解析 — net.cpp
- caffe源码解析之blob.hpp或blob.cpp
- caffe源码解析 — solver.cpp
- caffe源码解析 — blob.cpp
- caffe源码解析 — train_net.cpp
- caffe源码解析-/tools/caffe.cpp(caffe程序入口)
- caffe源码解析之blob.hpp或blob.cpp
- caffe源码解析 — solver.cpp
- caffe源码解析 — blob.cpp
- 【Caffe】002 caffe.cpp源码解析
- caffe源码解析 — SyncedMemory.cpp
- caffe源码解析 — solver.cpp
- CAFFE源码阅读(compute_image_mean.cpp)
- Caffe源码(十一):io.cpp 分析
- caffe源码解析 — caffe.proto
- caffe源码简单解析——Blob(1)
- caffe源码解析 — caffe.proto
- caffe源码解析之blob