先測試:
import torch
print(torch.__version__)
print(torch.cuda.is_available())
如果輸出的結(jié)果是False,那么說明當前的Pytorch版本無法使用顯卡。
解決辦法:
(1)如果有顯卡資源并需要使用顯卡資源,先檢查一下當前的CUDA版本,在終端中輸入
cat /usr/local/cuda/version.txt
(2)然后根據(jù)自己的CUDA版本在Pytorch官網(wǎng)查看并安裝可用的版本,參考鏈接如下:
CUDA 10.2
https://download.pytorch.org/whl/cu102/torch_stable.html
CUDA 10.1
https://download.pytorch.org/whl/cu101/torch_stable.html
CUDA 10.0
https://download.pytorch.org/whl/cu100/torch_stable.html
CUDA 9.0
https://download.pytorch.org/whl/cu90/torch_stable.html
CPU及所有CUDA版本