import os
from torchvision.datasets.folder import default_loader
from torch.utils.data import Dataset
class Sample_Class(Dataset):
def __init__(self, root, train=True, transform=None, loader=default_loader):
self.root = os.path.expanduser(root)
self.transform = transform
self.loader = default_loader
In the above code snippet, what is the significance of loader=default_loader
, what exactly does that do?
This
Sample_Class
is likely imitating the behavior of ImageFolder, DatasetFolder, and ImageNet. The function should take a filename as input and return either aPIL.Image
oraccimage.Image
depending on the selected image backend.The
default_loader
function is defined in torchvision/datasets/folder.pyNote :
default_loader
by default will bePIL
reader