Anaconda環境安裝
- 官網下載
- Win+r cmd
輸入conda,檢查是否安裝
輸入activate,下一行輸入python,檢查python版本,然后exit退出,

- 使用Anaconda兩條命令,第一條新建虛擬環境conda create -n py36 python=3.6
- 建立好虛擬環境,通過命令進入虛擬環境,退出虛擬環境,

Cuda安裝
- 命令提示符 nvcc -V看是否存在cuda
- 卸載時保留以下圖片內容

- 到官網下載

選擇第二個,可以下載歷史版cuda,我在里面選的cuda10.1
![]()
進行下載



安裝cudnn

安裝tensorflow
conda create -n tf21 python=3.7
pip install tensorflow_gpu==2.1.0 -i https://pypi.douban.com/simple --trusted-host pypi.douban.com
import tensorflow as tf
import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2' # 不顯示等級2以下的提示資訊
print('GPU', tf.test.is_gpu_available())
a = tf.constant(2.0)
b = tf.constant(4.0)
print(a + b)

參考https://blog.csdn.net/weixin_43786241/article/details/109203995
安裝pytorch
conda install pytorch==1.7.1 torchvision==0.8.2 torchaudio==0.7.2 cudatoolkit=10.1 -c pytorch
到pycharm下載

pytorch測驗代碼:
import torch
import time
from torch import autograd
#GPU加速
print(torch.__version__)
print(torch.cuda.is_available())
a=torch.randn(10000,1000)
b=torch.randn(1000,10000)
print(a)
print(b)
t0=time.time()
c=torch.matmul(a,b)
t1=time.time()
print(a.device,t1-t0,c.norm(2))
device=torch.device('cuda')
print(device)
a=a.to(device)
b=b.to(device)
t0=time.time()
c=torch.matmul(a,b)
t2=time.time()
print(a.device,t2-t0,c.norm(2))
t0=time.time()
c=torch.matmul(a,b)
t2=time.time()
print(a.device,t2-t0,c.norm(2))
參考https://blog.csdn.net/qq_36162036/article/details/107407928
注意有的顯卡會操作不成功
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/295179.html
標籤:python
上一篇:Java崗大廠面試百日沖刺 - 榷訓月累,每日三題【Day36】—— 實戰那些事兒1
下一篇:Python編程基礎 變數
