当前位置:网站首页>【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]
边栏推荐
- Global and Chinese markets for flexible chips 2022-2028: Research Report on technology, participants, trends, market size and share
- [engine development] rendering architecture and advanced graphics programming
- Niuke bm83 string deformation (case conversion, string inversion, string replacement)
- 远程服务器后台挂起 nohup
- NOI OPENJUDGE 1.6(09)
- How does vs+qt set the software version copyright, obtain the software version and display the version number?
- B2020 points candy
- Zzuli:1058 solving inequalities
- NOI OPENJUDGE 1.4(15)
- [graphics] hair simulation in tressfx
猜你喜欢
Adobe Premiere Pro 15.4 has been released. It natively supports Apple M1 and adds the function of speech to text
C language DUP function
Qt—绘制其他东西
On MEM series functions of C language
dllexport和dllimport
B2020 分糖果
The picture quality has been improved! LR enhancement details_ Lightroom turns on AI photo detail enhancement: picture clarity increases by 30%
【注意力机制】【首篇ViT】DETR,End-to-End Object Detection with Transformers网络的主要组成是CNN和Transformer
To improve efficiency or increase costs, how should developers understand pair programming?
[graphics] efficient target deformation animation based on OpenGL es 3.0
随机推荐
链表有环,快慢指针走3步可以吗
mmdetection 学习率与batch_size关系
Global and Chinese markets for infrared solutions (for industrial, civil, national defense and security applications) 2022-2028: Research Report on technology, participants, trends, market size and sh
Solve the problem that PR cannot be installed on win10 system. Pr2021 version -premiere Pro 2021 official Chinese version installation tutorial
Adobe Premiere Pro 15.4 has been released. It natively supports Apple M1 and adds the function of speech to text
Global and Chinese market of air cargo logistics 2022-2028: Research Report on technology, participants, trends, market size and share
4-29——4.32
Zzuli:1056 lucky numbers
Niuke bm83 string deformation (case conversion, string inversion, string replacement)
Yolov5 advanced seven target tracking latest environment construction (II)
1017 a divided by B (20 points)
C language STR function
[opengl] bone animation blending effect
Zzuli:1059 highest score
Zzuli:1047 logarithmic table
Explanation of time complexity and space complexity
There are links in the linked list. Can you walk three steps faster or slower
【微信小程序】WXSS 模板样式
Yolov5系列(一)——网络可视化工具netron
The picture quality has been improved! LR enhancement details_ Lightroom turns on AI photo detail enhancement: picture clarity increases by 30%