Windows7+visual Studio 2013+cuda7.5 Compilation Caffe

Source: Internet
Author: User
Tags theano visual studio 2010

After the guidance of friends, finally successfully compiled caffe on windows7, here will record the compilation process

Installation file preparation
Install visual studio 2013
Install cuda75
Compile caffe
1 Unzip the downloaded caffe-windows file
2 Go to the windows folder
3 Copy the configuration file and rename
4 Modify the configuration file Modify the property file of the project
5 Open the solution named Caffe
6 Compile the libcaffe project
7 Compile caffe project
8 Compile other projects
Run the first caffe test program
Configure cuDNN
Configure python
Configure matlab
1. Installation file preparation
Visual studio 2013 installation package download

Enter the visual studio download page
Select Visual Studio 2013-> Ultimate 2013 version-> Simplified Chinese iso file-> download
CUDA7.5

Cuda-toolkit-archive for nvidia official website


caffe for windows

The caffe windows version for GitHub
It must be noted that brand choose windows
Next, in order: install visual studio 2013-> install cuda 7.5-> compile caffe

2. Install visual studio 2013
See the specific installation method: Install visual studio 2013

3. Install cuda7.5
The installation method is the same as theano installation (2) Windows installation visual studio 2010 and cuda installation method in cuda, but the version number is different

Pay attention to a problem here, the cuda version before cuda6.5, the included D: \ Program Files \ NVIDIA Corporation \ CUDA samples \ v7.5 \ bin \ win64 \ Debug contains executable exe programs that can be used for testing But cuda7.5 does not, you need to compile it yourself. For the specific method of compiling cuda, please refer to related blogs

4. Compile caffe 4.1 Unzip the downloaded caffe-windows file
It is assumed here that caffe-windows is decompressed into the following folder
4.2 Go to the windows folder
4.3 Copy configuration file and rename
Make a copy of the CommonSettings.props.example file in the folder (ie. \ Windows), and name the copied file CommonSettings.props
-

4.4 Modify configuration file (modify project property file)
Caffe-windows comes with the configuration file CommonSettings.props.example. All configuration parameters are default values, for example: CUDA and cuDNN libraries are required to be used by default. cuDNN and CPU_ONLY can only be chosen one by one, Python Matlab is false by default, that is, it is not used. You can personalize the settings by modifying this property file. You mainly need to modify the following code snippet (the following code snippet is from CommonSettings.props.example, all parameters are the default values)
    <PropertyGroup Label = "UserMacros">
        <BuildDir> $ (SolutionDir) .. \ Build </ BuildDir>
        <!-NOTE: CpuOnlyBuild and UseCuDNN flags ca n‘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_35, sm_35; compute_52, sm_52 </ CudaArchitecture>

        <!-CuDNN 3 and 4 are supported->
        <CuDnnPath> </ CuDnnPath>
        <ScriptsDir> $ (SolutionDir) \ scripts </ ScriptsDir>
    </ PropertyGroup>
In the following, each parameter in the above code is explained separately:
(1) CpuOnlyBuild: whether to use CPU, the default value is False, that is, use GPU to compile; if the machine is not configured with CUDA, then this value should be assigned to True;
(2) UseCuDNN: Whether to use CuDNN, the default value is True; if the machine is not configured with CUDA, then the value should be assigned as False; Note: CpuOnlyBuild and CuDNN cannot be True
(3) CudaVersion: CUDA version
(4) PythonSupport: whether to support python, the default value is False;
(5) MatlabSupport: Whether to support matlab, the default value is False;
4.5 Open the solution named Caffe
Use VS2013 to open the solution named Caffe
4.6 Compile libcaffe project
You need to first compile the libcaffe project (other projects depend on the libcaffe project), specifically: right-click libcaffe, select generate, and start compiling libcaffe


After a period of waiting, the compilation is successful
There are two points to note here:
(1) During the compilation process, an error may occur. The cause of the error is that a warning occurred during the compilation process, which caused the compilation to fail. At this time, the following modifications are required:

That is: set project properties, don't treat warnings as errors
Right-click-> Project Properties-> C / C ++-> General-> Treat warning as error Set to No

(2) In the process of caffe compilation, some dependency packages are required. In the case of a network, when the first project libcaffe is compiled, the program will automatically download these dependency packages from the Internet to the same level as the caffe-windows folder In the NugetPackages folder, the dependent packages automatically downloaded by the program are shown

However, in the absence of a network, you need to download these dependent packages in advance, and set their path in the NuGet package of vs management: Tools-> Options-> NuGet Package Manager-> Package Source-> Use Right The plus sign on the side adds the local package

After manually adding these package addresses, you also need to manually install these NuGet Packages

4.7 Compile caffe project
Similarly, right click on the caffe project to generate

4.8 Compile other projects
After compiling libcaffe and caffe two projects, and then compile other projects in turn, the same method

5. Run the first caffe test program
In order to test whether the compiled caffe can be used normally, it needs to be tested, mainly using the mnist data set to test the classification problem

(1) Download the test data set
(2) Modify the configuration file
Enter the folder D: \ software \ caffe-vs \ caffe-windows \ examples \ mnist, which is the mnist folder under the examples path

① Open leant_solver.prototxt
Set the network configuration file path, here uses the absolute path, the relative path has not been tried

② Open leant_train_test.prototxt

(3) Run the caffe program, specifically
① Open the cmd command line, cd to caffe-windows. \ Build \ x64 \ Debug path, under this path, you can directly execute caffe.exe
D: \ software \ caffe-vs \ caffe-windows \ Build \ x64 \ Debug

Or, for convenience, you can add the caffe path to the environment variable Path, so that cmd can directly identify the caffe command
② Run caffe

caffe train -solver lenet_solver.prototxt
Note that because the D: \ software \ caffe-vs \ caffe-windows \ Build \ x64 \ Debug path has been added to the environment variable PATH in the previous step, you can use caffe.exe directly here

The following two steps mainly configure cuDnn, python and matlab, the specific configuration should be carried out before 4.5

6. Configure cuDNN
Download cuDNN v3 or cuDNN v4 from the nVidia official website, please note that you need to register to download
Unzip after downloading as shown
There are two options for configuring the path of cuDNN:

Option 1: Place the files in the bin, include, and lib of the cuDNN v4 compressed package in the corresponding directory of% CUDA_PATH% (that is, the installation path of cuda)
Option 2: Set the CuDnnPath in the. \ Windows \ CommonSettings.props file to the decompression path. For example, place the cuDNN decompressed file in D: \ software \ caffe-vs \ cuda-cuDNN. Then, in CommonSettings. In props, make <CuDnnPath> D: \ software \ caffe-vs \ cuda-cuDNN \ </ CuDnnPath>
And, let the UseCuDNN in the CommonSettings.props file be as follows: <UseCuDNN> ture </ UseCuDNN>

7. Configure python
Python has been installed before, for the specific method, refer to theano installation (1) Windows configuration and installation of theano environment (non-GPU version)
Note: It was installed with the help of AnaConda

Use the pip tool to install protobuf: pip install protobuf
Make two changes in the file:
(1) <PythonSupport> true </ PythonSupport>
(2) Change PythonDir to the installation directory of python. The python here is installed using Anaconda. The installation path is located at D: \ File Program \ Anaconda \.
    <PropertyGroup Condition = "‘ $ (PythonSupport) ’==‘ true ’">
        <PythonDir> D: \ File Program \ Anaconda \ </ PythonDir>
        <LibraryPath> $ (PythonDir) \ libs; $ (LibraryPath) </ LibraryPath>
        <IncludePath> $ (PythonDir) \ include; $ (IncludePath) </ IncludePath>
    </ PropertyGroup>
Add environment variables
In the user variables of the environment variables, create a new user variable, the variable name "PythonPath ", variable value" D: \ software \ caffe-vs \ caffe-windows \ Build \ x64 \ Release \ pycaffe "
Or copy the folder \ Build \ x64 \ Release \ pycaffe \ caffe to \ lib \ site-packages.
8. Configure matlab
This mainly involves modifying two places in the CommonSettings.props file

Modify the CommonSettings.props file, so that <MatlabSupport> true </ MatlabSupport>
Modify the parameters in the CommonSettings.props file to make it the local Matlab installation directory
   <PropertyGroup Condition = "‘ $ (MatlabSupport) ‘==‘ true ‘">
        <MatlabDir> D: \ File Program \ Matlab \ </ MatlabDir>
        <LibraryPath> $ (MatlabDir) \ extern \ lib \ win64 \ microsoft; $ (LibraryPath) </ LibraryPath>
        <IncludePath> $ (MatlabDir) \ extern \ include; $ (IncludePath) </ IncludePath>
    </ PropertyGroup>
Add environment variables
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.
Note: I found a better blog
http://m.blog.csdn.net/article/details?id=50819464

windows7 + visual studio 2013 + CUDA7.5 compile caffe

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.