当前位置:网站首页>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 :
边栏推荐
猜你喜欢

Pain points and solutions of fixed assets management of group companies

3D printing Arduino four axis aircraft

3. Detailed explanation of Modbus communication protocol

nacos簡易實現負載均衡

Which method is good for the management of fixed assets of small and medium-sized enterprises?

Mysql 优化

Imitation of Baidu search results top navigation bar effect

I use flask to write the website "one"

Vsync+ triple cache mechanism +choreographer

Bird recognition app
随机推荐
【pytorch】2.4 卷积函数 nn.conv2d
In the middle of the year, where should fixed asset management go?
How to manage fixed assets well? Easy to point and move to provide intelligent solutions
Shell script case in statement
Shell script case in and regular expressions
Can diffusion models be regarded as an autoencoder?
Shell script -for loop and for int loop
大型工厂设备管理痛点和解决方案
Ape anthropology topic 20 (the topic will be updated from time to time)
中小企业固定资产管理办法哪种好?
Microcomputer principle - bus and its formation
Daily practice of C language - day 80: currency change
【pytorch】nn.AdaptiveMaxPool2d
Jeecg restart alarm 40001
如何做好固定资产管理?易点易动提供智能化方案
[ESP nanny level tutorial] crazy completion chapter - Case: ws2812 light control system based on Alibaba cloud, applet and Arduino
It is designed with high bandwidth, which is almost processed into an open circuit?
Redis -- lattice connects to redis cluster
AVL树的理解和实现
nacos簡易實現負載均衡