当前位置:网站首页>2.3 [pytorch] data preprocessing torchvision datasets. ImageFolder
2.3 [pytorch] data preprocessing torchvision datasets. ImageFolder
2022-07-01 09:08:00 【Enzo tried to smash the computer】
When we were training , We have to read in the data , Different storage methods for data , We also have different reading methods , Thus, it is convenient for us to match the training data with their labels one by one .
Mode one : It is used to read data from a folder containing all categories of data . By rewriting torch.utils.data.Dataset, Build data reading mode ( Do your own processing and match the data and labels one by one ), Finally, through the iterator torch.utils.data.DataLoader Call to , according to batch_size Read data in batches . Here are two examples :
- 【kaggle Data sets - dog breed give an example 】 Data preprocessing 、 rewrite Dataset、DataLoader Reading data
- torch.utils.data.Dataset and torch.utils.data.DataLoader Based on using
Mode two : This is what we want to introduce in this article torchcvision.datasets.ImageFolder, It is used to read data from the classified folder , Examples are as follows
Data storage structure :
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) # View category name ( file name ) Corresponding tag value
print(train_data[0][0].size()) # The size of the first picture , It's us transforms.RandomResizedCrop Set crop size
for i in range(len(train_data)):
print(train_data[i][1]) # View the tag values mapped to all pictures in the training dataset
Output :
边栏推荐
- Promise异步编程
- Input标签的type设置为number,去掉上下箭头
- Nacos - gestion de la configuration
- 序列化、监听、自定义注解
- Shell script -while loop explanation
- [interview brush 101] linked list
- Personal decoration notes
- Glitch free clock switching technology
- 【pytorch】transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))
- Imitation of Baidu search results top navigation bar effect
猜你喜欢
Principles of Microcomputer - Introduction
Performance improvement 2-3 times! The second generation Kunlun core server of Baidu AI Cloud was launched
What are the differences between the architecture a, R and m of arm V7, and in which fields are they applied?
【pytorch】2.4 卷积函数 nn.conv2d
Daily practice of C language - day 80: currency change
Nacos - Configuration Management
中小企业固定资产管理办法哪种好?
Principles of Microcomputer - internal and external structure of microprocessor
Pain points and solutions of equipment management in large factories
How to manage fixed assets well? Easy to point and move to provide intelligent solutions
随机推荐
Redis源码学习(29),压缩列表学习,ziplist.c(二)
【ESP 保姆级教程 预告】疯狂Node.js服务器篇 ——案例:ESP8266 + DHT11 +NodeJs本地服务+ MySQL数据库
Shell script -for loop and for int loop
【pytorch学习】torch.device
Microcomputer principle - bus and its formation
猿人学第20题(题目会不定时更新)
Embedded Engineer Interview Question 3 Hardware
pcl_viewer命令
3D打印Arduino 四轴飞行器
Ranking list of domestic databases in February, 2022: oceanbase regained the "three consecutive increases", and gaussdb is expected to achieve the largest increase this month
[ESP nanny level tutorial] crazy completion chapter - Case: ws2812 light control system based on Alibaba cloud, applet and Arduino
【电赛训练】红外光通信装置 2013年电赛真题
Why is the Ltd independent station a Web3.0 website!
通过 代码实例 理解 浅复制 与 深复制
Shell script - special variables: shell $, $*, [email protected], $$$
Log4j log framework
[MFC development (17)] advanced list control list control
Bird recognition app
Shell脚本-特殊变量:Shell $#、$*、[email protected]、$?、$$
Glitch free clock switching technology