首页 > Windows开发 > 详细

Caffe中master与windows分支差异对比及通过命令提示符编译Caffe源码操作步骤

时间:2017-04-07 13:46:08      阅读:1015      评论:0      收藏:0      [点我收藏+]

目前GitHub https://github.com/fengbingchun/Caffe_Test   中的caffe还是依赖较老的版本,更新于2015.08.15,commit为09868ac,近期想更新到最新版本,在https://github.com/BVLC/caffe 中,有master分支和windows分支,为便于后面更新,这里先对比下master分支(2017.03.31, commit: c0597b1)和windows分支(2017.03.29,commit: 88ddc95)中include目录和src目录的主要差异:

一、include目录:

1.  caffe/test/test_caffe_main.hpp:

(1)、在windows分支中多包含了一个头文件<caffe/util/io.hpp>;

(2)、在windows分支中类MultiDeviceTest的析构函数调用了RemoveCaffeTempDir()函数用于清除一些创建的临时目录。

2.  caffe/util/cudnn.hpp:

(1)、在windows分支中取消对cudnnGetErrorString函数的定义;

(2)、在windows分支中对setConvolutionDesc函数,取消对宏CUDNN_VERSION_MIN的支持。

3.  caffe/util/io.hpp:

(1)、在windows分支中,在MakeTempDir函数中调用了boost::filesystem::create_directory函数用于创建临时目录;

(2)、在windows分支中,增加了RemoveCaffeTempDir函数的实现。

4.  caffe/common.hpp:

(1)、在windows分支中,如果定义了宏CMAKE_WINDOWS_BUILD,则包含”caffe/export.hpp”.

5.  caffe/layer_factory.hpp:

(1)、在windows分支中,将类LayerRegistry和类LayerRegisterer的实现体挪到了src/caffe/layer_factory.cpp文件中。

6.  caffe/solver_factory.hpp:

(1)、在windows分支中,将类SolverRegistry和类SolverRegisterer的实现体挪到了src/caffe/solver_factory.cpp文件中。

二、src目录:

1.  caffe/layers/bnll_layer.cu:

(1)、在windows分支中,将常量kBNLL_THRESHOLD由const floatkBNLL_THRESHOLD = 50.; 调整为__constant__ float kBNLL_THRESHOLD = 50.;

2.  caffe/test/test_benchmark.cpp:

(1)、在windows分支中,将常量kMillisecondsThreshold值由30调整为50。

3.  caffe/test/test_blob.cpp:

(1)、在windows分支中,在GPU mode下,取消对TYPED_TEST(BlobSimpleTest,TestPointersCPUGPU)的调用。

4.  caffe/test/test_gradient_based_solver.cpp:

(1)、在windows分支中,类GradientBasedSolverTest中RunLeastSquaresSolver函数增加std::replace函数将”\\”替换为”/”;

(2)、在windows分支中,类GradientBasedSolverTest中TestSnapshot函数内对调用caffe::Blob的CopyFrom函数的参数调整。

5.  caffe/test_lrn_layer.cpp:

(1)、在windows分支中,将模板类CuDNNLRNLayerTest的类型名由TypeParam调整为Dtype。

6.  caffe/util/db_lmdb.cpp:

(1)、在windows分支中,增加包含<direct.h>和#define mkdir(X,Y) _mkdir(X)

7.  caffe/util/io.cpp:

(1)、在windows分支中,增加包含<io.h>;

(2)、在windows分支中,对ReadProtoFromBinaryFile函数中的open函数由open(filename,O_RDONLY)调整为open(filename, O_RDONLY | O_BINARY)。

8.  caffe/util/signal_handler.cpp:

(1)、在windows分支中,将与SIGHUP相关的操作用SIGBREAK替换。

9.  caffe/common.cpp:

(1)、在windows分支中,增加包括<process.h>和#define getpid()_getpid()

(2)、在window分支中,在GlobalInit函数中取消对::google::InstallFailureSignalHandler函数的调用。

10.             caffe/layer_factory.cpp:

(1)、在windows分支中,增加包含<vector>;

(2)、在windows分支中,存放类LayerRegistry和类LayerRegisterer的实现体。

11.             caffe/solver_factory.cpp:

(1)、仅在windows分支中有的文件,存放类SolverRegistry和类SolverRegisterer的实现体。

由上面include和src比对得知,两个分支在C++的实现上差异不大。

三、cmake文件的差异:

两个分支上cmake文件差异较大。

四、在windows10 vs2013通过命令提示符编译caffe windows分支操作步骤:

1.        从https://github.com/BVLC/caffe/tree/windows clone caffe源码,clone到D:/DownLoad/caffe并切换到windows分支;

2.      参考README.md中的说明;

3.      打开命令提示符,将其定位到D:/DownLoad/caffe/scripts;

4.      调整build_win.cmd文件,调整后的build_win.cmd文件内容如下(仅包含调整的部分):

@echo off
@setlocal EnableDelayedExpansion

:: Default values
if DEFINED APPVEYOR (
    echo Setting Appveyor defaults
    if NOT DEFINED MSVC_VERSION set MSVC_VERSION=12
    if NOT DEFINED WITH_NINJA set WITH_NINJA=0
    if NOT DEFINED CPU_ONLY set CPU_ONLY=1
    if NOT DEFINED CMAKE_CONFIG set CMAKE_CONFIG=Release
    if NOT DEFINED USE_NCCL set USE_NCCL=0
    if NOT DEFINED CMAKE_BUILD_SHARED_LIBS set CMAKE_BUILD_SHARED_LIBS=0
    if NOT DEFINED PYTHON_VERSION set PYTHON_VERSION=0
    if NOT DEFINED BUILD_PYTHON set BUILD_PYTHON=0
    if NOT DEFINED BUILD_PYTHON_LAYER set BUILD_PYTHON_LAYER=0
    if NOT DEFINED BUILD_MATLAB set BUILD_MATLAB=0
    if NOT DEFINED PYTHON_EXE set PYTHON_EXE=python
    if NOT DEFINED RUN_TESTS set RUN_TESTS=0
    if NOT DEFINED RUN_LINT set RUN_LINT=0
    if NOT DEFINED RUN_INSTALL set RUN_INSTALL=0

    :: Set python 2.7 with conda as the default python
    if !PYTHON_VERSION! EQU 2 (
        set CONDA_ROOT=C:\Miniconda-x64
    )
    :: Set python 3.5 with conda as the default python
    if !PYTHON_VERSION! EQU 3 (
        set CONDA_ROOT=C:\Miniconda35-x64
    )
    set PATH=!CONDA_ROOT!;!CONDA_ROOT!\Scripts;!CONDA_ROOT!\Library\bin;!PATH!

    :: 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

    if ERRORLEVEL 1  (
      echo ERROR: Conda update or install failed
      exit /b 1
    )

    :: Install cuda and disable tests if needed
    if !WITH_CUDA! == 1 (
        call %~dp0\appveyor\appveyor_install_cuda.cmd
        set CPU_ONLY=0
        set RUN_TESTS=0
        set USE_NCCL=1
    ) else (
        set CPU_ONLY=1
    )

    :: Disable the tests in debug config
    if "%CMAKE_CONFIG%" == "Debug" (
        echo Disabling tests on appveyor with config == %CMAKE_CONFIG%
        set RUN_TESTS=0
    )

    :: Disable linting with python 3 until we find why the script fails
    if !PYTHON_VERSION! EQU 3 (
        set RUN_LINT=0
    )

) 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=12
    :: 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 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=2
    :: Change these options for your needs.
    if NOT DEFINED BUILD_PYTHON set BUILD_PYTHON=0
    if NOT DEFINED BUILD_PYTHON_LAYER set BUILD_PYTHON_LAYER=0
    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=0
)
(1)、调整包括仅编译CPU、vs12、不使用NinJa;

(2)、依赖库会默认下载到C:/Users/spring/.caffe目录下,大约1.07GB;

(3)、如有错误提示,修改cmake/WindowsDownloadPrebuiltDependencies.cmake中DEPENDENCIES_SHA_1800_27值;

执行完此命令后结果如下图所示:

技术分享

5.        执行build_win.cmd会在caffe/scripts/build目录下生成Caffe工程Caffe.sln,结果如下图所示:

技术分享

五、接下来仿照生成的Caffe.sln,将https://github.com/fengbingchun/Caffe_Test中的Caffe升级到最新。

GitHubhttps://github.com/fengbingchun/Caffe_Test

Caffe中master与windows分支差异对比及通过命令提示符编译Caffe源码操作步骤

原文:http://blog.csdn.net/fengbingchun/article/details/69499356

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!