"vscode:/vscode.git/clone" did not exist on "fca32e0565dd488a05f8957d2ba0f4c76c9db8c6"
Unverified Commit 2ba586d5 authored by Nicolas Hug's avatar Nicolas Hug Committed by GitHub
Browse files

Document that datasets support pathlib.Path (#8321)


Co-authored-by: default avatarPhilip Meier <github.pmeier@posteo.de>
parent 03251754
import os.path 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 import numpy as np
from PIL import Image from PIL import Image
...@@ -19,7 +20,7 @@ class SVHN(VisionDataset): ...@@ -19,7 +20,7 @@ class SVHN(VisionDataset):
This class needs `scipy <https://docs.scipy.org/doc/>`_ to load data from `.mat` format. This class needs `scipy <https://docs.scipy.org/doc/>`_ to load data from `.mat` format.
Args: Args:
root (string): 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'}. split (string): One of {'train', 'test', 'extra'}.
Accordingly dataset is selected. 'extra' is Extra training set. Accordingly dataset is selected. 'extra' is Extra training set.
transform (callable, optional): A function/transform that takes in a PIL image transform (callable, optional): A function/transform that takes in a PIL image
...@@ -52,7 +53,7 @@ class SVHN(VisionDataset): ...@@ -52,7 +53,7 @@ class SVHN(VisionDataset):
def __init__( def __init__(
self, self,
root: str, root: Union[str, Path],
split: str = "train", split: str = "train",
transform: Optional[Callable] = None, transform: Optional[Callable] = None,
target_transform: Optional[Callable] = None, target_transform: Optional[Callable] = None,
......
import os 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 from torch import Tensor
...@@ -28,7 +29,7 @@ class UCF101(VisionDataset): ...@@ -28,7 +29,7 @@ class UCF101(VisionDataset):
Internally, it uses a VideoClips object to handle clip creation. Internally, it uses a VideoClips object to handle clip creation.
Args: Args:
root (string): 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; annotation_path (str): path to the folder containing the split files;
see docstring above for download instructions of these files see docstring above for download instructions of these files
frames_per_clip (int): number of frames in a clip. frames_per_clip (int): number of frames in a clip.
...@@ -52,7 +53,7 @@ class UCF101(VisionDataset): ...@@ -52,7 +53,7 @@ class UCF101(VisionDataset):
def __init__( def __init__(
self, self,
root: str, root: Union[str, Path],
annotation_path: str, annotation_path: str,
frames_per_clip: int, frames_per_clip: int,
step_between_clips: int = 1, step_between_clips: int = 1,
......
import os 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 import numpy as np
from PIL import Image from PIL import Image
...@@ -15,7 +16,7 @@ class USPS(VisionDataset): ...@@ -15,7 +16,7 @@ class USPS(VisionDataset):
and make pixel values in ``[0, 255]``. and make pixel values in ``[0, 255]``.
Args: Args:
root (string): 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``, train (bool, optional): If True, creates dataset from ``usps.bz2``,
otherwise from ``usps.t.bz2``. otherwise from ``usps.t.bz2``.
transform (callable, optional): A function/transform that takes in a PIL image transform (callable, optional): A function/transform that takes in a PIL image
...@@ -43,7 +44,7 @@ class USPS(VisionDataset): ...@@ -43,7 +44,7 @@ class USPS(VisionDataset):
def __init__( def __init__(
self, self,
root: str, root: Union[str, Path],
train: bool = True, train: bool = True,
transform: Optional[Callable] = None, transform: Optional[Callable] = None,
target_transform: Optional[Callable] = None, target_transform: Optional[Callable] = None,
......
import os 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 import torch.utils.data as data
...@@ -29,7 +30,7 @@ class VisionDataset(data.Dataset): ...@@ -29,7 +30,7 @@ class VisionDataset(data.Dataset):
def __init__( def __init__(
self, self,
root: str = None, # type: ignore[assignment] root: Union[str, Path] = None, # type: ignore[assignment]
transforms: Optional[Callable] = None, transforms: Optional[Callable] = None,
transform: Optional[Callable] = None, transform: Optional[Callable] = None,
target_transform: Optional[Callable] = None, target_transform: Optional[Callable] = None,
......
import collections import collections
import os 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 xml.etree.ElementTree import Element as ET_Element
from .vision import VisionDataset
try: try:
from defusedxml.ElementTree import parse as ET_parse from defusedxml.ElementTree import parse as ET_parse
except ImportError: except ImportError:
from xml.etree.ElementTree import parse as ET_parse from xml.etree.ElementTree import parse as ET_parse
from typing import Any, Callable, Dict, List, Optional, Tuple
from PIL import Image from PIL import Image
from .utils import download_and_extract_archive, verify_str_arg from .utils import download_and_extract_archive, verify_str_arg
from .vision import VisionDataset
DATASET_YEAR_DICT = { DATASET_YEAR_DICT = {
"2012": { "2012": {
...@@ -67,7 +67,7 @@ class _VOCBase(VisionDataset): ...@@ -67,7 +67,7 @@ class _VOCBase(VisionDataset):
def __init__( def __init__(
self, self,
root: str, root: Union[str, Path],
year: str = "2012", year: str = "2012",
image_set: str = "train", image_set: str = "train",
download: bool = False, download: bool = False,
...@@ -121,7 +121,7 @@ class VOCSegmentation(_VOCBase): ...@@ -121,7 +121,7 @@ class VOCSegmentation(_VOCBase):
"""`Pascal VOC <http://host.robots.ox.ac.uk/pascal/VOC/>`_ Segmentation Dataset. """`Pascal VOC <http://host.robots.ox.ac.uk/pascal/VOC/>`_ Segmentation Dataset.
Args: Args:
root (string): 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"``. 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 image_set (string, optional): Select the image_set to use, ``"train"``, ``"trainval"`` or ``"val"``. If
``year=="2007"``, can also be ``"test"``. ``year=="2007"``, can also be ``"test"``.
...@@ -165,7 +165,7 @@ class VOCDetection(_VOCBase): ...@@ -165,7 +165,7 @@ class VOCDetection(_VOCBase):
"""`Pascal VOC <http://host.robots.ox.ac.uk/pascal/VOC/>`_ Detection Dataset. """`Pascal VOC <http://host.robots.ox.ac.uk/pascal/VOC/>`_ Detection Dataset.
Args: Args:
root (string): 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"``. 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 image_set (string, optional): Select the image_set to use, ``"train"``, ``"trainval"`` or ``"val"``. If
``year=="2007"``, can also be ``"test"``. ``year=="2007"``, can also be ``"test"``.
......
import os import os
from os.path import abspath, expanduser from os.path import abspath, expanduser
from pathlib import Path
from typing import Any, Callable, Dict, List, Optional, Tuple, Union from typing import Any, Callable, Dict, List, Optional, Tuple, Union
import torch import torch
...@@ -13,7 +15,7 @@ class WIDERFace(VisionDataset): ...@@ -13,7 +15,7 @@ class WIDERFace(VisionDataset):
"""`WIDERFace <http://shuoyang1213.me/WIDERFACE/>`_ Dataset. """`WIDERFace <http://shuoyang1213.me/WIDERFACE/>`_ Dataset.
Args: Args:
root (string): 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: Expects the following folder structure if download=False:
.. code:: .. code::
...@@ -55,7 +57,7 @@ class WIDERFace(VisionDataset): ...@@ -55,7 +57,7 @@ class WIDERFace(VisionDataset):
def __init__( def __init__(
self, self,
root: str, root: Union[str, Path],
split: str = "train", split: str = "train",
transform: Optional[Callable] = None, transform: Optional[Callable] = None,
target_transform: Optional[Callable] = None, target_transform: Optional[Callable] = None,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment