目錄
一、顯卡驅動版本和CUDA版本的確認和安裝與更新
TensorFlow安裝時需要cuda+對應的顯卡驅動。這裏給出英偉達官方的cuda和驅動的對應:
然後在這裏可下載最新的顯卡驅動(英偉達公版的驅動,程序員友好型)
關於具體步驟請參考我的上一篇文章《如何查看電腦是否支持CUDA及支持的CUDA版本》
二、配置python環境
(E:\programfile\Anaconda3) C:\Users\TP>pip3 install six numpy wheel
Requirement already satisfied: six in e:\programfile\anaconda3\lib\site-packages (1.11.0)
Requirement already satisfied: numpy in e:\programfile\anaconda3\lib\site-packages (1.16.0)
Requirement already satisfied: wheel in e:\programfile\anaconda3\lib\site-packages (0.29.0)
(E:\programfile\Anaconda3) C:\Users\TP>pip3 install keras_applications==1.0.6 --no-deps
Collecting keras_applications==1.0.6
Using cached Keras_Applications-1.0.6-py2.py3-none-any.whl (44 kB)
Installing collected packages: keras-applications
Attempting uninstall: keras-applications
Found existing installation: Keras-Applications 1.0.2
Uninstalling Keras-Applications-1.0.2:
Successfully uninstalled Keras-Applications-1.0.2
Successfully installed keras-applications-1.0.6
(E:\programfile\Anaconda3) C:\Users\TP>pip3 install keras_preprocessing==1.0.5 --no-deps
Collecting keras_preprocessing==1.0.5
Using cached Keras_Preprocessing-1.0.5-py2.py3-none-any.whl (30 kB)
Installing collected packages: keras-preprocessing
Attempting uninstall: keras-preprocessing
Found existing installation: Keras-Preprocessing 1.0.1
Uninstalling Keras-Preprocessing-1.0.1:
Successfully uninstalled Keras-Preprocessing-1.0.1
Successfully installed keras-preprocessing-1.0.5
(E:\programfile\Anaconda3) C:\Users\TP>
三、在 Windows 上安裝 Bazel
參考:https://blog.csdn.net/darkrabbit/article/details/81262524
前提
-
至少爲 64 位 Windows 7 ,或者至少同等於它的 Windows Server 版本
這些公共的 DLLs 是 Bazel 所需要的。你可能已經安裝了它們。
從我們的 GitHub releases 頁面下載 Windows 版本的 Bazel 。在頁面中找到 bazel-<version>-windows-x86_64.exe
,例如:
bazel-0.13.0-windows-x86_64.exe
提示: 爲了方便起見,將下載的二進制文件重命名爲 bazel.exe
,並將其移動到你的 %PATH%
目錄中,或者將它所在目錄的路徑添加進 %PATH%
。這樣你就可以在任何目錄中輸入 bazel
來運行 Bazel 而不需要輸入完整的路徑。
注意: Bazel 包含一個嵌入式的 JDK ,所以你不需要單獨安裝它。如果你想要下載一個不包含 JDK 的 Bazel 。在 release 頁面中找到 bazel-<version>-without-jdk-windows-x86_64.exe
。要使用它,你必須單獨安裝一個 JDK 8 (舊版本與新版本均不受支持),並設置 %JAVA_HOME%
的環境變量,例如:
set JAVA_HOME=c:\Program Files\Java\jdk1.8.0_171
要注意,不要使用引號(”)將路徑包住(就像你在 Unixes 上那樣)。
你也可以使用如下方式獲取 Bazel :
你可以使用 Chocolatey package manager 來安裝 Bazel:
choco install bazel
這條命令會安裝可用且最新版本的 Bazel 與依賴包,例如 MSYS2 shell 。但並不會安裝 Visual C++ 。
更多關於 Chocolatey 的信息,見 Chocolatey installation and package maintenance guide 。
從https://github.com/bazelbuild/bazel/releases下載,下載0.230版本,下載完畢後,配置環境變量,就可以使用了,如下:
四、安裝windows上的linux環境
1.在windows上安裝配置msys2,並將目錄D:\msys64\usr\bin添加到環境變量中。
安裝參考:https://blog.csdn.net/hustlei/article/details/86687588
MSYS2 [1] 是MSYS的一個升級版,準確的說是集成了pacman和Mingw-w64的Cygwin升級版, 提供了bash shell等linux環境、版本控制軟件(git/hg)和MinGW-w64 工具鏈。與MSYS最大的區別是移植了 Arch Linux的軟件包管理系統 Pacman(其實是與Cygwin的區別)。
2、安裝相關工具
pacman.exe -S git patch unzip
五、下載tensorflow源碼
https://github.com/tensorflow/tensorflow
E:\vmware\window_tensorflow_progect>git clone https://github.com/tensorflow/tensorflow
Cloning into 'tensorflow'...
remote: Enumerating objects: 217, done.
remote: Counting objects: 100% (217/217), done.
remote: Compressing objects: 100% (169/169), done.
remote: Total 878186 (delta 98), reused 157 (delta 48), pack-reused 877969R
Receiving objects: 100% (878186/878186), 510.77 MiB | 89.00 KiB/s, done.
Resolving deltas: 100% (712464/712464), done.
Checking out files: 100% (21487/21487), done.
E:\vmware\window_tensorflow_progect>cd tensorflow
E:\vmware\window_tensorflow_progect\tensorflow>git checkout r2.0
Checking out files: 100% (15123/15123), done.
Switched to a new branch 'r2.0'
Branch 'r2.0' set up to track remote branch 'r2.0' from 'origin'.
E:\vmware\window_tensorflow_progect\tensorflow>ls
ACKNOWLEDGMENTS CODEOWNERS ISSUE_TEMPLATE.md SECURITY.md configure.cmd third_party
ADOPTERS.md CODE_OF_CONDUCT.md LICENSE WORKSPACE configure.py tools
AUTHORS CONTRIBUTING.md README.md arm_compiler.BUILD models.BUILD
BUILD ISSUES.md RELEASE.md configure tensorflow
E:\vmware\window_tensorflow_progect\tensorflow>python ./configure.py
Cannot find bazel. Please install bazel.
E:\vmware\window_tensorflow_progect\tensorflow>python ./configure.py
You have bazel 3.0.0 installed.
Please downgrade your bazel installation to version 0.26.1 or lower to build TensorFlow! To downgrade: download the installer for the old version (from https://github.com/bazelbuild/bazel/releases) then run the installer.
E:\vmware\window_tensorflow_progect\tensorflow>
六、更新與tensorflow合適的bazel版本
從如上>python ./configure.py的執行log中可以知道bazel版本不符合,需要安裝合適的版本。
打開頁面“https://github.com/bazelbuild/bazel/releases”,點擊頁面最下方的“Next”按鈕,找到要下載的版本,如下:
點擊如上紅色“Assets”,展開如下,找到對應的window版本即可。
直接點擊下載會由於資源的問題,有時候後下載特別慢或者下載失敗。
因爲已經安裝了MSYS2,我們可以使用linux 命令進行下載。
E:\vmware\window_tensorflow_progect>wget -c https://github.com/bazelbuild/bazel/releases/download/0.26.1/bazel-0.26.1-windows-x86_64.exe
-C 允許斷點下載,即再下載失敗後,再次下載可以接着下載,而不是從新下載。
轉載:https://blog.csdn.net/qq_32095699/article/details/80855402
繼續編譯tensorflow源碼
參考鏈接:
1、https://blog.csdn.net/zzpong/article/details/80282814
2、https://blog.csdn.net/u013165921/article/details/77891913
總結一下方法:
1.安裝vs2015
光驅地址:https://blog.csdn.net/guxiaonuan/article/details/73775519?locationNum=2&fps=1
先安裝光驅,再裝vs2015
2.下載cuda8.0
下載地址:https://developer.nvidia.com/cuda-toolkit-archive
3.安裝cuda8.0
選擇項自定義安裝CUDA,並記下你所釋放安裝程序的路徑
之後按照默認路徑安裝即可。
不要選 Visual Stdio Integration!!
4、VS integration
把文件夾:
D:\SOFTWARE\CUDA_setup**CUDAVisualStudioIntegration\extras\visual_studio_integration\MSBuildExtension下的所有文件拷貝到C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\v140\BuildCustomizations下(黑色字體爲安裝程序的路徑**)
再將“**D:\SOFTWARE\CUDA_setup**CUDAVisualStudioIntegration\extras\visual_studio_integration”下的CudaProjectVsWizards文件夾整體拷貝到“C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions”(VS安裝路徑下找)下即可,
打開:C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE
管理員運行cmd:
就可以將CUDA 移入vs:
最後的最後,還可以把“**D:\SOFTWARE\CUDA_setup**CUDAVisualStudioIntegration”下的NVIDIA_Nsight_Visual_Studio_Edition_Win64_5.2.0.16321安裝一下,它是CUDA給VS2015提供的一個調試插件。
安裝成功
相關參考:https://blog.csdn.net/qq_32095699/article/details/80855402