当前位置:网站首页>【pytorch学习笔记】Transforms
【pytorch学习笔记】Transforms
2022-07-03 14:53:00 【liiiiiiiiiiiiike】
Transforms
所有torchvision数据集都有两个参数transform和target_transform,前者对图像增强,后者是对标签处理(标签平滑)。Fashionmnist是PIL图像格式,标签是整数。对于训练,需要将特征转换成归一化后的tensor,并将标签进行one-hot编码方便softmax。可以使用ToTensor和Lambda。
import torch
from torchvision import datasets
from torchvision.transforms import ToTensor, Lambda
ds = datasets.FashionMNIST(
root="data",
train=True,
download=True,
transform=ToTensor(),
target_transform=Lambda(lambda y: torch.zeros(10, dtype=torch.float).scatter_(0, torch.tensor(y), value=1))
)
ToTensor()
ToTensor()将PIL图像或者ndarray转换为FloatTensor,并将像素点归一化到[0,1]
边栏推荐
- [opengl] pre bake using computational shaders
- Neon global and Chinese markets 2022-2028: Research Report on technology, participants, trends, market size and share
- Zzuli:1052 sum of sequence 4
- PS tips - draw green earth with a brush
- TPS61170QDRVRQ1
- Yolov5 advanced nine target tracking example 1
- [wechat applet] wxss template style
- Zzuli:1055 rabbit reproduction
- 4-33--4-35
- C string format (decimal point retention / decimal conversion, etc.)
猜你喜欢

Série yolov5 (i) - - netron, un outil de visualisation de réseau

Dllexport and dllimport
![[ue4] geometry drawing pipeline](/img/30/9fcf83a665043fe57389d44c2e16a8.jpg)
[ue4] geometry drawing pipeline

C language fcntl function
![[opengl] advanced chapter of texture - principle of flowmap](/img/dd/6208122fcc578caaf098301b185e03.jpg)
[opengl] advanced chapter of texture - principle of flowmap

4-24--4-28

Implement Gobang with C language

C language DUP function

Open under vs2019 UI file QT designer flash back problem

QT program font becomes larger on computers with different resolutions, overflowing controls
随机推荐
【微信小程序】WXSS 模板样式
Centos7 deployment sentry redis (with architecture diagram, clear and easy to understand)
dllexport和dllimport
Awvs batch operation script
7-3 count the number of words in a line of text
[combinatorics] permutation and combination (set combination, one-to-one correspondence model analysis example)
2021-10-16 initial programming
Yolov5 advanced nine target tracking example 1
Vs+qt application development, set software icon icon
The picture quality has been improved! LR enhancement details_ Lightroom turns on AI photo detail enhancement: picture clarity increases by 30%
Yolov5进阶之八 高低版本格式转换问题
Tensor 省略号(三个点)切片
Neon global and Chinese markets 2022-2028: Research Report on technology, participants, trends, market size and share
Introduction to opengl4.0 tutorial computing shaders
406. 根据身高重建队列
Zzuli:1058 solving inequalities
PHP GD image upload bypass
[wechat applet] wxss template style
7-9 one way in, two ways out (25 points)
Yolov5进阶之九 目标追踪实例1