安裝ubuntu 20.04 安裝nvidia 驅(qū)動(dòng) 配置pytouch 和tensorflow環(huán)境
本機(jī)環(huán)境:戴爾g3 3579
win10 ,系統(tǒng)在128固態(tài)硬盤(pán)
安裝ubuntu20.04
1開(kāi)機(jī)按f2進(jìn)入bios
2 security boot 設(shè)置disable
安裝nvidia驅(qū)動(dòng)
最開(kāi)始安裝驅(qū)動(dòng),首先禁止nouveau
然后卸載原先的nvidia驅(qū)動(dòng)(如果有)
但是裝完出現(xiàn)這種情況
nvidia-smi有輸出,nvidia-settings有反映,而且還生成了快捷圖標(biāo)
但是重啟生效后,在設(shè)置->關(guān)于:顯卡由原來(lái)的集成顯卡630變成了lvib什么的
雖然不影響審定學(xué)習(xí)環(huán)境搭建但是總感覺(jué)以后會(huì)掛的
還有一種情況是 ,裝完成驅(qū)動(dòng)后,在設(shè)置->關(guān)于:顯卡顯示gtx1060。但是每次開(kāi)機(jī)或者關(guān)機(jī)顯示:dev/sda5 clean …dev/sda6 clean.等2s后關(guān)機(jī),開(kāi)機(jī)也是這樣。
還有一種情況是,環(huán)境搭建好了,驅(qū)動(dòng)什么的都好了,但是一個(gè)命令,當(dāng)時(shí)在安裝網(wǎng)易云音月,要弄什么依賴,然后一行命令過(guò)去,開(kāi)機(jī)無(wú)限閃現(xiàn)dev/sda6 clean 。ctro-alt-f1能打開(kāi)tty,但是用戶名和密碼來(lái)不及輸入,tty閃退,1s不到。然后進(jìn)不了系統(tǒng)。最后重裝系統(tǒng)
現(xiàn)在:
裝完ubuntu系統(tǒng)后,什么更新都不要,也不要禁止nouveau。第一件事情直接裝驅(qū)動(dòng),
重啟后,麻事情沒(méi)有。
搭建pytouch
安裝miniconda3,
換中科大,清華源
conda create -n pytouch python=3.7
conda activate pytouch
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
conda install pytorch=0.4.1 torchvision cuda90
安裝pycharm
點(diǎn)擊tools->create desktop entry 直接生成快捷鍵
設(shè)置編譯器為pytouch
填寫(xiě)代碼測(cè)試使用了gpu:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
import torch flag = torch.cuda.is_available() print(flag) ngpu= 1 # decide which device we want to run on device = torch.device("cuda:0" if (torch.cuda.is_available() and ngpu > 0) else "cpu") print(device) print(torch.cuda.get_device_name(0)) print(torch.rand(3,3).cuda()) # true # cuda:0 # geforce gtx 1060 # tensor([[0.5772, 0.5287, 0.0946], # [0.9525, 0.7855, 0.1391], # [0.6858, 0.5143, 0.8188]], device='cuda:0') |
安裝tensorflow14
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
import tensorflow as tf from tensorflow.python.client import device_lib print(device_lib.list_local_devices()) import warnings warnings.filterwarnings("ignore") hello=tf.constant("hello,tensorflow") print(hello) a=tf.constant([1.0,2.0]) #定義常數(shù) b=tf.constant([3.4,4.0]) result1=a+b print("a+b=",result1) c=tf.constant([[3.0],[1.4]]) result2=a+c sess=tf.session() print("result1:",result1)#顯示結(jié)果是“add:0"的張量,shape只有一個(gè)元素,即維度是1 # 2表示第一個(gè)維度有兩個(gè)元素,且是浮點(diǎn)型 try: print(sess.run(result1)) print("result2:",result2) print(sess.run(result2)) print(sess.run(hello)) except: #異常處理 print("exception") finally: #關(guān)閉會(huì)話,釋放資源 sess.close() |
總結(jié)
到此這篇關(guān)于安裝ubuntu20.04與安裝nvidia驅(qū)動(dòng)的教程的文章就介紹到這了,更多相關(guān)安裝ubuntu20.04 nvidia驅(qū)動(dòng)內(nèi)容請(qǐng)搜索服務(wù)器之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持服務(wù)器之家!
原文鏈接:https://blog.csdn.net/z_6_2_0_s/article/details/106201929