簡單利用conda安裝tensorflow-gpu=2.2.0的過程及問題解決
網(wǎng)上安裝tensorflow-gpu=2.2.0什么的一大推,而且最后還報錯,一般問題出現(xiàn)在:
一、安裝下載慢
二、cuda和cudnn版本不對
我最后實驗了,很好解決上面的問題。
2021年1月26日更新,python版本最好是3.7,3.8版本安裝有可能有問題,大概是conda沒有完全匹配好。
2021年8月10號更新,上面的問題官方解決了,首先使用conda命令安裝tensorflow-gpu=2.2.0,注意(需要已經(jīng)換成清華源了)
清華源命令:
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/ conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/ conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r/ conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/pro/ conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2/ conda config --set show_channel_urls yes
安裝命令:
conda install tensorflow-gpu==2.2.0
如果上面方式不行,就按下面方法來。
一、安裝tensorflow-gpu=2.2.0使用清華源安裝,代碼如下:
pip install tensorflow-gpu==2.2.0 -i https://pypi.tuna.tsinghua.edu.cn/simple
這樣下載速度飛起!
二、什么去官網(wǎng)下載cuda版本配置路徑,感覺都不靠譜,我實驗了,一個命令搞定,我的是1080Ti顯卡,先通過GeForce Experience把驅(qū)動更新到最新,我的cuda信息如下:

我cuda的是11.0,這不重要,一般需要cuda是10.1或者以上就可以了。
然后一句代碼安裝:
conda install cudatoolkit=10.1 cudnn=7.6.5
注意:不要改上面的版本,不然安裝成功了,使用時報錯,這里就是個坑,我試過很多,這兩個版本才是對應(yīng)的,不管tensorflow-gpu=2.0/2.1/2.2,都適用
tensorflow-gpu對應(yīng)的cuda版本網(wǎng)址:https://tensorflow.google.cn/install/source_windows
2021年5月18日更新,安裝tensorflow-gpu=2.4.0,使用python版本為3.7或者3.8,cudatoolkit=11.0,cudnn=8.0

安裝好后測試下,測試代碼;
import tensorflow as tf
import timeit
import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2' # 代碼用于忽略級別 2 及以下的消息(級別 1 是提示,級別 2 是警告,級別 3 是錯誤)。
with tf.device('/cpu:0'):
cpu_a = tf.random.normal([10000, 1000])
cpu_b = tf.random.normal([1000, 2000])
print(cpu_a.device, cpu_b.device)
with tf.device('/gpu:0'):
gpu_a = tf.random.normal([10000, 1000])
gpu_b = tf.random.normal([1000, 2000])
print(gpu_a.device, gpu_b.device)
def cpu_run():
with tf.device('/cpu:0'):
c = tf.matmul(cpu_a, cpu_b)
return c
def gpu_run():
with tf.device('/gpu:0'):
c = tf.matmul(gpu_a, gpu_b)
return c
# warm up
cpu_time = timeit.timeit(cpu_run, number=10)
gpu_time = timeit.timeit(gpu_run, number=10)
print('warmup:', cpu_time, gpu_time)
cpu_time = timeit.timeit(cpu_run, number=10)
gpu_time = timeit.timeit(gpu_run, number=10)
print('run time:', cpu_time, gpu_time)
print('GPU', tf.test.is_gpu_available())結(jié)果為:
warmup: 1.1624844 1.8189751
run time: 1.1631149999999995 0.0005907000000000551
GPU True
這樣就安裝成功了!
另外推薦個自動補全插件,很好用,TabNine,安裝方法鏈接如下:
https://www.tabnine.com/
2020年10月11號更新
最近可能出現(xiàn)的版本問題報錯,例如:
AttributeError: module ‘tensorflow’ has no attribute ‘compat’
解決方案:如下所示:
報錯:AttributeError: module ‘tensorflow’ has no attribute ‘compat’
找了半天錯誤,發(fā)現(xiàn)問題了,如下:

2020年10月5號更新
tensorflow==2.1.0版本也出現(xiàn)了這個問題,也用相同方法改正,注意版本就行了!!!
個是2.2版本,所以你要裝2.0.0版本的:
pip install tensorflow-estimator==2.0.0 -i https://pypi.tuna.tsinghua.edu.cn/simple
或者
conda install tensorflow-estimator==2.0.0
這樣就解決問題了。這個安裝估計是個bug,以前沒這個版本錯誤的,只是最近出現(xiàn)的。
到此這篇關(guān)于簡單利用conda安裝tensorflow-gpu=2.2.0的文章就介紹到這了,更多相關(guān)conda安裝tensorflow-gpu內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Python實現(xiàn)socket庫網(wǎng)絡(luò)通信套接字
socket又叫套接字,實現(xiàn)網(wǎng)絡(luò)通信的兩端就是套接字。分為服務(wù)器對應(yīng)的套接字和客戶端對應(yīng)的套接字,本文給大家介紹Python實現(xiàn)socket庫網(wǎng)絡(luò)通信套接字的相關(guān)知識,包括套接字的基本概念,感興趣的朋友跟隨小編一起看看吧2021-06-06
Python使用matplotlib 模塊scatter方法畫散點圖示例
這篇文章主要介紹了Python使用matplotlib 模塊scatter方法畫散點圖,結(jié)合實例形式分析了Python數(shù)值運算與matplotlib模塊圖形繪制相關(guān)操作技巧,需要的朋友可以參考下2019-09-09
python神經(jīng)網(wǎng)絡(luò)之批量學(xué)習(xí)tf.train.batch函數(shù)示例
這篇文章主要為大家介紹了python神經(jīng)網(wǎng)絡(luò)之批量學(xué)習(xí)tf.train.batch函數(shù)示例,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2022-05-05

