Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
vision
Commits
2ba586d5
Unverified
Commit
2ba586d5
authored
Mar 18, 2024
by
Nicolas Hug
Committed by
GitHub
Mar 18, 2024
Browse files
Document that datasets support pathlib.Path (#8321)
Co-authored-by:
Philip Meier
<
github.pmeier@posteo.de
>
parent
03251754
Changes
46
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
25 additions
and
19 deletions
+25
-19
torchvision/datasets/svhn.py
torchvision/datasets/svhn.py
+4
-3
torchvision/datasets/ucf101.py
torchvision/datasets/ucf101.py
+4
-3
torchvision/datasets/usps.py
torchvision/datasets/usps.py
+4
-3
torchvision/datasets/vision.py
torchvision/datasets/vision.py
+3
-2
torchvision/datasets/voc.py
torchvision/datasets/voc.py
+6
-6
torchvision/datasets/widerface.py
torchvision/datasets/widerface.py
+4
-2
No files found.
torchvision/datasets/svhn.py
View file @
2ba586d5
import
os.path
from
typing
import
Any
,
Callable
,
Optional
,
Tuple
from
pathlib
import
Path
from
typing
import
Any
,
Callable
,
Optional
,
Tuple
,
Union
import
numpy
as
np
from
PIL
import
Image
...
...
@@ -19,7 +20,7 @@ class SVHN(VisionDataset):
This class needs `scipy <https://docs.scipy.org/doc/>`_ to load data from `.mat` format.
Args:
root (str
ing
): Root directory of the dataset where the data is stored.
root (str
or ``pathlib.Path``
): Root directory of the dataset where the data is stored.
split (string): One of {'train', 'test', 'extra'}.
Accordingly dataset is selected. 'extra' is Extra training set.
transform (callable, optional): A function/transform that takes in a PIL image
...
...
@@ -52,7 +53,7 @@ class SVHN(VisionDataset):
def
__init__
(
self
,
root
:
str
,
root
:
Union
[
str
,
Path
]
,
split
:
str
=
"train"
,
transform
:
Optional
[
Callable
]
=
None
,
target_transform
:
Optional
[
Callable
]
=
None
,
...
...
torchvision/datasets/ucf101.py
View file @
2ba586d5
import
os
from
typing
import
Any
,
Callable
,
Dict
,
List
,
Optional
,
Tuple
from
pathlib
import
Path
from
typing
import
Any
,
Callable
,
Dict
,
List
,
Optional
,
Tuple
,
Union
from
torch
import
Tensor
...
...
@@ -28,7 +29,7 @@ class UCF101(VisionDataset):
Internally, it uses a VideoClips object to handle clip creation.
Args:
root (str
ing
): Root directory of the UCF101 Dataset.
root (str
or ``pathlib.Path``
): Root directory of the UCF101 Dataset.
annotation_path (str): path to the folder containing the split files;
see docstring above for download instructions of these files
frames_per_clip (int): number of frames in a clip.
...
...
@@ -52,7 +53,7 @@ class UCF101(VisionDataset):
def
__init__
(
self
,
root
:
str
,
root
:
Union
[
str
,
Path
]
,
annotation_path
:
str
,
frames_per_clip
:
int
,
step_between_clips
:
int
=
1
,
...
...
torchvision/datasets/usps.py
View file @
2ba586d5
import
os
from
typing
import
Any
,
Callable
,
Optional
,
Tuple
from
pathlib
import
Path
from
typing
import
Any
,
Callable
,
Optional
,
Tuple
,
Union
import
numpy
as
np
from
PIL
import
Image
...
...
@@ -15,7 +16,7 @@ class USPS(VisionDataset):
and make pixel values in ``[0, 255]``.
Args:
root (str
ing
): Root directory of dataset to store``USPS`` data files.
root (str
or ``pathlib.Path``
): Root directory of dataset to store``USPS`` data files.
train (bool, optional): If True, creates dataset from ``usps.bz2``,
otherwise from ``usps.t.bz2``.
transform (callable, optional): A function/transform that takes in a PIL image
...
...
@@ -43,7 +44,7 @@ class USPS(VisionDataset):
def
__init__
(
self
,
root
:
str
,
root
:
Union
[
str
,
Path
]
,
train
:
bool
=
True
,
transform
:
Optional
[
Callable
]
=
None
,
target_transform
:
Optional
[
Callable
]
=
None
,
...
...
torchvision/datasets/vision.py
View file @
2ba586d5
import
os
from
typing
import
Any
,
Callable
,
List
,
Optional
,
Tuple
from
pathlib
import
Path
from
typing
import
Any
,
Callable
,
List
,
Optional
,
Tuple
,
Union
import
torch.utils.data
as
data
...
...
@@ -29,7 +30,7 @@ class VisionDataset(data.Dataset):
def
__init__
(
self
,
root
:
str
=
None
,
# type: ignore[assignment]
root
:
Union
[
str
,
Path
]
=
None
,
# type: ignore[assignment]
transforms
:
Optional
[
Callable
]
=
None
,
transform
:
Optional
[
Callable
]
=
None
,
target_transform
:
Optional
[
Callable
]
=
None
,
...
...
torchvision/datasets/voc.py
View file @
2ba586d5
import
collections
import
os
from
pathlib
import
Path
from
typing
import
Any
,
Callable
,
Dict
,
List
,
Optional
,
Tuple
,
Union
from
xml.etree.ElementTree
import
Element
as
ET_Element
from
.vision
import
VisionDataset
try
:
from
defusedxml.ElementTree
import
parse
as
ET_parse
except
ImportError
:
from
xml.etree.ElementTree
import
parse
as
ET_parse
from
typing
import
Any
,
Callable
,
Dict
,
List
,
Optional
,
Tuple
from
PIL
import
Image
from
.utils
import
download_and_extract_archive
,
verify_str_arg
from
.vision
import
VisionDataset
DATASET_YEAR_DICT
=
{
"2012"
:
{
...
...
@@ -67,7 +67,7 @@ class _VOCBase(VisionDataset):
def
__init__
(
self
,
root
:
str
,
root
:
Union
[
str
,
Path
]
,
year
:
str
=
"2012"
,
image_set
:
str
=
"train"
,
download
:
bool
=
False
,
...
...
@@ -121,7 +121,7 @@ class VOCSegmentation(_VOCBase):
"""`Pascal VOC <http://host.robots.ox.ac.uk/pascal/VOC/>`_ Segmentation Dataset.
Args:
root (str
ing
): Root directory of the VOC Dataset.
root (str
or ``pathlib.Path``
): Root directory of the VOC Dataset.
year (string, optional): The dataset year, supports years ``"2007"`` to ``"2012"``.
image_set (string, optional): Select the image_set to use, ``"train"``, ``"trainval"`` or ``"val"``. If
``year=="2007"``, can also be ``"test"``.
...
...
@@ -165,7 +165,7 @@ class VOCDetection(_VOCBase):
"""`Pascal VOC <http://host.robots.ox.ac.uk/pascal/VOC/>`_ Detection Dataset.
Args:
root (str
ing
): Root directory of the VOC Dataset.
root (str
or ``pathlib.Path``
): Root directory of the VOC Dataset.
year (string, optional): The dataset year, supports years ``"2007"`` to ``"2012"``.
image_set (string, optional): Select the image_set to use, ``"train"``, ``"trainval"`` or ``"val"``. If
``year=="2007"``, can also be ``"test"``.
...
...
torchvision/datasets/widerface.py
View file @
2ba586d5
import
os
from
os.path
import
abspath
,
expanduser
from
pathlib
import
Path
from
typing
import
Any
,
Callable
,
Dict
,
List
,
Optional
,
Tuple
,
Union
import
torch
...
...
@@ -13,7 +15,7 @@ class WIDERFace(VisionDataset):
"""`WIDERFace <http://shuoyang1213.me/WIDERFACE/>`_ Dataset.
Args:
root (str
ing
): Root directory where images and annotations are downloaded to.
root (str
or ``pathlib.Path``
): Root directory where images and annotations are downloaded to.
Expects the following folder structure if download=False:
.. code::
...
...
@@ -55,7 +57,7 @@ class WIDERFace(VisionDataset):
def
__init__
(
self
,
root
:
str
,
root
:
Union
[
str
,
Path
]
,
split
:
str
=
"train"
,
transform
:
Optional
[
Callable
]
=
None
,
target_transform
:
Optional
[
Callable
]
=
None
,
...
...
Prev
1
2
3
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment