当前位置:网站首页>【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]
边栏推荐
- Neon global and Chinese markets 2022-2028: Research Report on technology, participants, trends, market size and share
- Address book sorting
- Niuke bm83 string deformation (case conversion, string inversion, string replacement)
- Global and Chinese market of trimethylamine 2022-2028: Research Report on technology, participants, trends, market size and share
- 什么是Label encoding?one-hot encoding ,label encoding两种编码该如何区分和使用?
- How to color ordinary landscape photos, PS tutorial
- NOI OPENJUDGE 1.3(06)
- Byte practice surface longitude
- 2021-10-16 initial programming
- Zzuli:1043 max
猜你喜欢

Yolov5 series (I) -- network visualization tool netron

Byte practice plane longitude 2

How does vs+qt set the software version copyright, obtain the software version and display the version number?
![[engine development] in depth GPU and rendering optimization (basic)](/img/71/abf09941eb06cd91784df50891fe29.jpg)
[engine development] in depth GPU and rendering optimization (basic)

C # realizes the login interface, and the password asterisk is displayed (hide the input password)

4-24--4-28

5-1 blocking / non blocking, synchronous / asynchronous

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

【Transform】【NLP】首次提出Transformer,Google Brain团队2017年论文《Attention is all you need》

The latest M1 dedicated Au update Adobe audit CC 2021 Chinese direct installation version has solved the problems of M1 installation without flash back!
随机推荐
How does vs+qt set the software version copyright, obtain the software version and display the version number?
Global and Chinese market of optical fiber connectors 2022-2028: Research Report on technology, participants, trends, market size and share
Chapter 14 class part 1
零拷贝底层剖析
Pytorch深度学习和目标检测实战笔记
406. 根据身高重建队列
Zzuli:1052 sum of sequence 4
On MEM series functions of C language
QT program font becomes larger on computers with different resolutions, overflowing controls
什么是embedding(把物体编码为一个低维稠密向量),pytorch中nn.Embedding原理及使用
C language STR function
4-29——4.32
.NET六大设计原则个人白话理解,有误请大神指正
Zzuli:1054 monkeys eat peaches
C language DUP function
Open under vs2019 UI file QT designer flash back problem
Série yolov5 (i) - - netron, un outil de visualisation de réseau
1017 a divided by B (20 points)
Global and Chinese market of solder bars 2022-2028: Research Report on technology, participants, trends, market size and share
Global and Chinese market of postal automation systems 2022-2028: Research Report on technology, participants, trends, market size and share