PyTorch data processing, use of datasets, DataLoader and its tools

torchvision is a visual toolkit for PyTorch that provides many image processing tools.

datasets use the ImageFolder tool to obtain customized images and automatically generate category labels. Such as cropping, rotation, standardization, normalization, etc.

DataLoader can scramble the datasets , divide them into batches, accelerate in parallel, etc.

1. Get pictures and named tags

Use torchvision.datasets in ImageFolder tools, features:

1. The folder name is the category name

2. Automatically create labels for folders from top to bottom, 0, 1, 2, .... Class_to_idx, imgs attributes can be viewed.

3. Return the data and label of each image

 

from torchvision.datasets Import ImageFolder 

DataSet = ImageFolder ( " E: / Data / dogcat_2 / Train / " ) # Get the path, the return of all of FIG. Data, label 
Print (dataset.class_to_idx) # view category name, and the corresponding tag . 
Print (dataset.imgs)   # View the path in all the pictures, and the corresponding label

Print (DataSet [0] [. 1]) # of FIG. 1 label 
DataSet [0] [0] # Data of FIG. 1

two,

 

Guess you like

Origin www.cnblogs.com/xixixing/p/12759849.html