pytorch
文章平均质量分 50
LLY_A_
声明:本人博客内有些文章中某些内容可能来源于网上,如有侵权,请作者本人及时联系我,我将及时删除。
展开
-
torch.flip
import torcht1 = torch.arange(16).view(2, 2, 2,2)print('x=\n',x)t2 = torch.flip(x, [2])print('a=\n',a)t1= tensor([[[[ 0, 1], [ 2, 3]], [[ 4, 5], [ 6, 7]]], [[[ 8, 9], [10, 11]], .原创 2021-08-10 17:29:12 · 1298 阅读 · 0 评论 -
AverageMeter()的作用与用法
utils.py源码from __future__ import division, absolute_import__all__ = ['AverageMeter'][docs]class AverageMeter(object): """Computes and stores the average and current value. Examples:: >>> # Initialize a meter to record loss原创 2021-08-10 17:01:48 · 2180 阅读 · 0 评论 -
(三)如何在GPU上运行
1、判断GPU是否可用torch.cuda.is_available()device=torch.device("cuda:0" if torch.cuda.is_available() else "cpu")2、把模型参数和input数据转换成cuda支持的数据类型model.to(device)x_true.to(device)3、在GPU上计算结果也为cuda的数据类型,需要转化为numpy或者torch的cpu的tensor类型predict=predict.cpu().原创 2021-08-09 16:40:47 · 952 阅读 · 0 评论 -
(二)模型构建优化损失函数API的使用
1、nn.Modulenn.Module是torch.nn提供的一个类,是pytorch中我们自定义网络的一个基类,这个类中定义了 很多有用的方法。原创 2021-08-09 16:09:37 · 235 阅读 · 0 评论 -
(一)张量的创建和属性
1、torch.Tensor()是一种包含单一数据类型元素的多维矩阵,是默认的tensor类型(torch.FlaotTensor)的简称。array1=np.arange(12).reshape(3,4) #生成一个列表array1=torch.Tensor(array1)print(array1)2、一个空张量tensor可以通过规定其大小来构建:torch.IntTensor(2, 4).zero_()0 0 0 00 0 0 0[torch.IntTensor of..原创 2021-08-09 10:51:22 · 154 阅读 · 0 评论 -
pytorch指定GPU训练
主要讲单机多卡(单主机多GPUs训练)使用多卡训练的方式有很多,当然前提是我们的设备中存在多个GPU:使用命令nvidia-smi查看当前Ubuntu平台的GPU数量,其中每个GPU被编上了序号:[0,1,2,3]0. 显卡编号(什么是主卡)在默认情况下,标号为0的显卡为主卡,如主机中有4块显卡,那么每张显卡的默认标号为[0,1,2,3]。如何将其他显卡设置为主卡呢?通过os.environ["CUDA_VISIBLE_DEVICES"]指定所要使用的显卡,如:os.environ[原创 2021-08-07 16:30:58 · 21668 阅读 · 4 评论