64位Win7SP1+VS2015Update3编译Tensorflow1.10

准备

  1. 64位 Windows 7 SP1;
  2. Visual Studio 2015 Community Update 3
  3. MSBuildTool 2015 Update 3(在 https://github.com/microsoft/msbuild/releases 里面找吧)
  4. Anaconda 5.2.0 x64
  5. CMake 3.14.1(最新版就行)
  6. swig 3.0.12(下载解压后目录加到系统环境变量PATH中)
  7. Git 2.20.1.windows.1(最新版就行)
  8. git clone https://github.com/llvm-mirror/compiler-rt.git (需要里面的lib/fuzzer)
  9. 通过网页 https://github.com/tensorflow/tensorflow/tags?after=v1.10.1 下载 tensorflow-1.10.0.zip。下载好之后解压,我图简单就解压到D:\下面了。
  10. 硬盘空间得有一些(我是128GB的SSD,分出来不到30GB给D盘,乱七八糟的加一起真没有剩下空间…)

改CMake配置文件

  1. D:\tensorflow-1.10.0\tensorflow\contrib\cmakeCMakeList.txt:第47行
option(tensorflow_WIN_CPU_SIMD_OPTIONS "Enables CPU SIMD instructions" OFF)

“OFF"改成”/arch:AVX"。其他选项也可以在这里改,在CMake-GUI里面改也一样。
2. D:\tf\tensorflow-1.10.0\tensorflow\contrib\cmake\external\protobuf.cmake:第19行

set(PROTOBUF_TAG v3.6.0)

“v3.6.0"改成"v3.6.1”。

运行CMake-GUI进行Configure和Generate

  1. 打开CMake-GUI。
  2. 设置“Where is the source code”为“D:/tensorflow-1.10.0/tensorflow/contrib/cmake”。
  3. 在“D:/tensorflow-1.10.0/tensorflow/contrib/cmake”目录中新建“build”子目录。
  4. 设置“Where to build the binaries”为“D:/tensorflow-1.10.0/tensorflow/contrib/cmake/build”。
  5. 点击“Configure”,选择“Visual Studio 14 2015”和“x64”,点“确定”继续。
  6. 勾选图中的选项:
    在这里插入图片描述
    再点“Configure”,出现“Configure done!”后再点“Generate”,直到出现“Generate done!”。

生成grpc

  1. 打开命令行cmd。
  2. 运行 “C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat” x64,注意双引号要保留。如果VS2015安装在别的位置,改一下路径。
  3. 运行以下命令
d:
cd tensorflow-1.10.0
cd tensorflow
cd contrib
cd cmake
cd build
msbuild /p:Configure=Release grpc.vcxproj
  1. 因为网速的问题,运行时间比较长。不出意外的话会报错,说thirdparty/bloaty中的submodule libFuzzer尝试git clone三次都没成功,但是其他配置都设置好了。
  2. 修改“D:\tf\tensorflow-1.10.0\tensorflow\contrib\cmake\build2\grpc\tmp\grpc-gitclone.cmake”文件,注释第16行至第94行,记得保存!保存!保存!
# execute_process(
  # COMMAND ${CMAKE_COMMAND} -E remove_directory "D:/tf/tensorflow-1.10.0/tensorflow/contrib/cmake/build2/grpc/src/grpc"
  # RESULT_VARIABLE error_code
  # )
# if(error_code)
  # message(FATAL_ERROR "Failed to remove directory: 'D:/tf/tensorflow-1.10.0/tensorflow/contrib/cmake/build2/grpc/src/grpc'")
# endif()

# set(git_options)

# # disable cert checking if explicitly told not to do it
# set(tls_verify "")
# if(NOT "x" STREQUAL "x" AND NOT tls_verify)
  # list(APPEND git_options
    # -c http.sslVerify=false)
# endif()

# set(git_clone_options)

# set(git_shallow "")
# if(git_shallow)
  # list(APPEND git_clone_options --depth 1 --no-single-branch)
# endif()

# set(git_progress "")
# if(git_progress)
  # list(APPEND git_clone_options --progress)
# endif()

# set(git_config "")
# foreach(config IN LISTS git_config)
  # list(APPEND git_clone_options --config ${config})
# endforeach()

# # try the clone 3 times in case there is an odd git clone issue
# set(error_code 1)
# set(number_of_tries 0)
# while(error_code AND number_of_tries LESS 3)
  # execute_process(
    # COMMAND "C:/Program Files/Git/cmd/git.exe" ${git_options} clone ${git_clone_options} --origin "origin" "https://github.com/grpc/grpc.git" "grpc"
    # WORKING_DIRECTORY "D:/tf/tensorflow-1.10.0/tensorflow/contrib/cmake/build2/grpc/src"
    # RESULT_VARIABLE error_code
    # )
  # math(EXPR number_of_tries "${number_of_tries} + 1")
# endwhile()
# if(number_of_tries GREATER 1)
  # message(STATUS "Had to git clone more than once:
          # ${number_of_tries} times.")
# endif()
# if(error_code)
  # message(FATAL_ERROR "Failed to clone repository: 'https://github.com/grpc/grpc.git'")
# endif()

# execute_process(
  # COMMAND "C:/Program Files/Git/cmd/git.exe" ${git_options} checkout d184fa229d75d336aedea0041bd59cb93e7e267f --
  # WORKING_DIRECTORY "D:/tf/tensorflow-1.10.0/tensorflow/contrib/cmake/build2/grpc/src/grpc"
  # RESULT_VARIABLE error_code
  # )
# if(error_code)
  # message(FATAL_ERROR "Failed to checkout tag: 'd184fa229d75d336aedea0041bd59cb93e7e267f'")
# endif()

# execute_process(
  # COMMAND "C:/Program Files/Git/cmd/git.exe" ${git_options} submodule init 
  # WORKING_DIRECTORY "D:/tf/tensorflow-1.10.0/tensorflow/contrib/cmake/build2/grpc/src/grpc"
  # RESULT_VARIABLE error_code
  # )
# if(error_code)
  # message(FATAL_ERROR "Failed to init submodules in: 'D:/tf/tensorflow-1.10.0/tensorflow/contrib/cmake/build2/grpc/src/grpc'")
# endif()

# execute_process(
  # COMMAND "C:/Program Files/Git/cmd/git.exe" ${git_options} submodule update --recursive --init 
  # WORKING_DIRECTORY "D:/tf/tensorflow-1.10.0/tensorflow/contrib/cmake/build2/grpc/src/grpc"
  # RESULT_VARIABLE error_code
  # )
# if(error_code)
  # message(FATAL_ERROR "Failed to update submodules in: 'D:/tf/tensorflow-1.10.0/tensorflow/contrib/cmake/build2/grpc/src/grpc'")
# endif()
  1. 把前面下载的compiler-rt/lib/fuzzer中全部内容都复制到“D:\tensorflow-1.10.0\tensorflow\contrib\cmake\build\grpc\src\grpc\third_party\bloaty\third_party\libFuzzer”中。
  2. 再次运行msbuild:
msbuild /p:Configure=Release grpc.vcxproj
  1. 等待运行结束提示0个错误,N个警告,进行下一步。

生成tensorflow.dll

  1. 生成tf_core_kernels:
msbuild /p:Configure=Release tf_core_kernels.vcxproj
  1. 生成tensorflow_static
msbuild /p:Configure=Release tensorflow_static.vcxproj
  1. 生成tensorflow
msbuild /p:Configure=Release tensorflow.vcxproj
  1. 大功告成!tensorflow_static.lib, tensorflow.libtensorflow.dll都在D:\tf\tensorflow-1.10.0\tensorflow\contrib\cmake\build2\Release里面,头文件是D:\tf\tensorflow-1.10.0\tensorflow\c\c_api.h

折腾了三个礼拜终于把遇到的坑都填上了… 我去训练模型了,DLL能不能用大家试过了可以告诉我。

祝各位也都编译成功!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值