Building the solution
Contents
Building the solution
Now it is time to compile Caffe from source.
Loading the solution in Visual Studio 2013
Start your Visual Studio 2013 (you may need to do this as Administrator if you faced permission problems for accessing file in the C: drive). Now from File -> Open -> Project/Solutoin load the Caffe.sln file located in C:\projects\caffe\windows folder. After the solution has been loaded, the Solution Explorer window should look like the following image:
Editing compile options
To tell Visual Studio what to build for us (e.g. CPU, GPU, cuDNN, Matlab and Python support) you only need to edit the CommonSettings.props (highlighted in the above image) file. I personally do not care about the Matlab and Python wrappers, but if you would like to have them, follow the guide of the authors:
Python
To build Caffe Python wrapper set
PythonSupport
totrue
in.\windows\CommonSettings.props
. Download Miniconda 2.7 64-bit Windows installer from Miniconda website. Install for all users and add Python to PATH (through installer).Run the following commands from elevated command prompt:
12345 conda install --yes numpy scipy matplotlib scikit-image pippip install protobufRemark
After you have built solution with Python support, in order to use it you have to either:
- set
PythonPath
environment variable to point to<caffe_root>\Build\x64\Release\pycaffe
, or- copy folder
<caffe_root>\Build\x64\Release\pycaffe\caffe
under<python_root>\lib\site-packages
.Matlab
To build Caffe Matlab wrapper set
MatlabSupport
totrue
andMatlabDir
to the root of your Matlab installation in.\windows\CommonSettings.props
.Remark
After you have built solution with Matlab support, in order to use it you have to:
- add the generated
matcaffe
folder to Matlab search path, and- add
<caffe_root>\Build\x64\Release
to your system path.
Back to our own journey, to compile Caffe with CUDA and cuDNN you need to make the following changes in the CommonSettings.props file:
- Set the <CpuOnlyBuild> to false
- Set the <UseCuDnn> to true
- Set the correct GPU Architecture by editing the <CudaArchitecture> tag. In my case, I am using a GTX 770 graphics card and I am good with these options: compute_30,sm_30  You can add pairs of compute _xx and sm_xx architectures separated by ‘;‘ characters.  If you are not sure what shader model and compute capabilities your graphics card has, you can learn more at nVIDIA’s specification page for your graphics card.
- Give the following path for the <CuDnnPath> option: C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v7.5 because as you can see further more in this file, it always appends \cuda\ to this directory.
To make it short, your first few lines of CommonSettings.props file should look like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
<?xml version="1.0" encoding="utf-8"?> <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <ImportGroup Label="PropertySheets" /> <PropertyGroup Label="UserMacros"> <BuildDir>$(SolutionDir)..\Build</BuildDir> <!--NOTE: CpuOnlyBuild and UseCuDNN flags can't be set at the same time.--> <CpuOnlyBuild>false</CpuOnlyBuild> <UseCuDNN>true</UseCuDNN> <CudaVersion>7.5</CudaVersion> <!-- NOTE: If Python support is enabled, PythonDir (below) needs to be set to the root of your Python installation. If your Python installation does not contain debug libraries, debug build will not work. --> <PythonSupport>false</PythonSupport> <!-- NOTE: If Matlab support is enabled, MatlabDir (below) needs to be set to the root of your Matlab installation. --> <MatlabSupport>false</MatlabSupport> <CudaDependencies></CudaDependencies> <!-- Set CUDA architecture suitable for your GPU. Setting proper architecture is important to mimize your run and compile time. --> <CudaArchitecture>compute_30,sm_30;compute_52,sm_52</CudaArchitecture> <!-- CuDNN 3 and 4 are supported --> <!-- EDITED BY SAEID 8======> you must copy cudnn folder here in "cuda" folder--> <CuDnnPath>C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v7.5</CuDnnPath> <ScriptsDir>$(SolutionDir)\scripts</ScriptsDir> </PropertyGroup> |
Now, make sure that your build mode is set to Debug and the target architecture is set to x64. Then just press F6 or from Build menu select the Build Solution option. After about 20 minutes (on a Core i5/4670) you should be done!
At the end of build process, the resulted executable and library files will be generated in C:\projects\caffe\Build\x64\Debug folder. Now you can start using Caffe! I also recommend to add this directory to your Path environment variable.
I am planning to run a simple image pattern recognition using Caffe. If I succeeded, I will add a tutorial here in my website! If you faced any problems, let me know in the comment section or in the dedicated forum topic.
Thanks a lot, this helped me to install caffe (I was not able to do it from other repositories which claim to be the windows port). I do not have nvidia graphics card so I went CPU only.
Glad it helped. I recommend running caffe with the help from gpu, because using only the cpu will make complex projects take forever!
I’d like to thank you for this quick but expressive guide, it was really helpful. I’d like just to ask something, does this port support the newest version of CUDA (8.0) for Pascal architectures and CuDNN 5.0 or 5.1? Thanks again!
I believe not, at least for the Windows platform…CUDA 8 is quite new and it will take a while (maybe well over a year) for Caffe to catch up. But I believe there has been some activities on Linux side of things according to BLVC on GitHub
Caffe can be compiled with either Make or CMake. Make is officially supported while CMake is supported by the community.
I did not have any success on Windows to build using CMAKE, I always got lots of errors in CMAKE. If you know the correct procedure please let us know!
Hello Saeid,
Thank you very much for the nice explanation.
I have successfully installed CUDA Toolkit and VS 2013. After that copied the ‘cuda’ folder in cuDNN to C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0
I couldn’t understand what to do after. Can you please help to complete the installation as i want to run this code https://github.com/rbgirshick/rcnn/tree/d0a24bec888e123885f8a229cc4f4a71cbeee80d
You need to create some layers to train the classifier, there are plenty of examples provided by caffe! just check those out.
Hello Saeid
I have followed all the steps. And I am getting the following error while building the caffe.sln file.:
Error 25 error : NuGet Error:Unknown command: 'overlay' G:\Research\NugetPackages\glog.0.3.3.0\build\native\glog.targets 329 5 upgrade_solver_proto_text
I am getting the following output from the build:
1>------ Build started: Project: libcaffe, Configuration: Debug x64 ------
1>G:\Research\NugetPackages\glog.0.3.3.0\build\native\glog.targets(329,5): error : NuGet Error:Unknown command: 'overlay'
2>------ Build started: Project: caffe, Configuration: Debug x64 ------
3>------ Build started: Project: convert_cifar_data, Configuration: Debug x64 ------
4>------ Build started: Project: classification, Configuration: Debug x64 ------
5>------ Build started: Project: convert_mnist_data, Configuration: Debug x64 ------
4>G:\Research\NugetPackages\glog.0.3.3.0\build\native\glog.targets(329,5): error : NuGet Error:Unknown command: 'overlay'
3>G:\Research\NugetPackages\glog.0.3.3.0\build\native\glog.targets(329,5): error : NuGet Error:Unknown command: 'overlay'
6>------ Build started: Project: convert_mnist_siamese_data, Configuration: Debug x64 ------
7>------ Build started: Project: upgrade_net_proto_binary, Configuration: Debug x64 ------
5>G:\Research\NugetPackages\glog.0.3.3.0\build\native\glog.targets(329,5): error : NuGet Error:Unknown command: 'overlay'
8>------ Build started: Project: upgrade_net_proto_text, Configuration: Debug x64 ------
2>G:\Research\NugetPackages\glog.0.3.3.0\build\native\glog.targets(329,5): error : NuGet Error:Unknown command: 'overlay'
9>------ Build started: Project: compute_image_mean, Configuration: Debug x64 ------
7>G:\Research\NugetPackages\glog.0.3.3.0\build\native\glog.targets(329,5): error : NuGet Error:Unknown command: 'overlay'
6>G:\Research\NugetPackages\glog.0.3.3.0\build\native\glog.targets(329,5): error : NuGet Error:Unknown command: 'overlay'
10>------ Build started: Project: convert_imageset, Configuration: Debug x64 ------
8>G:\Research\NugetPackages\glog.0.3.3.0\build\native\glog.targets(329,5): error : NuGet Error:Unknown command: 'overlay'
11>------ Build started: Project: extract_features, Configuration: Debug x64 ------
12>------ Build started: Project: test_all, Configuration: Debug x64 ------
9>G:\Research\NugetPackages\glog.0.3.3.0\build\native\glog.targets(329,5): error : NuGet Error:Unknown command: 'overlay'
13>------ Build started: Project: pycaffe, Configuration: Debug x64 ------
10>G:\Research\NugetPackages\glog.0.3.3.0\build\native\glog.targets(329,5): error : NuGet Error:Unknown command: 'overlay'
11>G:\Research\NugetPackages\glog.0.3.3.0\build\native\glog.targets(329,5): error : NuGet Error:Unknown command: 'overlay'
14>------ Build started: Project: matcaffe, Configuration: Debug x64 ------
15>------ Build started: Project: upgrade_solver_proto_text, Configuration: Debug x64 ------
12>G:\Research\NugetPackages\glog.0.3.3.0\build\native\glog.targets(329,5): error : NuGet Error:Unknown command: 'overlay'
13>G:\Research\NugetPackages\glog.0.3.3.0\build\native\glog.targets(329,5): error : NuGet Error:Unknown command: 'overlay'
14>G:\Research\NugetPackages\glog.0.3.3.0\build\native\glog.targets(329,5): error : NuGet Error:Unknown command: 'overlay'
15>G:\Research\NugetPackages\glog.0.3.3.0\build\native\glog.targets(329,5): error : NuGet Error:Unknown command: 'overlay'
========== Build: 0 succeeded, 15 failed, 0 up-to-date, 0 skipped ==========
Please help me out, as I have been trying to build caffe since last week.
Thanks.
– Lopa
I think this is a NuGet error, perhaps you have the wrong version! I think you better download standalone .exe of NuGet and try again…I cant remember but I think version 3 or 2 should work. Then pass the location of new downloaded NuGet.exe into the build file.
Hi. Saeid.
Your explanation is very helpful. but I get error in Project\Caffe\windows> Nuget restore Caffe.sln …. . It says Failed to load msbuild Toolset.
I download Nuget V3.5.0
What should I do.
Thanks you.
Hi, as far as I remember you should download the standalone executable of nuget, version 2 or 3…try both!
Hey saeid, first of all thank you for this tutorial ,
I compiled caffe but when I try to use it in matlab it gives an error , invalid mex file
That is a Matlab specific error…usually it means something is wrong with path to a library or something….
Hey.
Maybe you have to change the “mex -setup” in Matlab.
Hi..Thanks you Saeid,
Your explanation is very helpful.
But I still have the error when build caffe.sln.
The message is as follow ( for 13 descriptions):
Error 2 error : NuGet Error:Unknown command: ‘overlay’ C:\Project\NugetPackages\OpenCV.2.4.10\build\native\OpenCV.targets 768 5 caffe
What I should do Saeid?
Thanks you in advance,
Best regard,
Ismail
Thank you so much Saeid ! 🙂
I have installed caffe CPU only with (Python_support) on my Windows 7 successfully.
I want to run one example at https://github.com/shi-yan/caffe/tree/master/examples/cpp_xor
Please help me.
where can i find Nuget V 2.5?
it Nuget site only > 2.8 is available
I think you can find it on this link:
Download NuGet Standalone V2.5.0
i can not install on windows. If it is possible for me to install with teamviewer.
Settings and add the following enteries (replace the given path to the actual place you have installed the CUDNN_PATH = C:Program FilesNVIDIA GPU Computing ToolkitCUDAv7.5 CuDnnPath= C:Program FilesNVIDIA GPU Computing ToolkitCUDAv7.5
Hello sir, how to do this (make sure that your build mode is set to Debug and the target architecture is set to x64.)