VS2015 compilation Caffe2 (currently compiled CPU+GPU+PYTHON+OPENCV)

Source: Internet
Author: User
Tags git clone

Official compilation reference: Https://caffe2.ai/docs/getting-started.html?platform=windows&configuration=compile

Official installation guidance is not comprehensive, leaving a lot of pits, do not fill the pit will lead to the failure of the compiler, the main purpose of this article is landfills, the official document said the content is no longer detailed introduction.


First, download the source code

git clone--recursive https://github.com/caffe2/caffe2.git

This step does not need to be explained

Second, configure Cuda, Python, CMake and other third-party software

Cuda is not required, you can compile only the CPU version;

Python I installed the Anaconda 2.7, according to the official document installation of a variety of Python packages, the specific installation of modules please refer to the official documentation;

CMake must be installed, go to the official website download installation package can;

Third, modify the Caffe2 script:

Here is the key, the next start landfills. I am the December 1, 2017 download of the Caffe2 source code, when you see this article, it is possible that these pits have been officially updated to fill out, but also may be the official dug up a new pit.

1. Modify "(source root directory) \scripts\build_host_cmd.bat"

I compile with VS2015 64bit, so I need to modify the CMake variable associated with the compilation option, if you use vs2017 compilation, you do not need to modify this option. Add a statement at the beginning of the @echo off line: Set cmake_generator= "Visual Studio 2015 Win64"

2. Modify "(source root directory) \scripts\build_windows.bat"

Like two or 1, I compile with VS2015 64bit, so I need to modify the CMake variables associated with the compilation option, if you use vs2017 compilation, you do not need to modify this option. Add a statement at the beginning of the @echo off line: Set cmake_generator= "Visual Studio 2015 Win64"

The script also has a number of switch variables that control whether to compile the Python interface, use Cuda, and so on, and modify them as needed. It is recommended that you compile with the default settings, and then revise the variables to compile them before they are successful, so that the reason is not easy to locate when the error occurs.

3. Modify "(source root directory) \caffe2\cmake\proto_buf.cmake"

Locate the following code snippet:

if (WIN32)

Find_package (Protobuf no_module)

ElseIf (ANDROID OR IOS)

......

This code causes the compiler to not find the Protobuf module, causing the compilation to fail. As you can see in the following illustration, you will comment out the IF section and modify the ElseIf to If.

4. If you change the Build_python variable to on in the Build_windows.bat described in two, 2, that is, the compilation option for the Python interface is turned on, you also need to modify "(source root) \caffe2\cmake\ Dependencies.cmake ". This step can be ignored if the Python interface is not compiled.

In the following line, add the following statement to the IF (Pythoninterp_found and Pythonlibs_found and Numpy_found):

List (APPEND caffe2_python_dependency_libs ${python_libraries})

The purpose of this sentence is to add the Python27.lib (the anaconda that I installed is the python2.7 version) to the link option. If you do not add this sentence, there will be an error at compile time that cannot link python27.lib. Do not know whether the author has compiled his own works under Windows, it seems that there should be no.

5. Add Cuda and OPENCV support, in Build_windows.bat, set Use_cuda and Build_opencv to ON, then ... And then...... Then you have to change a lot of things, not a word can be said two words clear, very sour ... Want to open Cuda and OpenCV, or wait for the author to update the code, I will not repeat.

To say a word, vs2017 compiled with Cuda version unsuccessful, halfway reported a baffling error, so far do not know what the meaning.

Four, compile

Enter the command line with the Python path setting, Anaconda start the Anaconda prompt, switch the path to the source root directory, go to the Scripts folder, run the Build_windows.bat script, and wait for the compilation to complete. After a long wait, if your character is good enough, you should be able to see the success of the compilation of hints. You can use the vs2015 open (source root)/build under the VS solution, compile debug and other configuration scenarios, or track debugging, or add new engineering development programs.


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.