Building the solution
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:
To build Caffe Python wrapper set
.\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:
123 conda install --yes numpy scipy matplotlib scikit-image pippip install protobuf
After you have built solution with Python support, in order to use it you have to either:
PythonPathenvironment variable to point to
- copy folder
To build Caffe Matlab wrapper set
MatlabDirto the root of your Matlab installation in
After you have built solution with Matlab support, in order to use it you have to:
- add the generated
matcaffefolder to Matlab search path, and
<caffe_root>\Build\x64\Releaseto 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:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ImportGroup Label="PropertySheets" />
<!--NOTE: CpuOnlyBuild and UseCuDNN flags can't be set at the same time.-->
<!-- 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. -->
<!-- NOTE: If Matlab support is enabled, MatlabDir (below) needs to be
set to the root of your Matlab installation. -->
<!-- Set CUDA architecture suitable for your GPU.
Setting proper architecture is important to mimize your run and compile time. -->
<!-- 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>
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.