当前位置:网站首页>【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 transparent OLED displays 2022-2028: Research Report on technology, participants, trends, market size and share
- 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
- Global and Chinese market of lighting control components 2022-2028: Research Report on technology, participants, trends, market size and share
- Find books ()
- Zzuli:1056 lucky numbers
- Solve the problem that PR cannot be installed on win10 system. Pr2021 version -premiere Pro 2021 official Chinese version installation tutorial
- Global and Chinese market of trimethylamine 2022-2028: Research Report on technology, participants, trends, market size and share
- 5.4-5.5
- Explanation of time complexity and space complexity
- Yolov5 advanced seven target tracking latest environment construction (II)
猜你喜欢

Detailed explanation of four modes of distributed transaction (Seata)

Dllexport and dllimport

Bucket sorting in C language

How does vs+qt set the software version copyright, obtain the software version and display the version number?
![[opengl] advanced chapter of texture - principle of flowmap](/img/dd/6208122fcc578caaf098301b185e03.jpg)
[opengl] advanced chapter of texture - principle of flowmap

C language DUP function

Zero copy underlying analysis

My QT learning path -- how qdatetimeedit is empty

Dllexport et dllimport

C language fcntl function
随机推荐
[graphics] adaptive shadow map
Zzuli: cumulative sum of 1050 factorials
Zzuli:1053 sine function
创业团队如何落地敏捷测试,提升质量效能?丨声网开发者创业讲堂 Vol.03
Tensor ellipsis (three points) slice
[ue4] geometry drawing pipeline
Global and Chinese market of trimethylamine 2022-2028: Research Report on technology, participants, trends, market size and share
My QT learning path -- how qdatetimeedit is empty
[engine development] in depth GPU and rendering optimization (basic)
Global and Chinese market of marketing automation 2022-2028: Research Report on technology, participants, trends, market size and share
7-3 rental (20 points)
Zzuli:1043 max
Bucket sorting in C language
PHP GD image upload bypass
556. The next larger element III: simple construction simulation questions
C language fcntl function
Yolov5 series (I) -- network visualization tool netron
Global and Chinese markets for sterile packaging 2022-2028: Research Report on technology, participants, trends, market size and share
NOI OPENJUDGE 1.4(15)
Zero copy underlying analysis