caffe_vcpkg+vs2017+win7安装整理
1.前期准备
(1)python3.5->Anaconda3_64(caffe只支持python2.7和3.5):
可先查当前python版本,通过命令行键入“python –version”,即可查看当前python版本。
若是没有3.5或者2.7的话借助Anaconda3安装就好了,若是不想借助Anaconda3安装也可以去官网下载python3.5或者2.7安装包进行安装。
(2)caffe源码:https://github.com/willyd/caffe/tree/vcpkg
(3)python3.5的OpenCV-python:pip install opencv-python(在第一个条件满足的前提下安装)
2.开始安装
/一定要按照源码网址那样的安装/
(1)下载源码(windows)
打开命令行(cmd)
cd 这里输入你想要安装的位置
git clone https://github.com/BVLC/caffe.git
cd caffe
git checkout windows
等到git clone完成,进入第二步
(2)修改caffe/scripts/build_win.cmd内容
下面的语句修改,具体根据个人的需求,每一个指令的具体用处请看https://github.com/willyd/caffe/tree/vcpkg
篮字为具体修改的地方,以下为具体的修改内容
else (
:: Change the settings here to match your setup
:: Change MSVC_VERSION to 12 to use VS 2013
if NOT DEFINED MSVC_VERSION set MSVC_VERSION=15
:: Change to 1 to use Ninja generator (builds much faster)
if NOT DEFINED WITH_NINJA set WITH_NINJA=0
:: Change to 1 to build caffe without CUDA support
if NOT DEFINED CPU_ONLY set CPU_ONLY=1
:: Change to generate CUDA code for one of the following GPU architectures
:: [Fermi Kepler Maxwell Pascal All]
if NOT DEFINED CUDA_ARCH_NAME set CUDA_ARCH_NAME=Auto
:: Change to Debug to build Debug. This is only relevant for the Ninja generator the Visual Studio generator will generate both Debug and Release configs
if NOT DEFINED CMAKE_CONFIG set CMAKE_CONFIG=Release
:: Set to 1 to use NCCL
if NOT DEFINED USE_NCCL set USE_NCCL=0
:: Change to 1 to build a caffe.dll
if NOT DEFINED CMAKE_BUILD_SHARED_LIBS set CMAKE_BUILD_SHARED_LIBS=0
:: Change to 3 if using python 3.5 (only 2.7 and 3.5 are supported)
if NOT DEFINED PYTHON_VERSION set PYTHON_VERSION=3
:: Change these options for your needs.
if NOT DEFINED BUILD_PYTHON set BUILD_PYTHON=1
if NOT DEFINED BUILD_PYTHON_LAYER set BUILD_PYTHON_LAYER=1
if NOT DEFINED BUILD_MATLAB set BUILD_MATLAB=0
:: If python is on your path leave this alone
if NOT DEFINED PYTHON_EXE set PYTHON_EXE=python
:: Run the tests
if NOT DEFINED RUN_TESTS set RUN_TESTS=0
:: Run lint
if NOT DEFINED RUN_LINT set RUN_LINT=0
:: Build the install target
if NOT DEFINED RUN_INSTALL set RUN_INSTALL=1
)
:: Set the appropriate CMake generator
:: Use the exclamation mark ! below to delay the
:: expansion of CMAKE_GENERATOR
if %WITH_NINJA% EQU 0 (
if “%MSVC_VERSION%”==”15” (
set CMAKE_GENERATOR=Visual Studio 15 2017 Win64
)
if “%MSVC_VERSION%”==”14” (
set CMAKE_GENERATOR=Visual Studio 14 2015 Win64
)
if “%MSVC_VERSION%”==”12” (
set CMAKE_GENERATOR=Visual Studio 12 2013 Win64
)
if “!CMAKE_GENERATOR!”==”” (
echo ERROR: Unsupported MSVC version
exit /B 1
)
) else (
set CMAKE_GENERATOR=Ninja
)
(3)修改
caffe/cmake/WindowsDownloadPrebuiltDependencies.cmake内容
—–>WindowsDownloadPrebuiltDependencies.cmake内修改如下(除了篮字外的其他地方不用修改,加上蓝色那一句话就好了):
set(MSVC_VERSION 1900)
if(NOT DEFINED DEPENDENCIES_URL_{MSVC_VERSION}_
{MSVC_VERSION}_
{_pyver})
message(FATAL_ERROR “Could not find url for MSVC version =
MSVCVERSIONandPythonversion=
M
S
V
C
V
E
R
S
I
O
N
a
n
d
P
y
t
h
o
n
v
e
r
s
i
o
n
=
{PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}.”)
endif()
(4)命令行进入caffe/scripts文件夹,直接命令行输入build_win.cmd运行就可以了
等待编译成功,修改build_win.cmd把Debug和Realease都生成了,编译caffe.sln成功即可
(5)配置C++链接库
参考网址:根据不带源码的方式配置
https://blog.csdn.net/chris_zhangrx/article/details/79234568
(6)需要的话也可以配置一下python的
参考网址
https://blog.csdn.net/chris_zhangrx/article/details/79210288
问题解决:
(1)按照以上的每一个步骤配置完成后,测试时若是出现若出现“错误:LNK1104 libboost_date_time-vc141-mt-gd-x64-1_67.lib”则解决方法,右键属性——C/C++——代码生成——运行库,改为多线程调试 DLL (/MDd),可以运行即可
(2)若是出现
caffe/include/caffe/proto/caffe.pb.h:17:2: error: #error This file was generated by an older version of protoc which is
#error This file was generated by an older version of protoc which is
^
caffe/include/caffe/proto/caffe.pb.h:18:2: error: #error incompatible with your Protocol Buffer headers. Please
#error incompatible with your Protocol Buffer headers. Please
^
/usr/local/caffe/include/caffe/proto/caffe.pb.h:19:2: error: #error regenerate this file with a newer version of protoc.
#error regenerate this file with a newer version of protoc.
那么找到caffe.pb.h,找到以下字样
注意到有一串数字2006001,那代表的是protobuf的版本应该是2.6.1高于或者低于它都不行,若是3001000,那代表对应的protobuf版本的就是3.1版本,我的解决方法是,根据https://blog.csdn.net/qing666888/article/details/79137963安装好对应版本后,把生成的Debug文件夹内的所有lib复制黏贴到C:\Windows\System32和C:\Windows\SysWOW64下,重新运行build_win.cmd即可安装完成
成功了,鼓掌
心里话:一直想要写博客,帮帮跟我有一样的需求,但是找不到资料,又出现各种问题的各位,故小心翼翼写下这篇博客,这是我的第一篇博客,不足之处,还请各位大佬指出,若是能帮到各位,那就够了。