我才接触到的深度学习的一系列不那么相关的概念weight decay ,crop等等概念
来源:互联网 发布:阿里云 新网 编辑:程序博客网 时间:2024/06/05 21:54
一、weight decay(权值衰减)的使用既不是为了提高你所说的收敛精确度也不是为了提高收敛速度,其最终目的是防止过拟合。在损失函数中,weight decay是放在正则项(regularization)前面的一个系数,正则项一般指示模型的复杂度,所以weight decay的作用是调节模型复杂度对损失函数的影响,若weight decay很大,则复杂的模型损失函数的值也就大。
1、提高梯度在网络中的流动。Normalization能够使特征全部缩放到[0,1],这样在反向传播时候的梯度都是在1左右,避免了梯度消失现象。
2、提升学习速率。归一化后的数据能够快速的达到收敛。
3、减少模型训练对初始化的依赖。
PyTorch 的数据处理模块是 torchvision.transform
,只对 PIL.Image 或维度为 (H, W, C) 的图片数据进行数据预处理。由于 OpenCV 读入图片的数据维度是 (H, W, C),所以不能直接使用 torchvision.transform
处理 OpenCV 的图片数据。
1. class torchvision.transforms.Compose(transforms)
输入一个 transform
列表,将多个 transform
组合使用。
transforms.Compose([transforms.CenterCrop(10),
transfroms.ToTensor()])
2. class torchvision.transforms.Scale(size, interpolation=2)
将输入的 PIL.Image
重新改变大小成给定的 size
,其中 size
是最小边长。举一个例子,如果原图的 height > width
,那么改变大小后的图片大小是 (size*height\width, size)
。
form torchvision import transforms
from PIL import Image
crop = transforms.Scale(12)
img = Image.open('test.jpg')
print type(img)
print img.size
croped_img = crop(img)
print type(crop_img)
print type(crop_img.size)
输出结果为:
<class 'PIL.PngImagePlugin.PngImageFile'>
(10, 10, 3)
<class 'PIL.Image.Image'>
(12, 12, 3)
3. class torchvision.transforms.CenterCrop(size)
将给定的 PIL.Image
进行中心切割,得到给定的 size
,size
可以是 tuple
,(target_height, target_width)
。size
也可以是一个 Integer
,在这种情况下,切出来的图片形状是正方形。
4. class torchvision.transforms.RandomCrop(size, padding=0)
切割中心点的位置随机选取。size
可以是 tuple
也可以是 Integer
。
5. class torchvision.transforms.RandomHorizontalFlip
随机水平翻转给定的 PIL.Image
,概率为 0.5。即:一半的概率翻转,一半的概率不翻转。
6. class torchvision.transforms.RandomSizedCrop(size, interpolation=2)
先将给定的 PIL.Image
随机切,然后再 resize
成给定的 size
大小
7. class torchvision.transforms.Pad(padding, fill=0)
将给定的 PIL.Image
的所有边给定的 pad value
填充。padding
:要填充多少像素,fill
: 用什么值填充
from torchvision import transforms
form PIL import Image
padding_img = transforms.Pad(padding=10, fill=0)
img = Image.open('test.jpg')
print type(img)
print img.size
padded_img = padding(img)
print type(padded_img)
print type(padded_img.size)
输出结果为:
<class 'PIL.PngImagePlugin.PngImageFile'>
(10, 10, 3)
<class 'PIL.Image.Image'>
(30, 30, 3) # 由于上下左右都要填充 10 个像素
8. class torchvision.transforms.Normalize(mean, std)
给定均值:mean = (R, G, B)
,方差:std = (R, G, B)
,将会把 Tensor 归一化。即:Normalized_image = (image - mean) / std
。
9. class torchvision.transforms.ToTensor
把一个取值范围是 [0, 255]
的 PIL.Image 或者 shape
为 (H, W, C)
的 numpy.ndarray,转换为形状为 (C, H, W)
,取值范围是 [0, 1]
的 torch.FloatTensor
data = np.random.randint(0, 255, size=300)
img = data.reshape(10, 10, 3)
print img.shape
img_tensor = transforms.ToTensor()(img) # 转换成 tensor
print img_tensor
输出结果为:
(10, 10, 3)
(3, 10, 10)
10. class torchvision.transforms.ToPILImage
将 shape
为 (C, H, W)
的 Tensor 或者 shape
为 (H, W, C)
的 numpy.ndarray 转换成 PIL.Image
,值不变。
11. class torchvision.transforms.Lambda(lambda)
通用变换,使用 lambda
作为转换器
- 我才接触到的深度学习的一系列不那么相关的概念weight decay ,crop等等概念
- 深度学习的概念
- 机器学习 和 深度学习 的相关概念
- 迁移学习的相关概念
- J2EE相关概念的学习
- 迁移学习的相关概念
- 【深度学习系列】机器学习的概念
- 深度图的概念
- 我不知道的C++概念
- 深度学习:几个重要的数学概念
- 深度学习中遇到的一些概念
- 学习笔记一:learning rate,weight decay和momentum的理解
- Caffe中learning rate 和 weight decay 的理解
- Caffe中learning rate 和 weight decay 的理解
- Caffe中learning rate 和 weight decay 的理解
- 超参数momentum与weight-decay的作用
- [机器学习]概念学习的相关理论
- PPC的相关概念
- Java面向对象编程——多态性的实现
- 萌新理解-Java之TCP通信
- 从 Quora 的 187 个问题中学习机器学习和NLP
- 多重背包有个疑惑点
- SSL P2278 Oliver的救援 题目
- 我才接触到的深度学习的一系列不那么相关的概念weight decay ,crop等等概念
- 70. Climbing Stairs
- Gradle 安装
- Angular在页面加载很慢的时候,会出现双花括号的问题
- Ubuntu 16.04安装手动分区配置
- 【dsu on tree】Codeforces600E[Lomsat gelral]题解
- JAVA 集合 迭代器
- 与系统函数distance重名的问题
- 开门见“神” HNUST 1886 ( 区间DP )