当前位置:网站首页>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]) # 查看训练数据集中所有图片映射到的标签值
输出:
边栏推荐
- 通过 代码实例 理解 浅复制 与 深复制
- VSYNC+三重缓存机制+Choreographer
- Personal decoration notes
- I would like to know the process of stock registration and account opening by mobile phone? In addition, is it safe to open a mobile account?
- 【ESP 保姆级教程】疯狂毕设篇 —— 案例:基于阿里云、小程序、Arduino的WS2812灯控系统
- Performance improvement 2-3 times! The second generation Kunlun core server of Baidu AI Cloud was launched
- Do you know how data is stored? (C integer and floating point)
- Embedded Engineer Interview Question 3 Hardware
- Imitation of Baidu search results top navigation bar effect
- FreeRTOS learning easy notes
猜你喜欢

Dynamic proxy

An overview of the design of royalties and service fees of mainstream NFT market platforms
![[MFC development (16)] tree control](/img/b9/1de4330c0bd186cfe062b02478c058.png)
[MFC development (16)] tree control

猿人学第20题(题目会不定时更新)

3. Detailed explanation of Modbus communication protocol

FreeRTOS learning easy notes

FreeRTOS学习简易笔记

Only in China! Alicloud container service enters the Forrester leader quadrant

动态代理

Jetson nano installs tensorflow GPU and problem solving
随机推荐
固定资产管理系统让企业动态掌握资产情况
LogBack
【ESP 保姆级教程 预告】疯狂Node.js服务器篇 ——案例:ESP8266 + MQ系列 + NodeJs本地服务 + MySql存储
Is it safe to dig up money and make new shares
Why is the Ltd independent station a Web3.0 website!
嵌入式工程师面试-常问问题集
Full mark standard for sports items in the high school entrance examination (Shenzhen, Anhui and Hubei)
Shell script - special variables: shell $, $*, [email protected], $$$
序列化、监听、自定义注解
Set the type of the input tag to number, and remove the up and down arrows
Serialization, listening, custom annotation
Shell脚本-if else语句
Pain points and solutions of fixed assets management of group companies
TV size and viewing distance
Dynamic proxy
毕业季,我想对你说
C语言学生信息管理系统
I use flask to write the website "one"
R语言观察日志(part24)--初始化设置
Insert mathematical formula in MD document and mathematical formula in typora