天天看點

64位Win7SP1+VS2015Update3編譯Tensorflow1.10準備改CMake配置檔案運作CMake-GUI進行Configure和Generate生成grpc生成tensorflow.dll

64位Win7SP1+VS2015Update3編譯Tensorflow1.10

  • 準備
  • 改CMake配置檔案
  • 運作CMake-GUI進行Configure和Generate
  • 生成grpc
  • 生成tensorflow.dll

準備

  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行

“OFF"改成”/arch:AVX"。其他選項也可以在這裡改,在CMake-GUI裡面改也一樣。

2. D:\tf\tensorflow-1.10.0\tensorflow\contrib\cmake\external\protobuf.cmake:第19行

“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. 勾選圖中的選項:
    64位Win7SP1+VS2015Update3編譯Tensorflow1.10準備改CMake配置檔案運作CMake-GUI進行Configure和Generate生成grpc生成tensorflow.dll
    再點“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.lib和tensorflow.dll都在D:\tf\tensorflow-1.10.0\tensorflow\contrib\cmake\build2\Release裡面,頭檔案是D:\tf\tensorflow-1.10.0\tensorflow\c\c_api.h。

折騰了三個禮拜終于把遇到的坑都填上了… 我去訓練模型了,DLL能不能用大家試過了可以告訴我。

祝各位也都編譯成功!

繼續閱讀