10. PyTorch Tutorial---Loading Data

PyTorch includes a package called torchvision for loading and preparing datasets. It includes two basic functions, Dataset and DataLoader, for converting and loading data sets.

**Dataset**
Dataset is used to read and transform data points from a given dataset. The basic syntax of the implementation is as follows:

trainset = torchvision.datasets.CIFAR10(root='./data', train=True, download=True, transform=transform)

**DataLoader**
DataLoader is used for random arrangement and batch processing of data. It can work with multi-process workers to load data in parallel.

trainloader = torch.utils.data.DataLoader(trainset, batch_size=4, shuffle=True, num_workers=2)

Example: Loading CSV files
We use the Python package Pandas to load CSV files. The original file has the following format: (image name, 68 markers - each marker has x,y coordinates).

landmarks_frame = pd.read_csv('faces/face_landmarks.csv')

n = 65
img_name = landmarks_frame.iloc[n, 0]
landmarks = landmarks_frame.iloc[n, 1:].values
landmarks = landmarks.astype('float').reshape(-1, 2)

Guess you like

Origin blog.csdn.net/Knowledgebase/article/details/133309917