安装Windows10 和环境下的caffe(新版)

16 篇文章 0 订阅
10 篇文章 0 订阅

安装Windows10 和环境下的caffe(新版)

我的运行环境 VS2015, Anaconda3( python 3.5 目前caffe只到python3.5), Matlab201X, CMake 3.8

Requirements

参考:https://github.com/BVLC/caffe/tree/windows

Visual Studio 2013 or 2015
CMake 3.4 or higher (Visual Studio and Ninja generators are supported)
CMake: https://cmake.org/
Ninja: https://ninja-build.org/
安装参考:
如果用VS编译,而不是Ninja,可以不用安装,VS编译看下面

windows 安装ninja
http://blog.csdn.net/darren2015zdc/article/details/74504917
caffe安装依赖库的下载路径
https://github.com/willyd/caffe-builder/releases
根据自己的 VS, python 环境 选择下载

安装caffe的依赖库

1. 下载caffe

git clone https://github.com/BVLC/caffe.git
cd caffe
git checkout windows
#下面命令暂不执行
#scripts\build_win.cmd

2. 修改build_win.cmd

打开 caffe\scripts\build_win.cmd
可以看到
为了在python中使用

#:: Check that we have the right python version
!PYTHON_EXE! --version
#:: Add the required channels
conda config --add channels conda-forge
conda config --add channels willyd
#:: Update conda
conda update conda -y
#:: Download other required packages
conda install --yes cmake ninja numpy scipy protobuf==3.1.0 six scikit-image pyyaml pydotplus graphviz

在 else做修改

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=14
    :: Change to 1 to use Ninja generator (builds much faster)
    #使用NINJA编译 WITH_NINJA=1 
    if NOT DEFINED WITH_NINJA set WITH_NINJA=1  
    :: Change to 1 to build caffe without CUDA support
    #使用gpu,设置CPU_ONLY=0
    if NOT DEFINED CPU_ONLY set CPU_ONLY=0
    :: 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
    # 我的是单GPU没有设置这里。 多GPU需要设置
    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)
    #我的是python3.5所以PYTHON_VERSION=3
    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
    #使用matcaffe  matlab 所以 BUILD_MATLAB=1
    if NOT DEFINED BUILD_MATLAB set BUILD_MATLAB=1
    :: 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=0
)

然后caffe下运行: scripts\build_win.cmd

安装caffe

运行:scripts\build_win.cmd
下载经常失败。直接从 https://github.com/willyd/caffe-builder/releases 下次,支持的包
下载 失败
caffe 生成的build, zdc.caffe\ dependencies\download\
的需要删除。 下载好的依赖包, 就放在.caffe\ dependencies\download\ 下。

C:\Users\zdc\.caffe\dependencies\download\libraries_v140_x64_py35_1.1.0.tar.bz2

将caffe 生成的build清理一下, 重新运行 scripts\build_win.cmd

INFO: ============================================================
INFO: Summary:
INFO: ============================================================
INFO: MSVC_VERSION               = 14
INFO: WITH_NINJA                 = 1
INFO: CMAKE_GENERATOR            = "Ninja"
INFO: CPU_ONLY                   = 0
INFO: CUDA_ARCH_NAME             = Auto
INFO: CMAKE_CONFIG               = Release
INFO: USE_NCCL                   = 0
INFO: CMAKE_BUILD_SHARED_LIBS    = 0
INFO: PYTHON_VERSION             = 3
INFO: BUILD_PYTHON               = 1
INFO: BUILD_PYTHON_LAYER         = 1
INFO: BUILD_MATLAB               = 1
INFO: PYTHON_EXE                 = "python"
INFO: RUN_TESTS                  = 0
INFO: RUN_LINT                   = 0
INFO: RUN_INSTALL                = 0
INFO: ============================================================
-- The C compiler identification is MSVC 19.0.24215.1
-- The CXX compiler identification is MSVC 19.0.24215.1
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/amd64/cl.exe
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/amd64/cl.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/amd64/cl.exe
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/amd64/cl.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found PythonInterp: C:/Users/zdc/Anaconda3/python.exe (found suitable version "3.5.2", minimum required is "2.7")
-- Extracting dependencies
-- Looking for pthread.h
-- Looking for pthread.h - not found
-- Found Threads: TRUE
-- Boost version: 1.61.0
-- Found the following Boost libraries:
--   system
--   thread
--   filesystem
--   chrono
--   date_time
--   atomic
-- Found GFlags: C:/Users/zdc/.caffe/dependencies/libraries_v140_x64_py35_1.1.0/libraries/include
-- Found gflags  (include: C:/Users/zdc/.caffe/dependencies/libraries_v140_x64_py35_1.1.0/libraries/include, library: gflags_shared)
-- Found Glog: C:/Users/zdc/.caffe/dependencies/libraries_v140_x64_py35_1.1.0/libraries/include
-- Found glog    (include: C:/Users/zdc/.caffe/dependencies/libraries_v140_x64_py35_1.1.0/libraries/include, library: glog)

VS编译安装caffe

scripts\build_win.cmd 中的 设置WITH_NINJA

 if NOT DEFINED WITH_NINJA set WITH_NINJA=0 

Python的测试

切换到 C:\Users\zdc\caffe\python 路径:

C:\Users\zdc\caffe>cd python

C:\Users\zdc\caffe\python>python
Python 3.5.2 |Anaconda custom (64-bit)| (default, Jul  5 2016, 11:41:13) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import caffe
>>> quit()

Matlab的 测试

打开Matlab 切换到 C:\Users\zdc\caffe\matlab 路径。
输入以下命令: caffe.run_tests()

>> caffe.run_tests()
Cleared 0 solvers and 0 stand-alone nets
正在运行 caffe.test.test_net
.....
已完成 caffe.test.test_net
__________

警告: 执行 'caffe.Solver' 类析构函数时,捕获到以下错误:
错误使用 caffe_
Usage: caffe_('delete_solver', hSolver)

出错 caffe.Solver/delete (line 40)
      caffe_('delete_solver', self.hSolver_self);

出错 caffe.Solver (line 21)
        self = caffe.get_solver(varargin{:});

出错 caffe.test.test_solver (line 22)
      self.solver = caffe.Solver(solver_file);

出错 caffe.run_tests (line 14)
  run(caffe.test.test_solver) ... 
> In caffe.Solver (line 21)
  In caffe.test.test_solver (line 22)
  In caffe.run_tests (line 14) 
正在运行 caffe.test.test_solver
.
已完成 caffe.test.test_solver
__________

正在运行 caffe.test.test_io
.
已完成 caffe.test.test_io
__________

Cleared 0 solvers and 0 stand-alone nets

ans = 

  1×7TestResult 数组(具有属性):

    Name
    Passed
    Failed
    Incomplete
    Duration
    Details

总计:
   7 Passed, 0 Failed, 0 Incomplete.
   0.76046 秒测试时间。

表明测试成功

VS编译的会出现以下问题:

未定义函数或变量 'caffe_'。 或者  'caffe_' not found

caffe_.mexw64 出现在 \caffe\matlab+caffe\private\Release或者
\caffe\matlab+caffe\private\Debug中。
Ninja编译的 caffe_.mexw64 直接出现在 \caffe\matlab+caffe\private\ 中。
比较省事的方法:我直接 将\caffe\matlab+caffe\private\Release中的 caffe_.mexw64 拷贝到 \caffe\matlab+caffe\private\ 中,就可以了

参考:

旧的版本安装参考:
http://blog.csdn.net/qq_14845119/article/details/52415090
Windows下caffe安装详解(cpu+gpu+matcaffe+pycaffe)
新的版本安装参考:
http://blog.csdn.net/thomaszhaoyc/article/details/68489299
winsows10下用ninja编译配置caffe

Windows下VS2015编译caffe(CPU ONLY)
http://blog.csdn.net/light169/article/details/53993893

在MATLAB下调试Caffe
http://blog.csdn.net/kkk584520/article/details/49475633

matlab + mnist 调用训练好的caffe模型进行手写体识别
http://blog.csdn.net/a571255945/article/details/51694782

【caffe-Windows】微软官方caffe之 matlab接口配置
http://m.blog.csdn.net/zb1165048017/article/details/51702686

  • 0
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值