網上有很多教程,特別是簡寫上的寫的都還算比較詳細。但我自己還是遇到了幾個坑,希望對深度學習有興趣的同學遇到跟我一樣的坑,希望這份記錄能幫助到你。
問題一:要不要使用Anaconda?
我看極客時間上的視頻課《Tensorflow快速入門與實踐》,留言版塊上也有討論這個,視頻課中沒有用,給出的理由是太大了,幾個G。https://time.geekbang.org/discuss/detail/62837
有利弊吧,管理版本方便,但也增加了一定的復雜度。自己覺得好就行~
問題二:pip install tensorflow-gpu 下載慢怎么辦?
用國內的鏡像,不要就得翻牆。用法:pip install -i https://mirrors.aliyun.com/pypi/simple/ --upgrade tensorflow-gpu==1.14.0
-i 后面跟着是鏡像的網址,上面用的是阿里雲的,國內還有例如清華大學等鏡像,自行搜索一下就行。
建議使用2.0的版本,截止目前為止 2.0.0.b1 很多用法已經進行了較大的調整,特別是API。你從網上下載的代碼和學習使用的代碼,可能都需要進行修改,無疑增加了學習的難度,建議最高用 1.14.0或者更低的版本
問題三:不同的 Tensorflow-gpu 該安裝何種 CUDA 和 cuDNN 版本呢?
查看鏈接 https://tensorflow.google.cn/install/source_windows ,注意查看文章不要使用中文,中文的翻譯沒有 1.14.0(翻譯可能滯后了)
千萬記得一定要下載匹配的版本,不然會有問題的。
你的顯卡是否支持 CUDA 的版本,可以通過這個網址查看:https://developer.nvidia.com/cuda-gpus
CUDA 下載 https://developer.nvidia.com/cuda-downloads
cuDNN 下載 https://developer.nvidia.com/rdp/cudnn-download
如果你確實想嘗新,記得查看官網的文檔:https://tensorflow.google.cn/beta/guide/migration_guide
問題四:遇到 failed call to cuInit: CUDA_ERROR_UNKNOWN 錯誤怎么辦?
我就遇到了,折騰的死去活來的,最終發現是自己手癢的問題,不該升級顯卡驅動的。 TF 的版本,我從1.x 換到 2.0 然后又換回來,光 CUDA 與 cuDNN 都卸載重裝好多次了,電腦了重啟了N次,還是失敗。
最后找到一篇在ubuntu上遇到這個問題的文章,說是顯卡驅動問題,然后我從官網重新下載了 windows 的驅動,安裝后正常了。 顯卡驅動下載地址:https://www.nvidia.cn/Download/index.aspx?lang=cn
問題五:如何驗證是否安裝成功了(僅限 TF 1.x)
cmd -> python
進入 python 命令行之后,使用下面的代碼進行驗證
> import tensorflow as tf
> sess = tf.Session()
如果一切正常,會輸出
Python 3.6.4 (v3.6.4:d48eceb, Dec 19 2017, 06:54:40) [MSC v.1900 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import tensorflow as tf >>> sess = tf.Session() 2019-08-11 17:38:01.267862: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library nvcuda.dll 2019-08-11 17:38:01.393012: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1640] Found device 0 with properties: name: GeForce GTX 1060 6GB major: 6 minor: 1 memoryClockRate(GHz): 1.7085 pciBusID: 0000:01:00.0 2019-08-11 17:38:01.397606: I tensorflow/stream_executor/platform/default/dlopen_checker_stub.cc:25] GPU libraries are statically linked, skip dlopen check. 2019-08-11 17:38:01.400748: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1763] Adding visible gpu devices: 0 2019-08-11 17:38:01.403269: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 2019-08-11 17:38:01.408338: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1640] Found device 0 with properties: name: GeForce GTX 1060 6GB major: 6 minor: 1 memoryClockRate(GHz): 1.7085 pciBusID: 0000:01:00.0 2019-08-11 17:38:01.412305: I tensorflow/stream_executor/platform/default/dlopen_checker_stub.cc:25] GPU libraries are statically linked, skip dlopen check. 2019-08-11 17:38:01.415404: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1763] Adding visible gpu devices: 0 2019-08-11 17:38:02.046658: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1181] Device interconnect StreamExecutor with strength 1 edge matrix: 2019-08-11 17:38:02.050748: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1187] 0 2019-08-11 17:38:02.052282: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1200] 0: N 2019-08-11 17:38:02.054474: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1326] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 4712 MB memory) -> physical GPU (device: 0, name: GeForce GTX 1060 6GB, pci bus id: 0000:01:00.0, compute capability: 6.1) >>>
環境安裝完了,從網上隨便找一個驗證碼識別的例子開始玩起來吧~