验证pytorch、tensorflow GPU版本是否可用
2. tensorflow验证失败可能会提示缺少一些dll文件,根据提示下载缺少的文件到指定位置即可。1. pytorch或者tensorflow版本与cuda版本不一致。解决方案:查看自己的cuda版本,搜索一下适配的版本进行安装。二、验证tensorflow GPU版本。一、验证pytorch GPU版本。
·
一、验证pytorch GPU版本
方法1:
#判断是否安装了cuda
import torch
print(torch.cuda.is_available()) #返回True则说明已经安装了cuda
#判断是否安装了cuDNN
from torch.backends import cudnn
print(cudnn.is_available()) #返回True则说明已经安装了cuDNN
运行结果:
方法2:
import torch
a = torch.cuda.is_available()
print(a)
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())
运行结果:
二、验证tensorflow GPU版本
方法1:
import tensorflow as tf
print("Num GPUs Available: ", len(tf.config.experimental.list_physical_devices('GPU')))
运行结果:
方法2:
import tensorflow as tf
a = tf.test.is_built_with_cuda() # 判断CUDA是否可以用
b = tf.test.is_gpu_available(
cuda_only=False,
min_cuda_compute_capability=None
) # 判断GPU是否可以用
print(a)
print(b)
运行结果:
验证失败原因解析:
1. pytorch或者tensorflow版本与cuda版本不一致
解决方案:查看自己的cuda版本,搜索一下适配的版本进行安装
2. tensorflow验证失败可能会提示缺少一些dll文件,根据提示下载缺少的文件到指定位置即可
更多推荐
已为社区贡献2条内容
所有评论(0)