- Deep Learning with PyTorch
- Vishnu Subramanian
- 128字
- 2021-06-24 19:16:26
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.
推薦閱讀
- Cortex-M3 + μC/OS-II嵌入式系統(tǒng)開發(fā)入門與應用
- 電腦維護與故障排除傻瓜書(Windows 10適用)
- 計算機組裝與系統(tǒng)配置
- STM32嵌入式技術應用開發(fā)全案例實踐
- Building 3D Models with modo 701
- Internet of Things Projects with ESP32
- Blender Quick Start Guide
- 觸摸屏應用技術從入門到精通
- Istio實戰(zhàn)指南
- USB應用分析精粹:從設備硬件、固件到主機端程序設計
- 從企業(yè)級開發(fā)到云原生微服務:Spring Boot實戰(zhàn)
- 多媒體應用技術(第2版)
- 詳解FPGA:人工智能時代的驅動引擎
- PIC系列單片機的流碼編程
- Exceptional C++:47個C++工程難題、編程問題和解決方案(中文版)