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

DataLoader class

The DataLoader class present in PyTorch's utils class combines a dataset object along with different samplers, such as SequentialSampler and RandomSampler, and provides us with a batch of images, either using a single or multi-process iterators. Samplers are different strategies for providing data to algorithms. The following is an example of a DataLoader for our Dogs vs. Cats dataset:

dataloader = DataLoader(dogsdset,batch_size=32,num_workers=2)
for imgs , labels in dataloader:
#Apply your DL on the dataset.
pass

imgs will contain a tensor of shape (32, 224, 224, 3), where 32 represents the batch size. 

The PyTorch team also maintains two useful libraries, called torchvision and torchtext, which are built on top of the Dataset and DataLoader classes. We will use them in the relevant chapters.

主站蜘蛛池模板: 开阳县| 临沂市| 滁州市| 东方市| 乌鲁木齐市| 镇沅| 九江市| 民和| 贵阳市| 侯马市| 崇礼县| 曲麻莱县| 刚察县| 崇信县| 大渡口区| 清新县| 平乐县| 阿勒泰市| 色达县| 竹北市| 武功县| 濮阳市| 越西县| 双鸭山市| 东城区| 如东县| 荔波县| 临漳县| 灵山县| 岳池县| 介休市| 常熟市| 内乡县| 来凤县| 石泉县| 双峰县| 宣汉县| 株洲县| 闽清县| 汶上县| 沧州市|