书籍
https://github.com/zergtant/pytorch-handbook Pytorch指南
PyTorch 中文手册(pytorch handbook) - Pytorch中文手册
https://github.com/yunjey/pytorch-tutorial Pytorch指南3
Practical Deep Learning for Coders - Practical Deep Learning
吴恩达老师的 deeplearning.ai 课程板书
示例
Pytorch---- CIFAR10实战(训练集+测试集+验证集)完整版,逐行注释-----学习笔记_深度不学习!!的博客-CSDN博客_cifar10数据集训练
AI练手系列(一)—— 利用Pytorch训练CIFAR-10数据集_知了爱啃代码的博客-CSDN博客
Kaggle dog_vs_cat 猫狗大战数据集 极速下载_Photon117的博客-CSDN博客
Dogs vs. Cats数据集_田土豆的博客-CSDN博客 数据集下载
GitHub - jcjohnson/neural-style: Torch implementation of neural style algorithm
基础
Python之可变参数,*参数,**参数,以及传入*参数,**参数解包,*args,**kwargs的理解_叫我王员外就行的博客-CSDN博客_python 参数**
**kwargs python_python中**kwargs怎么用?_MFKc的博客-CSDN博客
python3(十三)File对象的属性_呆呆的猫的博客-CSDN博客_file的属性
Python字符串string处理详解_雪花飞龙的博客-CSDN博客_python 处理string
Python字符串拼接的四种方法_三玹的博客-CSDN博客_python字符串拼接
Tensor
pytorch中比较两个tensor是否相等 - 万物小白 - 博客园
Pytorch判断两个tensor是否相等_anshiquanshu的博客-CSDN博客_判断两个tensor是否相等
import torch a = torch.tensor([1, 2, 3, 4]) b = torch.tensor([1, 2, 3, 4]) print(a.equal(b)) # 返回结果:True import torch c = torch.tensor([1, 2, 2, 3]) d = torch.tensor([2, 2, 3, 3]) print(c.eq(d)) # 返回结果:tensor([0, 1, 0, 1], dtype=torch.uint8)
函数
Pytorch autograd,backward详解 - 知乎
Pytorch:torch.flatten()与torch.nn.Flatten()_有人比我慢吗的博客-CSDN博客_nn.flatten
class Module: def __setattr__(self, name: str, value: Union[Tensor, 'Module']) -> None: def remove_from(*dicts_or_sets): for d in dicts_or_sets: if name in d: if isinstance(d, dict): del d[name] else: d.discard(name) params = self.__dict__.get('_parameters') if isinstance(value, Parameter): if params is None: raise AttributeError( "cannot assign parameters before Module.__init__() call") remove_from(self.__dict__, self._buffers, self._modules, self._non_persistent_buffers_set) self.register_parameter(name, value) elif params is not None and name in params: if value is not None: raise TypeError("cannot assign '{}' as parameter '{}' " "(torch.nn.Parameter or None expected)" .format(torch.typename(value), name)) self.register_parameter(name, value) else: modules = self.__dict__.get('_modules') if isinstance(value, Module): if modules is None: raise AttributeError( "cannot assign module before Module.__init__() call") remove_from(self.__dict__, self._parameters, self._buffers, self._non_persistent_buffers_set) modules[name] = value elif modules is not None and name in modules: if value is not None: raise TypeError("cannot assign '{}' as child module '{}' " "(torch.nn.Module or None expected)" .format(torch.typename(value), name)) modules[name] = value else: buffers = self.__dict__.get('_buffers') if buffers is not None and name in buffers: if value is not None and not isinstance(value, torch.Tensor): raise TypeError("cannot assign '{}' as buffer '{}' " "(torch.Tensor or None expected)" .format(torch.typename(value), name)) buffers[name] = value else: object.__setattr__(self, name, value)
从上可以看出,Module中对__setattr__函数进行了重载,它会收集里面的Parameter,Module,Tensor,分别放在_parameters,_modules,_buffers中,便于后续操作里面的参数,模块。
卷积
Pytorch的nn.Conv2d()详解_风雪夜归人o的博客-CSDN博客_nn.conv2
pytorch之torch.nn.Conv2d()函数详解_夏普通的博客-CSDN博客_torch.nn.conv2d
Pytorch.nn.conv2d 过程验证(单,多通道卷积过程) - 知乎
torch.nn.MaxPool2d详解_Medlen的博客-CSDN博客_maxpool2d
PyTorch中torch.linspace的详细用法 - 知乎
【pytorch学习】torch.empty_UESTC_20172222的博客-CSDN博客_torch.empty
torchvision
torchvision.transforms解读 - dychen0408 - 博客园
PyTorch之torchvision.transforms详解[原理+代码实现]_雷恩Layne的博客-CSDN博客_pytorch torchvision.transforms
Torchvision transforms 总结_Hansry的博客-CSDN博客_torchvision transform
torchvision.transforms.ToTensor :把一个取值范围是[0,255]的PIL.Image或者shape为(H,W,C)的numpy.ndarray,转换成形状为[C,H,W],取值范围是[0,1.0]的torch.FloadTensor
torchvision.transforms.ToPILImage:将shape为(C,H,W)的Tensor或shape为(H,W,C)的numpy.ndarray转换成PIL.Image,值不变。
torchvision.transforms.Normalize(mean, std):用给定的均值和标准差分别对每个通道的数据进行正则化。具体来说,给定均值(M1,…,Mn),给定标准差(S1,…,Sn),其中n是通道数(一般是3),对每个通道进行如下操作:
output[channel] = (input[channel] - mean[channel]) / std[channel]
比如:原来的tensor是三个维度的,值在[0,1]之间,经过变换之后就到了[-1,1]
计算如下:((0,1)-0.5)/0.5=(-1,1)
PIL 库
from PIL import Image # Numpy 转 Image img = Image.fromarray(array) # Image 转 Numpy array = Image.fromarray(img)
pytorch的tensor,Image,numpy和opencv四种格式的相互转换_峰峰的猫的博客-CSDN博客_tensor转cv