Skip to content

Allow to pass load function in ImageFolder #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 1, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions torchvision/datasets/folder.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,14 @@ def make_dataset(dir, class_to_idx):

return images


def default_loader(path):
return Image.open(path).convert('RGB')


class ImageFolder(data.Dataset):
def __init__(self, root, transform=None, target_transform=None):
def __init__(self, root, transform=None, target_transform=None,
loader=default_loader):
classes, class_to_idx = find_classes(root)
imgs = make_dataset(root, class_to_idx)

Expand All @@ -44,10 +50,11 @@ def __init__(self, root, transform=None, target_transform=None):
self.class_to_idx = class_to_idx
self.transform = transform
self.target_transform = target_transform
self.loader = loader

def __getitem__(self, index):
path, target = self.imgs[index]
img = Image.open(os.path.join(self.root, path)).convert('RGB')
img = self.loader(os.path.join(self.root, path))
if self.transform is not None:
img = self.transform(img)
if self.target_transform is not None:
Expand Down