利用caffe写自己的程序

caffe-window搭建自己的小项目例子
caffe-Windows】添加工程-以classification为例
caffe-windows添加自己的工程
参考上面的文章,感恩万分。
因为要用到caffe写自己的程序,需要重新新建工程,很多caffe中的链接库呀什么的不会弄,幸得博客大牛多多,借鉴之后可以
用上了,这里做个总结,以免自己忘记。

1.新建一个c++工程

新建一个MFC程序,也可以新建一个控制台程序,都行。这里新建一个MFC程序。

利用caffe写自己的程序_第1张图片

选择的是:
基于对话框
在共享DLL中使用MFC
之后发现错误之后再改成这个也行,其他不用修改。

2.配置环境

1、打开工程的属性窗口–>找到C/C++–>Treat Warning As Errors(将警告视为错误),将其改为no。
2、打开工程的属性窗口,将配置改为release,平台改为x64,没有x64,则新建一个,在New platform中选择x64即可

利用caffe写自己的程序_第2张图片
利用caffe写自己的程序_第3张图片
3. 打开工程的属性窗口–>c/c++–>常规–>附加包含目录,include添加一下:
(1)添加下载的NugetPackages中的依赖
E:\MFC\caffe\NugetPackages\boost.1.59.0.0\lib\native\include
E:\MFC\caffe\NugetPackages\boost.1.59.0.0\lib\native\include\boost
E:\MFC\caffe\NugetPackages\gflags.2.1.2.1\build\native\include
E:\MFC\caffe\NugetPackages\gflags.2.1.2.1\build\native\include\gflags
E:\MFC\caffe\NugetPackages\glog.0.3.3.0\build\native\include
E:\MFC\caffe\NugetPackages\glog.0.3.3.0\build\native\include\glog
E:\MFC\caffe\NugetPackages\protobuf-v120.2.6.1\build\native\include
E:\MFC\caffe\NugetPackages\protobuf-v120.2.6.1\build\native\include\google
E:\MFC\caffe\NugetPackages\OpenBLAS.0.2.14.1\lib\native\include
E:\MFC\caffe\NugetPackages\OpenCV.2.4.10\build\native\include
E:\MFC\caffe\NugetPackages\OpenCV.2.4.10\build\native\include\opencv
E:\MFC\caffe\NugetPackages\OpenCV.2.4.10\build\native\include\opencv2
(2)添加caffe-master中的依赖
E:\MFC\caffe\Class-MFC2\include(将caffe-master\include移动到自己的文件夹下,也可包含未移动的如第2项)
E:\MFC\caffe\caffe-master\include
E:\MFC\caffe\caffe-master\src\caffe
(3)添加cuda中的依赖
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v7.0\include

4. 打开工程的属性窗口–>链接器–>常规–>附加依赖库,lib添加一下:
(1)添加下载的NugetPackages中的依赖
E:\MFC\caffe\NugetPackages\boost_date_time-vc120.1.59.0.0\lib
E:\MFC\caffe\NugetPackages\OpenCV.2.4.10\build\native\lib\x64\v120\Release
E:\MFC\caffe\NugetPackages\boost_date_time-vc120.1.59.0.0\lib\native\address-model-64\lib
E:\MFC\caffe\NugetPackages\boost_filesystem-vc120.1.59.0.0\lib\native\address-model-64\lib
E:\MFC\caffe\NugetPackages\boost_system-vc120.1.59.0.0\lib\native\address-model-64\lib
E:\MFC\caffe\NugetPackages\glog.0.3.3.0\build\native\lib\x64\v120\Release\dynamic
E:\MFC\caffe\NugetPackages\gflags.2.1.2.1\build\native\x64\v120\dynamic\Lib
E:\MFC\caffe\NugetPackages\OpenBLAS.0.2.14.1\lib\native\lib\x64
E:\MFC\caffe\NugetPackages\protobuf-v120.2.6.1\build\native\lib\x64\v120\Release
E:\MFC\caffe\NugetPackages\hdf5-v120-complete.1.8.15.2\lib\native\lib\x64
E:\MFC\caffe\NugetPackages\lmdb-v120-clean.0.9.14.0\lib\native\lib\x64
E:\MFC\caffe\NugetPackages\boost_chrono-vc120.1.59.0.0\lib\native\address-model-64\lib
E:\MFC\caffe\NugetPackages\boost_thread-vc120.1.59.0.0\lib\native\address-model-64\lib
E:\MFC\caffe\NugetPackages\LevelDB-vc120.1.2.0.0\build\native\lib\x64\v120\Release
(2)添加caffe-master中的依赖
E:\MFC\caffe\caffe-master\Build\x64\Release
E:\MFC\caffe\Class-MFC2\lib(将上述E:\MFC\caffe\caffe-master\Build\x64\Release中lib文件放在本项目下,两者选其一即可)
(3)添加cuda中的依赖
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v7.0\include

5. 打开工程的属性窗口–>链接器–>输入–>附加依赖库,添加一下依赖:
caffe.lib
libcaffe.lib
cudart.lib
cublas.lib
curand.lib
gflags.lib
libglog.lib
libopenblas.dll.a
libprotobuf.lib
leveldb.lib
lmdb.lib
hdf5.lib
hdf5_hl.lib
Shlwapi.lib
opencv_core2410.lib
opencv_highgui2410.lib
opencv_imgproc2410.lib
opencv_video2410.lib
opencv_objdetect2410.lib

6.新建一个head.h 添加如下代码

 #include "caffe/common.hpp"
 #include "caffe/layers/input_layer.hpp"
 #include "caffe/layers/inner_product_layer.hpp"
 #include "caffe/layers/dropout_layer.hpp"
 #include "caffe/layers/conv_layer.hpp"
 #include "caffe/layers/relu_layer.hpp"

 #include "caffe/layers/pooling_layer.hpp"
 #include "caffe/layers/lrn_layer.hpp"
 #include "caffe/layers/softmax_layer.hpp"


namespace caffe
{

    extern INSTANTIATE_CLASS(InputLayer);
    extern INSTANTIATE_CLASS(InnerProductLayer);
    extern INSTANTIATE_CLASS(DropoutLayer);
    extern INSTANTIATE_CLASS(ConvolutionLayer);
    REGISTER_LAYER_CLASS(Convolution);
    extern INSTANTIATE_CLASS(ReLULayer);
    REGISTER_LAYER_CLASS(ReLU);
    extern INSTANTIATE_CLASS(PoolingLayer);
    REGISTER_LAYER_CLASS(Pooling);
    extern INSTANTIATE_CLASS(LRNLayer);
    REGISTER_LAYER_CLASS(LRN);
    extern INSTANTIATE_CLASS(SoftmaxLayer);
    REGISTER_LAYER_CLASS(Softmax);

}

然后将以下头文件加入stdafx.h

 #include 
 #include "head.h"

7.将caffe-master/windows中的CommonSettings.props移动到自己项目文件中,在项目属性管理器中,添加进去
利用caffe写自己的程序_第4张图片

生成项目文件时能正常生成

你可能感兴趣的:(Caffe学习)