帝王谷资源网 Design By www.wdxyy.com
我就废话不多说了,那就直接看代码吧~
inputs = Variable(torch.randn(2,2)) inputs.is_cuda # will return false inputs = Variable(torch.randn(2,2).cuda()) inputs.is_cuda # returns true
判断:
torch.is_tensor() #如果是pytorch的tensor类型返回true
torch.is_storage() # 如果是pytorch的storage类型返回ture
这里还有一个小技巧,如果需要判断tensor是否为空,可以如下
> a=torch.Tensor() > len(a) 0 > len(a) is 0 True
设置:通过一些内置函数,可以实现对tensor的精度, 类型,print打印参数等进行设置
torch.set_default_dtype(d) #对torch.tensor() 设置默认的浮点类型 torch.set_default_tensor_type() # 同上,对torch.tensor()设置默认的tensor类型 > torch.tensor([1.2, 3]).dtype # initial default for floating point is torch.float32 torch.float32 > torch.set_default_dtype(torch.float64) > torch.tensor([1.2, 3]).dtype # a new floating point tensor torch.float64 > torch.set_default_tensor_type(torch.DoubleTensor) > torch.tensor([1.2, 3]).dtype # a new floating point tensor torch.float64 torch.get_default_dtype() #获得当前默认的浮点类型torch.dtype torch.set_printoptions(precision=None, threshold=None, edgeitems=None, linewidth=None, profile=None)#) ## 设置printing的打印参数
判断变量类型:下面两种方法都行
if isinstance(downsample, torch.nn.Module):
# if torch.type(downsample) != torch.IntTensor:
补充知识:pytorch:测试GPU是否可用
废话不多说,看代码吧~
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 1080 tensor([[0.9530, 0.4746, 0.9819], [0.7192, 0.9427, 0.6768], [0.8594, 0.9490, 0.6551]], device='cuda:0')
以上这篇pytorch判断是否cuda 判断变量类型方式就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。
帝王谷资源网 Design By www.wdxyy.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
帝王谷资源网 Design By www.wdxyy.com
暂无评论...
RTX 5090要首发 性能要翻倍!三星展示GDDR7显存
三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。
首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。
据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。
更新日志
2024年10月26日
2024年10月26日
- 群星2013-青春缤纷辑压箱宝大公开3CD2[新加坡限量版][WAV整轨]
- 林育群.2013-BalladShow(日本版)【环球】【WAV+CUE】
- 陈加洛.1992-痛到感觉不到【宝丽金】【WAV+CUE】
- 群星.2023-宿命之敌电视剧原声带【韶愔音乐】【FLAC分轨】
- 東京事変-大発見[FLAC+CUE]
- 椎名林檎-三文ゴシップ[FLAC+CUE]
- 2024年08月04日
- 裘德《裘德「最后的水族馆」演唱会LIVE》[320K/MP3][228.89MB]
- 裘德《裘德「最后的水族馆」演唱会LIVE》[24bit 48kHz][FLAC/分轨][2.08G]
- 基因三重奏《如果你什么都不说 音乐会现场录音》[320K/MP3][145.37MB]
- 孟庭苇.1996-月亮说话(2020环球24KGOLD限量版)【上华】【WAV+CUE】
- 群星.1997-新艺宝优质音响系列·国语精选监听版【新艺宝】【WAV+CUE】
- 阿桑.2005-寂寞在唱歌(星外星引进版)【华研国际】【WAV+CUE】
- 基因三重奏《如果你什么都不说 音乐会现场录音》[FLAC/分轨][287.43MB]
- 蔡题谦《我爱你,却依然要看你走》[320K/MP3][88.65MB]