- 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ā)入門與應(yīng)用
- 顯卡維修知識(shí)精解
- 電腦維護(hù)與故障排除傻瓜書(Windows 10適用)
- 深入淺出SSD:固態(tài)存儲(chǔ)核心技術(shù)、原理與實(shí)戰(zhàn)
- Getting Started with Qt 5
- 電腦組裝、維護(hù)、維修全能一本通(全彩版)
- scikit-learn:Machine Learning Simplified
- 計(jì)算機(jī)組裝與維護(hù)(第3版)
- 基于Proteus仿真的51單片機(jī)應(yīng)用
- Managing Data and Media in Microsoft Silverlight 4:A mashup of chapters from Packt's bestselling Silverlight books
- 無蘋果不生活:OS X Mountain Lion 隨身寶典
- 3D Printing Blueprints
- Spring Security 3.x Cookbook
- FPGA實(shí)戰(zhàn)訓(xùn)練精粹
- 微服務(wù)架構(gòu)基礎(chǔ)(Spring Boot+Spring Cloud+Docker)