当前位置:网站首页>2.3 【pytorch】数据预处理 torchvision.datasets.ImageFolder
2.3 【pytorch】数据预处理 torchvision.datasets.ImageFolder
2022-07-01 09:03:00 【Enzo 想砸电脑】
我们在做训练的时候,我们免不了要读入数据,而针对数据的不同存储方式,我们也有不同的读入方法,从而方便我们将训练数据与其标签一一对应上。
方式一:使用于从一个存放了所有类别数据的文件夹中读取数据。通过重写torch.utils.data.Dataset,构建数据读取方式(自己做处理将数据和标签一一对应上),最后通过迭代器 torch.utils.data.DataLoader 的调用,按照batch_size 分批次读取数据。 如下有两个例子:
- 【kaggle数据集 - dog breed 举例】数据预处理、重写Dataset、DataLoader读取数据
- torch.utils.data.Dataset 和 torch.utils.data.DataLoader 基础使用
方式二:是我们这篇文章要介绍的 torchcvision.datasets.ImageFolder, 用于从已经归好类的文件夹中读取数据,举例如下
数据存储结构:
from torchvision import datasets, transforms
my_trans = transforms.Compose([transforms.RandomResizedCrop(224),
transforms.ToTensor()])
train_data = datasets.ImageFolder('./animals/train', transform=my_trans)
print(train_data.class_to_idx) # 查看分类名称(文件名) 对应的标签数值
print(train_data[0][0].size()) # 第一张图片的尺寸,就是我们 transforms.RandomResizedCrop 设定的裁剪尺寸
for i in range(len(train_data)):
print(train_data[i][1]) # 查看训练数据集中所有图片映射到的标签值
输出:
边栏推荐
- 毕业季,我想对你说
- Jetson Nano 安装TensorFlow GPU及问题解决
- Pain points and solutions of fixed assets management of group companies
- An overview of the design of royalties and service fees of mainstream NFT market platforms
- Is it safe to dig up money and make new shares
- [MFC development (17)] advanced list control list control
- Football and basketball game score live broadcast platform source code /app development and construction project
- Understand shallow replication and deep replication through code examples
- MySQL optimization
- [MFC development (16)] tree control
猜你喜欢

Public network cluster intercom +gps visual tracking | help the logistics industry with intelligent management and scheduling

Nacos - service discovery

ARM v7的体系结构A、R、M区别,分别应用在什么领域?
![[MFC development (17)] advanced list control list control](/img/e8/24c52cb51defc6c96b43c2ef3232ff.png)
[MFC development (17)] advanced list control list control

Embedded Engineer Interview Question 3 Hardware

Microcomputer principle - bus and its formation

MySQL optimization

Screenshot tips

TV size and viewing distance

Nacos - Configuration Management
随机推荐
Football and basketball game score live broadcast platform source code /app development and construction project
1. Connection between Jetson and camera
[MFC development (16)] tree control
又到年中,固定资产管理该何去何从?
类加载
钓鱼识别app
Understand shallow replication and deep replication through code examples
Nacos - service discovery
毕业季,我想对你说
安装Oracle EE
Imitation of Baidu search results top navigation bar effect
足球篮球体育比赛比分直播平台源码/app开发建设项目
Foundation: 3 Opencv getting started images and videos
Shell脚本-字符串
美团2022年机试
Summary of reptile knowledge points
嵌入式工程师面试题3-硬件
MySQL optimization
Centos7 shell script one click installation of JDK, Mongo, Kafka, FTP, PostgreSQL, PostGIS, pgrouting
Interrupt sharing variables with other functions and protection of critical resources