走了好多坑,終於把深度學習的環境給搭好了
首先感謝這兩位博主的無私奉獻,我是綜合他們的方法安裝成功的,本文有些步驟直接複製以下博文
https://blog.csdn.net/qq_35976351/article/details/79325476
https://www.cnblogs.com/xuliangxing/p/7575586.html
http://www.cnblogs.com/xuliangxing/p/7569946.html
一.驅動,直接從官網下載官方驅動。我下載的是最新的版本Nvidia 410.78
安裝驅動的具體操作步驟參照 http://www.cnblogs.com/xuliangxing/p/7569946.html
二.下載CUDA 9.0,記得一定是9.0,這樣少走點坑(初次登錄需要註冊帳號)
CUDA9.0下載地址:https://developer.nvidia.com/cuda-90-download-archive?target_os=Linux&target_arch=x86_64&target_distro=Ubuntu&target_version=1604&target_type=deblocal
記得下載runfile(local),不要下載deb(我是沒裝好)
安裝必要的依賴
sudo apt-get install freeglut3-dev build-essential libx11-dev libxmu-dev libxi-devlibgl1-mesa-glx libglu1 #安裝依賴庫
安裝runfile(直接使用tab補全不了,建議直接複製文件名到terminal)
sudo sh cuda_9.0.176_384.81_linux.run #執行安裝文件
安裝過程中,所有選項都是accept, y 或者enter(就直接默認路徑)。除了Graphics Driver(選N)
配置環境變量
sudo vim ~/.bashrc # 配置環境變量
# 文末追加以下三行代碼
export PATH=/usr/local/cuda-9.0/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda-9.0/lib64:$LD_LIBRARY_PATH
export CUDA_HOME=/usr/local/cuda
執行命令,生效
#環境變量立即生效
sudo source ~/.bashrc
sudo ldconfig
檢查cuda是否配置成功(顯示版本信息爲V9.0即可)
nvcc --version
再測試cuda samples是否成功
# 切換到cuda-samples所在目錄
cd /usr/local/cuda-9.0/samples
# 沒有make,先安裝命令 sudo apt-get install cmake,-j是最大限度的使用cpu編譯,加快編譯的速度
make –j
# 編譯完畢,切換release目錄(/usr/local/cuda-9.0/samples/bin/x86_64/linux/release完整目錄)
cd ./bin/x86_64/linux/release
# 檢驗是否成功,運行實例
./deviceQuery
# 可以認真看看自行結果,它顯示了你的NVIDIA顯卡的相關信息,最後能看到Result = PASS就算成功。
三.安裝cuDNN
**cuDNN v7.3.1**下載地址:https://developer.nvidia.com/rdp/cudnn-archive
用之前下載CUDA註冊的郵箱登錄就行。
進入之後點擊Download,之後進入下載界面,選擇上I Agree To the Terms of the cuDNN Software License Agreement的複選框
下載三個文件(但我安裝的時候只使用了一個,其他的以後備用)
在下載目錄直接安裝deb
sudo dpkg -i libcudnn7_7.3.1.20-1+cuda9.0_amd64.deb
四.安裝tensorflow(創一個虛擬環境,我用的anaconda,安裝的python3.6,當時爲了測試bert gpu版本)
conda create -n bert_p3 python=3.6
用source activate bert_p3進入虛擬環境(安裝1.11是支持CUDA 9.0的)
pip install --upgrade tensorflow-gpu==1.11
最後直接粘貼博主的測試代碼
測試有結果即可
import tensorflow as tf
import numpy as np
x = tf.placeholder("float",shape=[None,1])
W = tf.Variable(tf.zeros([1,1]))
b = tf.Variable(tf.zeros([1]))
y = tf.matmul(x,W) +b
y_ = tf.placeholder("float",[None,1])
cost = tf.reduce_sum(tf.pow((y_-y),2))
train_step = tf.train.GradientDescentOptimizer(0.001).minimize(cost)
init = tf.initialize_all_variables()
sess = tf.Session()
sess.run(init)
All_x = np.empty(shape=[1,1])
All_y = np.empty(shape=[1,1])
for i in range(1000):
x_s = np.random.rand(1,1)
y_s = np.dot([[0.33]],np.random.rand(1,1)) + 0.33
feed = {x: x_s, y_: y_s}
sess.run(train_step,feed_dict=feed)
print("After %d iteration:"%i)
print("W : %f"%sess.run(W))
print("b : %f"%sess.run(b))
All_x = np.concatenate((All_x,x_s))
All_y = np.concatenate((All_y,y_s))
print(All_x)
print(All_y)
---------------------
作者:Erick_Lv
來源:CSDN
原文:https://blog.csdn.net/qq_35976351/article/details/79325476
版權聲明:本文爲博主原創文章,轉載請附上博文鏈接!