官术网_书友最值得收藏!

PyTorch dataset loaders

Pytorch includes data loaders for several datasets to help you get started. The torch.dataloader is the class used for loading datasets. The following is a list of the included torch datasets and a brief description:

Here is a typical example of how we load one of these datasets into PyTorch:

CIFAR10 is a torch.utils.dataset object. Here, we are passing it four arguments. We specify a root directory relative to where the code is running, a Boolean, train, indicating if we want the test or training set loaded, a Boolean that, if set to True, will check to see if the dataset has previously been downloaded and if not download it, and a callable transform. In this case, the transform we select is ToTensor(). This is an inbuilt class of torchvision.transforms that makes the class return a tensor. We will discuss transforms in more detail later in the chapter.

The contents of the dataset can be retrieved by a simple index lookup. We can also check the length of the entire dataset with the len function. We can also loop through the dataset in order. The following code demonstrates this:

主站蜘蛛池模板: 永川市| 辽源市| 大城县| 鹰潭市| 治多县| 上蔡县| 红桥区| 鄄城县| 栾城县| 通河县| 淮南市| 安阳市| 奉新县| 瑞金市| 松溪县| 泰顺县| 日照市| 江山市| 高邑县| 澄江县| 安宁市| 田东县| 娄底市| 三台县| 凭祥市| 封开县| 日喀则市| 富平县| 阜阳市| 延川县| 岱山县| 三原县| 双桥区| 建昌县| 西充县| 新和县| 荆门市| 沽源县| 南丰县| 广河县| 客服|