- Deep Learning with PyTorch
- Vishnu Subramanian
- 188字
- 2021-06-24 19:16:30
Loading PyTorch tensors as batches
It is a common practice in deep learning or machine learning to batch samples of images, as modern graphics processing units (GPUs) and CPUs are optimized to run operations faster on a batch of images. The batch size generally varies depending on the kind of GPU we use. Each GPU has its own memory, which can vary from 2 GB to 12 GB, and sometimes more for commercial GPUs. PyTorch provides the DataLoader class, which takes in a dataset and returns us a batch of images. It abstracts a lot of complexities in batching, such as the usage of multi-workers for applying transformation. The following code converts the previous train and valid datasets into data loaders:
train_data_gen =
torch.utils.data.DataLoader(train,batch_size=64,num_workers=3)
valid_data_gen =
torch.utils.data.DataLoader(valid,batch_size=64,num_workers=3)
The DataLoader class provides us with a lot of options and some of the most commonly used ones are as follows:
- shuffle: When true, this shuffles the images every time the data loader is called.
- num_workers: This is responsible for parallelization. It is common practice to use a number of workers fewer than the number of cores available in your machine.
- Linux KVM虛擬化架構實戰指南
- 電腦常見問題與故障排除
- 計算機應用與維護基礎教程
- 深入淺出SSD:固態存儲核心技術、原理與實戰(第2版)
- scikit-learn:Machine Learning Simplified
- 分布式系統與一致性
- 筆記本電腦使用、維護與故障排除從入門到精通(第5版)
- LPC1100系列處理器原理及應用
- Istio服務網格技術解析與實踐
- 無蘋果不生活:OS X Mountain Lion 隨身寶典
- 單片機原理與技能訓練
- 微服務實戰(Dubbox +Spring Boot+Docker)
- 單片機原理及應用
- Mastering Quantum Computing with IBM QX
- 微服務架構基礎(Spring Boot+Spring Cloud+Docker)