pytorch
文章平均质量分 58
alien丿明天
这个作者很懒,什么都没留下…
展开
-
深度学习中的归纳性偏好
深度学习的归纳性偏好介绍1.CNN inductive bias2. RNN inductive bias3. GNN inductive bias4.Attention bias介绍学习的方法会对学习的问题做一些关于目标函数的必要假设,称为归纳偏置。西瓜书解释:机器学习算法在学习过程中对某种类型假设的偏好,称为归纳性偏好。归纳性偏好可以看作是学习算法自身在一个庞大的假设空间中对假设进行选择的启发式价值观。深度神经网络偏好的认为层次化处理信息有更好的效果。网络越深效果越好。1.CNN induct原创 2022-04-11 16:07:58 · 1115 阅读 · 0 评论 -
数据增强---Mixup和Cutmix
数据增强---Mixup介绍1.Mixup2.Cutmix介绍1.Mixup是一种运用在计算机视觉中的对图像进行混类增强的算法,它可以将不同类之间的图像进行混合,从而扩充训练数据集。论文:https://arxiv.org/abs/1710.09412源码:https://github.com/facebookresearch/mixup-cifar10mixup就是选两个不同batch的样本按照一定的权重合成一个新的样本和标签使用方法from timm.data import Mixup原创 2022-04-11 10:26:36 · 2030 阅读 · 0 评论 -
torch.nn.utils.clip_grad_norm_ 梯度裁剪
Pytorch 梯度裁剪介绍介绍直接看源代码吧,源代码比较简单def clip_grad_norm_( parameters: _tensor_or_tensors, max_norm: float, norm_type: float = 2.0, error_if_nonfinite: bool = False) -> torch.Tensor: r"""Clips gradient norm of an iterable of parameters.原创 2022-04-09 21:51:33 · 979 阅读 · 0 评论 -
Pytorch torch.cuda.amp 自动混合精度
自动混合精度Pytorch的自动混合精度是由torch.cuda.amp模块带来的from torch.cuda.amp import autocast as autocastPytorch的amp模块里面有两种精度的Tensor,torch.FloatTensor和torch.HalfTensor。torch.cuda.amp只能在cuda上使用,这个功能正是NVIDIA的开发人员贡献到Pytorch项目中的。而只有支持Tensor core的CUDA硬件才能享受到AMP的好处(例如:2080Ti原创 2022-04-09 20:23:36 · 1487 阅读 · 0 评论 -
Pytorch模型训练中 使用的 MetricLogger类总结
MetricLogger类这个类主要用来打印输出训练的时候产生的一些数据首先搬出我们看到的源代码,主要是在看何凯明大佬的MAE项目代码的时候遇到了,一起来学习一下~~MAE-github官方源代码:https://github.com/facebookresearch/mae源代码:class SmoothedValue(object): """Track a series of values and provide access to smoothed values over a原创 2022-04-09 19:00:26 · 6161 阅读 · 3 评论 -
torch.distributed.barrier()
torch.distributed.barrier作用Pytorch在分布式训练过程中,对于数据的读取是采用主进程预读取并缓存,然后其它进程从缓存中读取,不同进程之间的同步通信需要通过torch.distributed.barrier()实现t = torch.tensor([self.count, self.total], dtype=torch.float64, device='cuda')dist.barrier()dist.all_reduce(t)主要就是通过对其他进程进行阻塞来等所有原创 2022-04-09 11:28:25 · 6259 阅读 · 0 评论 -
torch.nn.parameter.Parameter
torch.nn.parameter.Parameter介绍介绍Parameter是张量tensor的一个子类:class Parameter(torch.Tensor)一般是在需要用户自己创建一些张量加到模型的学习模块里面去学习,比如在注意力机制里面,我们一般可以加入可学习的位置编码pos_emb = torch.rand(1,num_patch,dim)pos_emb = torch.nn.parameter.Parameter(pos_emb, requires_grad=True)原创 2022-04-09 11:14:06 · 526 阅读 · 1 评论 -
Pytorch 多GPU训练
Pytorch 多GPU训练介绍使用1.1 torch.nn.DataParallel1.2 torch.nn.parallel.DistributedDataParallel介绍Pytorch 的分布式训练主要是使用torch.distributed来实现的,它主要由三个组件构成:1.Distributed Data-Parallel Training(DDP):它是一个single-program和multi-process。使用DDP组件的时候,模型被复制到每一个进程也就是GPU里面,每个mod原创 2022-04-09 11:01:44 · 5044 阅读 · 0 评论 -
pytorch 源代码实现 PIL.image、Tensor 、numpy数据类型之间的转换
pytorch 源代码实现 PIL.image、Tensor 、numpy数据类型之间的转换class ToTensor1.源码阅读:class ToTensor2.源码阅读:to_tensor()2.1源码理解:2.1.1 handle numpy array2.1.2 handle accimage.Image2.1.3 handle PIL Imageclass PILtoTensor1. 源码阅读:class PILToTensor2. 源码阅读: F.pil_to_tensor(pic)class原创 2022-04-07 11:00:34 · 1595 阅读 · 0 评论 -
PIL.image数据转换为Numpy和Tensor
PIL.image数据转换为Numpy和Tensorimport numpy as np from PIL import Imageimport torch ##PIL.Imagepil_img = Image.open('./dog.jpg').convert('RGB')print(type(pil_img))##<class 'PIL.Image.Image'>## ToNumpynp_img = np.array(pil_img, dtype=np.uint8)原创 2022-04-07 09:48:38 · 4150 阅读 · 0 评论