You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
frompathlibimportPathfromtorchvisionimportdatasets, transformsdata_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 strdataset=datasets.ImageFolder(str(data_dir), transform=transform)
# Proposed enhancement would allow thisdataset=datasets.ImageFolder(data_dir, transform=transform)
The text was updated successfully, but these errors were encountered:
Thanks for the feature request @songyuc . ImageFolder already supports Path objects, we probably just forgot to edit its type annotation. I've opened #8526 to fix that, it will be available in the next release soon, but you should already be able to use Path objects.
🚀 The feature
It would be highly beneficial for PyTorch to support
Path
objects from thepathlib
module when specifying dataset directories in functions liketorchvision.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, thePath
object is more versatile and is recommended for file system paths in Python 3. By supportingPath
objects, users can take full advantage of the functionality provided by thepathlib
module.Example
The text was updated successfully, but these errors were encountered: