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

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:

主站蜘蛛池模板: 化德县| 都江堰市| 两当县| 留坝县| 会理县| 柳林县| 墨竹工卡县| 永兴县| 江西省| 鲜城| 麦盖提县| 周宁县| 女性| 鄢陵县| 金秀| 壤塘县| 图木舒克市| 莱阳市| 鄂尔多斯市| 呼玛县| 拉萨市| 曲周县| 河津市| 涡阳县| 秭归县| 赤壁市| 秭归县| 平果县| 江安县| 新闻| 额尔古纳市| 平泉县| 武宁县| 宁津县| 义乌市| 江西省| 漳浦县| 郓城县| 杂多县| 德阳市| 安图县|