Dataset and Transforms
Next, we set up a function to load our data and subsequently perform needed transforms. This functions uses a few tools that exist within torchvision.
Dataset
torchvision.datasets.ImageFolder
is a generic data loader where images are structured as follows:
Note the directories C0, C2, and C4 are the names of the three classes in our classifier and, in this case, refer to low, medium and high levels of damage. Another noteworthy feature of torchvision's datasets is that images are not immediately loaded into memory. They are loaded one by one as needed.
Transforms
torchvision.transforms.Compose
applies a series of transformations to your data. In our function, we use Compose to perform a series of two transforms:
torchvision.transforms.Resize
which resizes your image to the specified dimensiontorchvision.transofrms.ToTensor
converts you images from PIL or numpy arrrays to a torch tensor.
In the function below, we use ImageFolder
to load our train, validation and testing data and perform the needed transformations as described above.
CVW material development is supported by NSF OAC awards 1854828, 2321040, 2323116 (UT Austin) and 2005506 (Indiana University)