diff --git a/setup.py b/setup.py index 70ba0aa2e50..8498354adb9 100644 --- a/setup.py +++ b/setup.py @@ -58,6 +58,7 @@ def write_version_file(): pytorch_dep += "==" + os.getenv("PYTORCH_VERSION") requirements = [ + "typing_extensions", "numpy", "requests", pytorch_dep, diff --git a/torchvision/datasets/stl10.py b/torchvision/datasets/stl10.py index bf7db144b8a..1ef50cf0a24 100644 --- a/torchvision/datasets/stl10.py +++ b/torchvision/datasets/stl10.py @@ -1,5 +1,5 @@ import os.path -from typing import Any, Callable, Optional, Tuple +from typing import Any, Callable, Optional, Tuple, cast import numpy as np from PIL import Image @@ -65,10 +65,12 @@ def __init__( self.labels: Optional[np.ndarray] if self.split == "train": self.data, self.labels = self.__loadfile(self.train_list[0][0], self.train_list[1][0]) + self.labels = cast(np.ndarray, self.labels) self.__load_folds(folds) elif self.split == "train+unlabeled": self.data, self.labels = self.__loadfile(self.train_list[0][0], self.train_list[1][0]) + self.labels = cast(np.ndarray, self.labels) self.__load_folds(folds) unlabeled_data, _ = self.__loadfile(self.train_list[2][0]) self.data = np.concatenate((self.data, unlabeled_data)) diff --git a/torchvision/transforms/functional_pil.py b/torchvision/transforms/functional_pil.py index fdaf5f7de1a..fb70d1969dc 100644 --- a/torchvision/transforms/functional_pil.py +++ b/torchvision/transforms/functional_pil.py @@ -4,6 +4,7 @@ import numpy as np import torch from PIL import Image, ImageOps, ImageEnhance +from typing_extensions import Literal try: import accimage @@ -130,7 +131,7 @@ def pad( img: Image.Image, padding: Union[int, List[int], Tuple[int, ...]], fill: Optional[Union[float, List[float], Tuple[float, ...]]] = 0, - padding_mode: str = "constant", + padding_mode: Literal["constant", "edge", "reflect", "symmetric"] = "constant", ) -> Image.Image: if not _is_pil_image(img): @@ -189,7 +190,7 @@ def pad( if img.mode == "P": palette = img.getpalette() img = np.asarray(img) - img = np.pad(img, ((pad_top, pad_bottom), (pad_left, pad_right)), padding_mode) + img = np.pad(img, ((pad_top, pad_bottom), (pad_left, pad_right)), mode=padding_mode) img = Image.fromarray(img) img.putpalette(palette) return img