我是靠谱客的博主 缓慢小蝴蝶,这篇文章主要介绍(Ubuntu/Window)pytorch验证(pytorch是否安装成功)验证pytorch是否可用(CPU/GPU),现在分享给大家,希望可以做个参考。

验证pytorch是否可用(CPU/GPU)

以下是pytorch是否安装成功的验证代码,看到没有报错正常输出了,那就要恭喜你完成小白的第一步了!
分享一下: 在确定你自己显卡驱动后,其实可以通过Pytorch官网的命令直接进行pytorch(GPU/CPU)两个版本的安装,安装失败基本是网络问题!
pip install -i “豆瓣源” ---->>>>(可以用这总方式u进行)

GPU上测试

复制代码
1
2
3
4
5
6
7
8
9
import torch # 能否调用pytorch库 print(torch.cuda.current_device()) # 输出当前设备(我只有一个GPU为0) print(torch.cuda.device(0)) # <torch.cuda.device object at 0x7fdfb60aa588> print(torch.cuda.device_count()) # 输出含有的GPU数目 print(torch.cuda.get_device_name(0)) # 输出GPU名称 --比如1080Ti x = torch.rand(5, 3) print(x) # 输出一个5 x 3 的tenor(张量)

CPU上测试

复制代码
1
2
3
4
import torch x = torch.rand(5,3) print(x)

最后

以上就是缓慢小蝴蝶最近收集整理的关于(Ubuntu/Window)pytorch验证(pytorch是否安装成功)验证pytorch是否可用(CPU/GPU)的全部内容,更多相关(Ubuntu/Window)pytorch验证(pytorch是否安装成功)验证pytorch是否可用(CPU/GPU)内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(66)

评论列表共有 0 条评论

立即
投稿
返回
顶部