Skip to content

Make DatasetFolder.find_classes public #3628

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 8 commits into from
Apr 7, 2021
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
10 changes: 7 additions & 3 deletions torchvision/datasets/folder.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def __init__(
) -> None:
super(DatasetFolder, self).__init__(root, transform=transform,
target_transform=target_transform)
classes, class_to_idx = self._find_classes(self.root)
classes, class_to_idx = self.find_classes(self.root)
samples = self.make_dataset(self.root, class_to_idx, extensions, is_valid_file)

self.loader = loader
Expand All @@ -202,8 +202,12 @@ def make_dataset(
) -> List[Tuple[str, int]]:
return make_dataset(directory, class_to_idx, extensions=extensions, is_valid_file=is_valid_file)

@staticmethod
def _find_classes(dir: str) -> Tuple[List[str], Dict[str, int]]:
def find_classes(self, dir: str) -> Tuple[List[str], Dict[str, int]]:
"""Same as :func:`find_classes`.

This method can be overridden to only consider
a subset of classes, or to adapt to a different dataset directory structure.
"""
return find_classes(dir)

def __getitem__(self, index: int) -> Tuple[Any, Any]:
Expand Down