当前位置:网站首页>【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]
边栏推荐
- Dllexport and dllimport
- Piwigo 2.7.1 sqli learning
- [opengl] pre bake using computational shaders
- . Net six design principles personal vernacular understanding, please correct if there is any error
- Composite type (custom type)
- Global and Chinese markets for flexible chips 2022-2028: Research Report on technology, participants, trends, market size and share
- Global and Chinese markets for transparent OLED displays 2022-2028: Research Report on technology, participants, trends, market size and share
- Use of form text box (I) select text
- 【Transform】【NLP】首次提出Transformer,Google Brain团队2017年论文《Attention is all you need》
- How to color ordinary landscape photos, PS tutorial
猜你喜欢
![[engine development] rendering architecture and advanced graphics programming](/img/a4/3526a4e0f68e49c1aa5ce23b578781.jpg)
[engine development] rendering architecture and advanced graphics programming

Devaxpress: range selection control rangecontrol uses

B2020 points candy

Zero copy underlying analysis

Vs+qt multithreading implementation -- run and movetothread

什么是embedding(把物体编码为一个低维稠密向量),pytorch中nn.Embedding原理及使用

Remote server background hangs nohup

Rasterization: a practical implementation (2)

Qt development - scrolling digital selector commonly used in embedded system

Solve the problem that PR cannot be installed on win10 system. Pr2021 version -premiere Pro 2021 official Chinese version installation tutorial
随机推荐
[graphics] efficient target deformation animation based on OpenGL es 3.0
[combinatorics] permutation and combination (set combination, one-to-one correspondence model analysis example)
7-1 positive integer a+b (15 points)
[opengl] bone animation blending effect
Zzuli:1059 highest score
Global and Chinese market of air cargo logistics 2022-2028: Research Report on technology, participants, trends, market size and share
4-33--4-35
Byte practice surface longitude
【Transform】【实践】使用Pytorch的torch.nn.MultiheadAttention来实现self-attention
C language fcntl function
Zzuli:1056 lucky numbers
[ue4] cascading shadow CSM
Zzuli:1054 monkeys eat peaches
Global and Chinese market of transfer case 2022-2028: Research Report on technology, participants, trends, market size and share
TPS61170QDRVRQ1
7-3 count the number of words in a line of text
Zzuli:1044 failure rate
Zzuli:1047 logarithmic table
PS tips - draw green earth with a brush
QT program font becomes larger on computers with different resolutions, overflowing controls