windows+caffe+vs2013+cuda6.5 Configuration Records

Source: Internet
Author: User

After half a year, because of the needs of the paper, and re-start research Caffe. Thanks to the contribution of Niuzhiheng's GitHub great God, Caffe is already available under Windows. Reference to a lot of great God's blog, successfully configured in their own notebook Windows version of the Caffe. Now the configuration process and the configuration of the problems encountered in the record, I hope to be helpful to everyone.

1. Configuring the Environment

I configured the Caffe in my own notebook, configuring the Environment for: Windows 7 64-bit + cuda6.5 + Opencv2.49 + VS2013. Let's say you're ready for this before you configure Caffe.

This article will give some compiled dependent libraries, if you are also using the Windows 7 64-bit +vs2013, can be used directly.

2. Prepare a dependent library

One of the main problems with configuring Caffe under Windows is that it relies on library compilation. Unlike under Ubuntu, the dependent libraries need to be compiled with vs2013 for use under Windows. Below I will describe the dependent libraries required by Caffe (if you are also win7 64-bit +vs2013, you can use the dependent libraries I provide directly).

2.1 Boost

Boost can download the source code for compiling, or you can download the installation files directly. I use the latter, convenient and fast.

I am using: boost_1.56_0-msvc-12.0-64.exe

:http://sourceforge.net/projects/boost/files/boost-binaries/1.56.0/

Note Download the boost version for your configuration environment.

After the download, double-click to run the installation file.

2.2 Glog+gflag+protobuf+leveldb+hdf5+lmdb+openblas

Many of these are Google's Open source libraries, which are not easy to download (you know). So I'm using Neil Z. SHAO ' s Blog

Provided by the compiled well. Because the big God gave the address is Google Network disk, not easy to download. I will transfer it to Baidu Plate.

:Http://pan.baidu.com/s/1mg1iJrE

After downloading, unzip to get 3rdparty folder. It will be used in the next paragraph.

3. Establishment of Caffe Project

After you have prepared the dependent libraries and environments that Caffe needs, you can build the Caffe vs project and compile it.

3.1 Download Caffe source code

You can download the source code from Caffe's GitHub homepage.

:Caffe ' s GitHub

Unzip the file, assuming that the Caffe source directory is caffe_root.

3.2 Dependent library and system environment variables required for preparing the project

After a previous phase of preparation, the dependent libraries required for the Caffe project are ready.

1. First set the system environment variables (in my case):

cuda_path_v6_5 The environment variable is added automatically after the cuda6.5 is installed Cuda_path_v6_5

opencv_2_49 d:/tools/opencv2.49/build/

boost_1_56 D:/tools/boost_1_56_0

2. Place the 3rdparty folder in the Caffe_root

3.3 Creating Caffe projects with VS

1. Use VS2013 to set up Win32 Console Application under Caffe_root and select an empty project.

Change the platform of the project from 32 bits to 64-bit

2. Modify Project Properties

Project--Property--c/c++--general--Additional Include directories

Add to:

.. /include;

.. /SRC;

.. /3rdparty/include;

.. /3rdparty;

.. /3rdparty/include;

.. /3rdparty/include/openblas;

.. /3rdparty/include/hdf5;

.. /3rdparty/include/lmdb;

.. /3RDPARTY/INCLUDE/LEVELDB;

.. /3rdparty/include/gflag;

.. /3rdparty/include/glog;

.. /3rdparty/include/google/protobuf;

Project--Zodiac--vc++ directory--Include directory

Add to:

$ (cuda_path_v6_5) \include;

$ (opencv_2_49) \include;

$ (opencv_2_49) \include\opencv;

$ (opencv_2_49) \include\opencv2;

$ (boost_1_56)

Project--Properties--linker--general--Additional library directory

Add to:

$ (cuda_path_v6_5) \lib\$ (platformname);

$ (opencv_2_49) \x64\vc12\lib;

$ (boost_1_56) \lib64-msvc-12.0;

.. \3rdparty\lib;

Project--Properties--linker--input--Additional dependencies

Debug Add:

Opencv_ml249d.lib
Opencv_calib3d249d.lib
Opencv_contrib249d.lib
Opencv_core249d.lib
Opencv_features2d249d.lib
Opencv_flann249d.lib
Opencv_gpu249d.lib
Opencv_highgui249d.lib
Opencv_imgproc249d.lib
Opencv_legacy249d.lib
Opencv_objdetect249d.lib
Opencv_ts249d.lib
Opencv_video249d.lib
Opencv_nonfree249d.lib
Opencv_ocl249d.lib
Opencv_photo249d.lib
Opencv_stitching249d.lib
Opencv_superres249d.lib
Opencv_videostab249d.lib
Cudart.lib
Cuda.lib
Nppi.lib
Cufft.lib
Cublas.lib
Curand.lib
Gflagsd.lib
Libglog.lib
Libopenblas.dll.a
Libprotobufd.lib
Libprotoc.lib
Leveldbd.lib
Lmdbd.lib
Libhdf5_d.lib
Libhdf5_hl_d.lib
Shlwapi.lib
Gflags.lib
Libprotobuf.lib
Leveldb.lib
Lmdb.lib
Libhdf5.lib
Libhdf5_hl.lib

Release add:

Opencv_ml249.lib
Opencv_calib3d249.lib
Opencv_contrib249.lib
Opencv_core249.lib
Opencv_features2d249.lib
Opencv_flann249.lib
Opencv_gpu249.lib
Opencv_highgui249.lib
Opencv_imgproc249.lib
Opencv_legacy249.lib
Opencv_objdetect249.lib
Opencv_ts249.lib
Opencv_video249.lib
Opencv_nonfree249.lib
Opencv_ocl249.lib
Opencv_photo249.lib
Opencv_stitching249.lib
Opencv_superres249.lib
Opencv_videostab249.lib
Cudart.lib
Cuda.lib
Nppi.lib
Cufft.lib
Cublas.lib
Curand.lib
Gflags.lib
Libglog.lib
Libopenblas.dll.a
Libprotobuf.lib
Libprotoc.lib
Leveldb.lib
Lmdb.lib
Libhdf5.lib
Libhdf5_hl.lib
Shlwapi.lib

3.4 Compiling Caffe

Once you have configured the properties of the Caffe project, you can compile the Caffe step-by-step.

3.4.1 compiling files in the./src

First, put the. The *.cpp file in the/src folder is added to the project.

Compile each of the *.cpp files in turn.

1. Compiling blob.cpp

Direct compile error, missing file "Caffe\proto\caffe.pb.h"

This time we need to put the proto.exe. /3rdparty/bin folder

Put Gernaratepb.bat on the. /scripts folder

:http://pan.baidu.com/s/1pJ7Onph

Run the bat script file to generate Caffe.pb.h

You can then compile it successfully.

2. Compiling common.cpp

To compile this file directly, there will be errors about GetID and fopen_s . The following steps can be modified:

Add in front of code : #include <process.h>

Modify Project Properties: Project--Properties--c/c++--preprocessor--Preprocessor definitions

Added :_crt_secure_no_warnings

Make the following changes to the location of the GetID in your code:

#ifdef _msc_ver

PID = GetID ();

#else

PID = _getid ();

#endf

After the modifications are complete, the compilation can be successful.

3. Compiling net.cpp

To compile this file directly, there will be errors about Mkstep, close, Mkdtemp . The following modifications are required:

In the IO.HPP header file, add : #include "mkstep.h"

In the IO.HPP header file, make the following modifications in the location of Close ():

#ifdef _msc_ver

Close (FD);

#else

_close (FD);

#endif

Make the following changes in the Mkdtemp location:

#ifndef _msc_ver

char* Mkdtemp_result = mkdtemp (TEMP_DIRNAME_CSTR);

#else

errno_t Mkdtemp_result = _mktemp_s (temp_dirname_cstr, sizeof (TEMP_DIRNAME_CSTR));

#endif

The modification is complete and can be compiled successfully.

4. Compiling solver.cpp

Direct compilation will cause errors on snprintf, which need to be modified as follows:

#ifdef _msc_ver

#define Snprinf sprintf_s

#endif

The modification is complete and can be compiled successfully.

5. Other remaining CPP files are compiled in turn

3.4.2 compiling files in the./src/layers

Add all the CPP and CU files in the./src/layers to the project.

Right click on the CU file and modify the properties.

In the Bnll_layer.cu file, make the following modifications:

float kbnll_threshold = 50--> #define Kbnll_threshold 50.0

Compile all the files in turn.

3.4.3 compiling files in the./src/util

Add all the files in the./src/util to the project

1. In the Io.cpp

Modifying the readprotofrombinaryfile function

O_rdonly--> O_rdonly | O_binary

Make the following modifications in your code:

#ifdef _msc_ver

#define OPEN _open

#endif

Change Close () to _close ()

2. In the Math_functions.cpp

Make the following changes:

#define __builtin_popcount __popcnt

#define __BUILTIN_POPCOUNTL __popcnt

3. In the Db.cpp

Make the following changes:

#ifdef _msc_ver

#include <direct.h>

#endif

Modify Check_eq

#ifdef _msc_ver

Check_eq (_mkdir (Source.c_str ()), 0) << "mkdir" <<source<< "failed";

#else

Check_eq (mkdir (Source.c_str (), 0744), 0) << "Mkidr" <<source<< "failed";

#endif

4. Compile other files in sequence

3.4.4 compiling files in the./src/proto

Refer to the previous step to add the files in the proto to the project.

To modify a property:

Project--Attribute--c/c++--preprocessor--preprocessor definition

Added:_scl_secure_no_warnings

compiles all files.

3.4.5 compiling files in the./tools

There are several CPP files under this folder, which can be used to know the function by their name. Add different CPP files to the project, and then build the project, you can get different functions of the EXE file.

Add Caffe.cpp to project, build project, get Caffe.exe file, can be used to train model

Add Computer_image_mean.cpp to project, build project, and the resulting EXE file can be used to convert training samples to Leveldb/lmdb datasets used by Caffe.

In turn.

Since then, the compilation of Caffe under Windows is complete, and you can then use it to train your model.

Finally, this paper mainly refer to Neil Z. SHAO's Blog, thanks to bloggers for their contributions.

windows+caffe+vs2013+cuda6.5 Configuration Records

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.