[转载]Windows部署Caffe-Backup Best Guidence
2016-07-30 11:13
423 查看
Caffe + vs2013 + OpenCV in Windows Tutorial (I) – Setup
Posted on July15, 2015 by Neil
Z. Shao
The purpose of this series it to get caffe working
in windows in the most quick and dirty way: I’ll provide 1) the modified file that can be compiled in windows right away; 2) the vs2013 project that I’m currently using. In short:
Install CUDA, Boost, OpenCV.
Download caffe code with vs2013 from GitHub.
Download 3ryparty.zip and
unzip to ‘3rdparty’ folder.
Edit ‘Caffe-vs2013 – Debug.props’ and ‘Caffe-vs2013 – Release.props’ files so that the path of CUDA, Boost and OpenCV make sense for you. Also, the
given ‘compute_50,sm_50’ is for Maxwell GPU.
Change 50 to 20 for Fermiand
30 for Kepler.
Open caffe-vs2013.sln.
Set platform to Release, x64 and change ‘caffe’ project’s ‘Configuration Type’ to ‘Application (.exe)’.
Right click on ‘caffe’ project and ‘compile’.
Run test on MNIST.
For caffe.exe, please use Release|x64 mode. Debug version of caffe.exe makes no sense and is slow.
32 bit version should work but lacking support for lmdb and hdf5 because I didn’t compile them. lol
Setup:
CUDA 6.5
You have to have a Nvidia GPU on your PC to enable GPU version of Caffe. My impression was that you get maybe 10x speed-up using GPU over CPU, and another 10x speed-up by enable CuDNN library.
The installation will create system variable for you, e.g. CUDA_PATH_V6_5.
If you are using a GPU with the architecture of Fermi or Kepler: CUDA
6.5
If you are using a GeForce GTX9xx GPU with the architecture of Maxwell: CUDA
6.5 for Maxwell
Newer version of CUDA should be
fine also.
Boost
Pre-built version of boost are available. I’m using boost 1.56.0 myself. Get pre-built
boost and install.
Add boost’s path to system’s path. I added BOOST_1_56_0:
OpenCV
Since we are not using GPU supported OpenCV here, e.g. GpuMat, etc. Pre-built
version of OpenCV are good enough for a quick start.
I use OpenCV 3.0 here as example. Add system path variable for OpenCV also:
System variable need ‘log off’ or ‘restart’ your system to take effect
Download the code for caffe from my GitHub
The original code was forded from 7e465f2.
Then I manually added the changes from #1416 to
support “vector<Mat>”.
Download the 3rdparty.zip and unzip its content to 3rdpary folder
3rdparty.zip (Version 2015.7.18) [Google
Drive] [360 YunPan (code: 6147)]
3rdparty.zip
(Version 2015.7.15)
Included is the support for gflags, glog, google/protobuf, hdf5, leveldb, liblmdb, openblas, cudnn,
etc.
Before compile (skip if you’re familiar with vs2013 already):
When it comes to a big project, many errors can happen. Let’s get things a bit clear first.
In a project, usually functions are declared in .h/.hpp files and implemented in .c/.cpp files. Missing .hpp file is usually shown in the editor and missing .cpp file usually gives linking error.
All .cpp files added to the vs project will be compiled to .obj files which can be linked later. While no .hpp files will be compiled. Adding .hpp files to the vs project or not makes no difference to the compiling.
If you want to include .hpp file from another project, e.g. OpenCV. You need to add the path of the header files to ‘AdditionalIncludeDirectories’.
Adding header files to the vs project does NOT add the path automatically.
Adding the path of .cpp files to ‘AdditionalIncludeDirectories’ is NOT needed and has NO effect.
For example if the file path is “D:\toolkits\opencv-3.0.0\build\include\opencv2\opencv.hpp”, you can either:
1) add “D:\toolkits\opencv-3.0.0\build\include” to ‘AdditionalIncludeDirectories’ and write #include “opencv2/opencv.hpp”; or
2) add “D:\toolkits\opencv-3.0.0\build\include\opencv2” to ‘AdditionalIncludeDirectories’ and write #include “opencv.hpp”;
After the .hpp file is included, the compiler knows that these functions exist so ‘unknown namespace cv’ kind of error will not happen any more.
After all .cpp files in your project are compiled, here comes the linking. The implementation of functions have to be either in .cpp files of your project or .lib files generated by other projects.
Enabling lib files requires 1) path to be added to ‘AdditionalLibraryDirectories’; and 2) file names to be added to ‘AdditionalDependencies’.
For example, you might add “D:\toolkits\opencv-3.0.0\build\x86\vc12\lib” to ‘AdditionalLibraryDirectories’ and add “opencv_ts300.lib; opencv_world300.lib;” to ‘AdditionalDependencies’.
Usually the path of lib files changes according to the ‘PlatformTarget’, i.e. ‘x86’, and the ‘Configuration’, i.e. ‘Debug’. I usually let Visual Studio handle the difference, e.g. I add “$(OPENCV_3_0_0)\$(PlatformTarget)\vc12\lib” for OpenCV in
later sections.
If you solve compile error by having proper .hpp files and solve linking error by have proper .lib files, you program will run. Yet it might have missing .dll error.
Some library are compiled in the static way to generate .lib files only, like gflags, protobuf, etc.
Some library are compiled in the dynamic way to generate both .lib and .dll files. In this case your program will require .dll files on run-time.
Personally I like to copy required .dll files to the same folder of the .exe file for simplicity.
相关文章推荐
- 【转载】在Windows下快速部署MongoDB服务
- windows 10 下 Caffe + Matlab 部署
- 转载:linux下 openldap 的配置(windows下配置部署的话,请部分参考)
- 【转载】Python的Cython在Windows环境下的部署安装
- 微软杂志转载:Windows 7 部署指南
- (转载)关于Windows下ShellCode编写的一点思考
- 为 Microsoft Windows SharePoint Services 中的文档库创建事件日志消息 [转载]
- 取回WINDOWS密码的绝妙方法(转载)
- 網管必讀-常用網絡命令Windows 200x (转载)
- Windows自动启动程序的十大藏身之所(转载)
- Windows的端口列表(转载)
- HOW TO:使用 Visual C# _NET 对 DataGrid Windows 控件执行分页(转载)
- 仿windows登陆条 (转载)
- 初探在下一代 Windows 中编写和部署应用程序
- 解决Windows 程序界面闪烁问题的一些经验 (转载)
- (转载)Windows 9X 启动全揭秘
- (转载)获取Windows 系统的内核变量
- Windows Socket API 使用经验(转载)
- (转载)Windows 98 第二版的关机问题
- Windows 2000/XP 注册表终极修改(转载)