当前位置:网站首页>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]) # 查看训练数据集中所有图片映射到的标签值
输出:
边栏推荐
- Advanced level of C language pointer (Part 1)
- Understanding and implementation of AVL tree
- Nacos - gestion de la configuration
- Principles of Microcomputer - internal and external structure of microprocessor
- Principle and application of single chip microcomputer timer, serial communication and interrupt system
- Redis source code learning (29), compressed list learning, ziplist C (II)
- Shell脚本-特殊变量:Shell $#、$*、[email protected]、$?、$$
- Differences among tasks, threads and processes
- Personal decoration notes
- Shell脚本-if else语句
猜你喜欢

FreeRTOS learning easy notes

集团公司固定资产管理的痛点和解决方案

3. Detailed explanation of Modbus communication protocol

Nacos - 配置管理

Principles of Microcomputer - Introduction

NiO zero copy

Vsync+ triple cache mechanism +choreographer

Phishing identification app

How to manage fixed assets efficiently in one stop?

Advanced level of C language pointer (Part 1)
随机推荐
【ESP 保姆级教程】疯狂毕设篇 —— 案例:基于阿里云、小程序、Arduino的温湿度监控系统
Installing Oracle EE
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?
V79.01 Hongmeng kernel source code analysis (user mode locking) | how to use the fast lock futex (Part 1) | hundreds of blogs analyze the openharmony source code
Shell script - array definition and getting array elements
钓鱼识别app
Nacos - Configuration Management
Shell脚本-read命令:读取从键盘输入的数据
记一次redis超时
Common interview questions for embedded engineers 2-mcu_ STM32
大型工厂设备管理痛点和解决方案
Full mark standard for sports items in the high school entrance examination (Shenzhen, Anhui and Hubei)
Vsync+ triple cache mechanism +choreographer
It is designed with high bandwidth, which is almost processed into an open circuit?
小鸟识别APP
Databinding source code analysis
Public network cluster intercom +gps visual tracking | help the logistics industry with intelligent management and scheduling
Do you know how data is stored? (C integer and floating point)
JCL 和 SLF4J
JCL and slf4j