current position:Home>Usage of torch.utils.data in pytorch ---- Loading Data

Usage of torch.utils.data in pytorch ---- Loading Data

2022-08-06 08:53:50chuanauc

1. We alias torch.utils.data to Dataset, ie:

from torch.utils.data import Dataset

2. View the usage of Dataset through the help() statement. In fact, there is an easy way to view the usage instructions with clearer layout:

Enter the jupyter notebook statement through the terminal in PyCharm to open the web version of jupyter notebook

Type two "?" after the function to be queried, and run it to get a well-typed help document:

A brief summary of the help documentation for Dataset is:

The Dataset class is an abstract class, all datasets must inherit this Dataset class, and all subclasses need to override the __getitem__ function
What the __getitem__ function needs to do is: get each dataand its corresponding label
At the same time, we can also selectively rewrite the __len__ function, whose default form is to return the size of the dataset
Therefore, the main thing is to lose the rewriting of these two functions:

(1) __getitem__(self, index) (2) __add__(self, other: 'Dataset[T_co]')

The original text is as follows:

3. Implementation:

The disorder of os.listdir in Python

copyright notice
author[chuanauc],Please bring the original link to reprint, thank you.
https://en.chowdera.com/2022/218/202208060848299394.html

Random recommended