Prepare datasets for distributed training
You've preprocessed a dataset for a precision agriculture system to help farmers monitor crop health. Now you'll load the data by creating a DataLoader and place the data on GPUs for distributed training, if GPUs are available. Note the exercise actually uses a CPU, but the code is the same for CPUs and GPUs.
Some data has been pre-loaded:
- A sample
datasetwith agricultural imagery - The
Acceleratorclass from theacceleratelibrary - The
DataLoaderclass
本练习是课程的一部分
Efficient AI Model Training with PyTorch
练习说明
- Create a
dataloaderfor the pre-defineddataset. - Place the
dataloaderon available devices using theacceleratorobject.
交互式实操练习
通过完成这段示例代码来试试这个练习。
accelerator = Accelerator()
# Create a dataloader for the pre-defined dataset
dataloader = ____(____, batch_size=32, shuffle=True)
# Place the dataloader on available devices
dataloader = accelerator.____(____)
print(accelerator.device)