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

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.
主站蜘蛛池模板: 蒙阴县| 大连市| 水城县| 阳江市| 西青区| 庆阳市| 新巴尔虎左旗| 丰宁| 彭泽县| 织金县| 龙江县| 泸溪县| 峨眉山市| 鞍山市| 平度市| 茂名市| 贵阳市| 武威市| 阜新市| 吉安县| 保靖县| 无棣县| 莱州市| 凤台县| 团风县| 温州市| 秦皇岛市| 金塔县| 房产| 汉阴县| 婺源县| 彰武县| 迭部县| 平顶山市| 洞口县| 朝阳县| 盈江县| 株洲市| 辉南县| 三原县| 新干县|