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
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 (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'}.
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,
......
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 (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;
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,
......
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 (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``,
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,
......
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,
......
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 (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"``.
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 (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"``.
image_set (string, optional): Select the image_set to use, ``"train"``, ``"trainval"`` or ``"val"``. If
``year=="2007"``, can also be ``"test"``.
......
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 (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:
.. 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,
......
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