当前位置:网站首页>【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]
边栏推荐
猜你喜欢

Talking about part of data storage in C language

Yolov5系列(一)——网络可视化工具netron

Byte practice surface longitude

CentOS7部署哨兵Redis(带架构图,清晰易懂)
![[ue4] Niagara's indirect draw](/img/8a/576022b5d19e1d6422ff0135c50c93.jpg)
[ue4] Niagara's indirect draw

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

Besides lying flat, what else can a 27 year old do in life?
随机推荐
Dllexport et dllimport
QT program font becomes larger on computers with different resolutions, overflowing controls
C language STR function
Zzuli:1055 rabbit reproduction
556. The next larger element III: simple construction simulation questions
[ue4] Niagara's indirect draw
Global and Chinese market of transfer case 2022-2028: Research Report on technology, participants, trends, market size and share
Vs+qt multithreading implementation -- run and movetothread
PS tips - draw green earth with a brush
Global and Chinese market of iron free motors 2022-2028: Research Report on technology, participants, trends, market size and share
Plane vector addition
Use of form text box (I) select text
Tencent internship interview sorting
The picture quality has been improved! LR enhancement details_ Lightroom turns on AI photo detail enhancement: picture clarity increases by 30%
Zzuli:1048 factorial table
牛客 BM83 字符串變形(大小寫轉換,字符串反轉,字符串替換)
406. 根据身高重建队列
Implement Gobang with C language
【Transform】【实践】使用Pytorch的torch.nn.MultiheadAttention来实现self-attention
Zzuli:1049 square sum and cubic sum