文章目录
torch模块
torch.finfo/torch.iinfo
torch.finfo/torch.iinfo(type: dtype)
用途:获得某一dtype类型的位数、表示的最小数字、最大数字、最小正数
link: https://zhuanlan.zhihu.com/p/76870605
torch.chunk
torch.chunk(input, chunks, dim=0) → List of Tensors
• input: tensor
• chunks: 想切分成多少块
• dim: 对某一纬度进行切块
link: https://blog.csdn.net/weixin_30823833/article/details/96184248
torch.einsum
torch.einsum(equation: str, *operands: Tensor)
eg:dots = torch.einsum('bhid,bhjd->bhij', q, k)
# 隐含语义:但bhi,bhj固定时,得到两个长度为d的向量,元素相乘,并对d长度求和
link:https://www.cnblogs.com/mengnan/p/10319701.html
torch.register_buffer
self.register_buffer(‘running_mean’, torch.zeros(num_features))
torch.ranperm
y = torch.randperm(n)
y是把1到n这些数随机打乱得到的一个数字序列。
link: https://blog.csdn.net/wangxinsheng0901/article/details/83002573
torch.Tensor模块
torch.Tensor.masked_fill/torch._ masked_fill_
torch.Tensor.masked_fill/torch._ masked_fill_(mask,
value)
用法:mask元素中为True的位置,替换为value
link: https://blog.csdn.net/qq_41568188/article/details/107281395
torch.nn模块
nn.GELU
link: https://mp.weixin.qq.com/s/pA9JW75p9J5e5KHe3ifcBQ
nn.LayerNorm
nn.LayerNorm(normalized_shape: Union[int, List[int], Size],
eps: float = 1e-5,
elementwise_affine: bool = True)
link: https://blog.csdn.net/liuxiao214/article/details/81037416
torch.nn.functional 模块
F.pad
F.pad(input, pad, mode=‘constant’, value=0)
• input
需要扩充的tensor,可以是图像数据,抑或是特征矩阵数据
• pad
扩充维度,用于预先定义出某维度上的扩充参数
• mode
扩充方法,’constant‘, ‘reflect’ or ‘replicate’三种模式,分别表示常量,反射,复制
• value
扩充时指定补充值,但是value只在mode=’constant’有效,即使用value填充在扩充出的新维度位置,而在’reflect’和’replicate’模式下,value不可赋值
link: https://blog.csdn.net/binbinczsohu/article/details/106359426
基本知识
torchvision.transforms下的transform.py和functional.py的区别
torchvision.transforms这个包中包含resize、crop等常见的data augmentation操作,基本上PyTorch中的data augmentation操作都可以通过该接口实现。该包主要包含两个脚本:transforms.py和functional.py,前者定义了各种data augmentation的类,在每个类中通过调用functional.py中对应的函数完成data augmentation操作。
link: 添加链接描述