-
Notifications
You must be signed in to change notification settings - Fork 7.2k
Closed
Description
🚀 The feature
It would be highly beneficial for PyTorch to support Path objects from the pathlib module when specifying dataset directories in functions like torchvision.datasets.ImageFolder. This support would make the code more Pythonic and in line with modern Python programming practices.
Motivation, pitch
Currently, when using torchvision.datasets.ImageFolder, the dataset directory must be specified as a string. However, the Path object is more versatile and is recommended for file system paths in Python 3. By supporting Path objects, users can take full advantage of the functionality provided by the pathlib module.
Example
from pathlib import Path
from torchvision import datasets, transforms
data_dir = Path("dataset", "train")
transform = transforms.Compose([
transforms.Resize((256, 256)),
transforms.ToTensor(),
transforms.Normalize((0.485, 0.456, 0.406), (0.229, 0.224, 0.225))
])
# Currently, this requires converting Path to str
dataset = datasets.ImageFolder(str(data_dir), transform=transform)
# Proposed enhancement would allow this
dataset = datasets.ImageFolder(data_dir, transform=transform)Metadata
Metadata
Assignees
Labels
No labels