Skip to content

Commit faf19ff

Browse files
NicolasHugfacebook-github-bot
authored andcommitted
Backout D64619891 for torchvision
Summary: Changes to torchvision weren't exported to GitHub properly, and that's now creating conflicts. Reviewed By: vmoens Differential Revision: D68022237 fbshipit-source-id: 2adb3b0e7f5c47619397d5e6ef41c7c0f5019025
1 parent 78052c8 commit faf19ff

File tree

15 files changed

+37
-52
lines changed

15 files changed

+37
-52
lines changed

references/depth/stereo/train.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from typing import List, Union
66

77
import numpy as np
8-
import numpy.typing as npt
98
import torch
109
import torch.distributed as dist
1110
import torchvision.models.optical_flow
@@ -34,7 +33,7 @@ def make_stereo_flow(flow: Union[torch.Tensor, List[torch.Tensor]], model_out_ch
3433
return flow
3534

3635

37-
def make_lr_schedule(args: argparse.Namespace, optimizer: torch.optim.Optimizer) -> npt.NDArray:
36+
def make_lr_schedule(args: argparse.Namespace, optimizer: torch.optim.Optimizer) -> np.ndarray:
3837
"""Helper function to return a learning rate scheduler for CRE-stereo"""
3938
if args.decay_after_steps < args.warmup_steps:
4039
raise ValueError(f"decay_after_steps: {args.function} must be greater than warmup_steps: {args.warmup_steps}")

references/depth/stereo/visualization.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from typing import List
33

44
import numpy as np
5-
import numpy.typing as npt
65
import torch
76
from torch import Tensor
87
from torchvision.utils import make_grid
@@ -65,7 +64,7 @@ def make_training_sample_grid(
6564
disparities: Tensor,
6665
masks: Tensor,
6766
predictions: List[Tensor],
68-
) -> npt.NDArray:
67+
) -> np.ndarray:
6968
# detach images and renormalize to [0, 1]
7069
images_left = left_images.detach().cpu() * 0.5 + 0.5
7170
images_right = right_images.detach().cpu() * 0.5 + 0.5
@@ -85,7 +84,7 @@ def make_training_sample_grid(
8584

8685

8786
@torch.no_grad()
88-
def make_disparity_sequence_grid(predictions: List[Tensor], disparities: Tensor) -> npt.NDArray:
87+
def make_disparity_sequence_grid(predictions: List[Tensor], disparities: Tensor) -> np.ndarray:
8988
# right most we will be adding the ground truth
9089
seq_len = len(predictions) + 1
9190
predictions = list(map(lambda x: x[:, :1, :, :].detach().cpu(), predictions + [disparities]))

test/datasets_utils.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
from typing import Any, Callable, Dict, Iterator, List, Optional, Sequence, Tuple, Union
1919

2020
import numpy as np
21-
import numpy.typing as npt
2221

2322
import PIL
2423
import PIL.Image
@@ -826,8 +825,8 @@ def size(idx: int) -> Tuple[int, int, int]:
826825
def shape_test_for_stereo(
827826
left: PIL.Image.Image,
828827
right: PIL.Image.Image,
829-
disparity: Optional[npt.NDArray] = None,
830-
valid_mask: Optional[npt.NDArray] = None,
828+
disparity: Optional[np.ndarray] = None,
829+
valid_mask: Optional[np.ndarray] = None,
831830
):
832831
left_dims = get_dimensions(left)
833832
right_dims = get_dimensions(right)

torchvision/datasets/_optical_flow.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from typing import Callable, List, Optional, Tuple, Union
77

88
import numpy as np
9-
import numpy.typing as npt
109
import torch
1110
from PIL import Image
1211

@@ -165,7 +164,7 @@ def __getitem__(self, index: int) -> Union[T1, T2]:
165164
"""
166165
return super().__getitem__(index)
167166

168-
def _read_flow(self, file_name: str) -> npt.NDArray:
167+
def _read_flow(self, file_name: str) -> np.ndarray:
169168
return _read_flo(file_name)
170169

171170

@@ -226,7 +225,7 @@ def __getitem__(self, index: int) -> Union[T1, T2]:
226225
"""
227226
return super().__getitem__(index)
228227

229-
def _read_flow(self, file_name: str) -> Tuple[npt.NDArray, npt.NDArray]:
228+
def _read_flow(self, file_name: str) -> Tuple[np.ndarray, np.ndarray]:
230229
return _read_16bits_png_with_flow_and_valid_mask(file_name)
231230

232231

@@ -294,7 +293,7 @@ def __getitem__(self, index: int) -> Union[T1, T2]:
294293
"""
295294
return super().__getitem__(index)
296295

297-
def _read_flow(self, file_name: str) -> npt.NDArray:
296+
def _read_flow(self, file_name: str) -> np.ndarray:
298297
return _read_flo(file_name)
299298

300299

@@ -392,7 +391,7 @@ def __getitem__(self, index: int) -> Union[T1, T2]:
392391
"""
393392
return super().__getitem__(index)
394393

395-
def _read_flow(self, file_name: str) -> npt.NDArray:
394+
def _read_flow(self, file_name: str) -> np.ndarray:
396395
return _read_pfm(file_name)
397396

398397

@@ -444,7 +443,7 @@ def __init__(self, root: Union[str, Path], split: str = "train", transforms: Opt
444443
"Could not find the HD1K images. Please make sure the directory structure is correct."
445444
)
446445

447-
def _read_flow(self, file_name: str) -> Tuple[npt.NDArray, npt.NDArray]:
446+
def _read_flow(self, file_name: str) -> Tuple[np.ndarray, np.ndarray]:
448447
return _read_16bits_png_with_flow_and_valid_mask(file_name)
449448

450449
def __getitem__(self, index: int) -> Union[T1, T2]:
@@ -463,7 +462,7 @@ def __getitem__(self, index: int) -> Union[T1, T2]:
463462
return super().__getitem__(index)
464463

465464

466-
def _read_flo(file_name: str) -> npt.NDArray:
465+
def _read_flo(file_name: str) -> np.ndarray:
467466
"""Read .flo file in Middlebury format"""
468467
# Code adapted from:
469468
# http://stackoverflow.com/questions/28013200/reading-middlebury-flow-files-with-python-bytes-array-numpy
@@ -480,7 +479,7 @@ def _read_flo(file_name: str) -> npt.NDArray:
480479
return data.reshape(h, w, 2).transpose(2, 0, 1)
481480

482481

483-
def _read_16bits_png_with_flow_and_valid_mask(file_name: str) -> Tuple[npt.NDArray, npt.NDArray]:
482+
def _read_16bits_png_with_flow_and_valid_mask(file_name: str) -> Tuple[np.ndarray, np.ndarray]:
484483

485484
flow_and_valid = decode_png(read_file(file_name)).to(torch.float32)
486485
flow, valid_flow_mask = flow_and_valid[:2, :, :], flow_and_valid[2, :, :]

torchvision/datasets/_stereo_matching.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
from typing import Callable, cast, List, Optional, Tuple, Union
1010

1111
import numpy as np
12-
import numpy.typing as npt
1312
from PIL import Image
1413

1514
from .utils import _read_pfm, download_and_extract_archive, verify_str_arg
@@ -93,7 +92,7 @@ def _scan_pairs(
9392
return paths
9493

9594
@abstractmethod
96-
def _read_disparity(self, file_path: str) -> Tuple[Optional[npt.NDArray], Optional[npt.NDArray]]:
95+
def _read_disparity(self, file_path: str) -> Tuple[Optional[np.ndarray], Optional[np.ndarray]]:
9796
# function that returns a disparity map and an occlusion map
9897
pass
9998

@@ -179,7 +178,7 @@ def __init__(self, root: Union[str, Path], transforms: Optional[Callable] = None
179178
disparities = self._scan_pairs(left_disparity_pattern, right_disparity_pattern)
180179
self._disparities = disparities
181180

182-
def _read_disparity(self, file_path: str) -> Tuple[npt.NDArray, None]:
181+
def _read_disparity(self, file_path: str) -> Tuple[np.ndarray, None]:
183182
disparity_map = _read_pfm_file(file_path)
184183
disparity_map = np.abs(disparity_map) # ensure that the disparity is positive
185184
valid_mask = None
@@ -258,7 +257,7 @@ def __init__(self, root: Union[str, Path], split: str = "train", transforms: Opt
258257
else:
259258
self._disparities = list((None, None) for _ in self._images)
260259

261-
def _read_disparity(self, file_path: str) -> Tuple[Optional[npt.NDArray], None]:
260+
def _read_disparity(self, file_path: str) -> Tuple[Optional[np.ndarray], None]:
262261
# test split has no disparity maps
263262
if file_path is None:
264263
return None, None
@@ -346,7 +345,7 @@ def __init__(self, root: Union[str, Path], split: str = "train", transforms: Opt
346345
else:
347346
self._disparities = list((None, None) for _ in self._images)
348347

349-
def _read_disparity(self, file_path: str) -> Tuple[Optional[npt.NDArray], None]:
348+
def _read_disparity(self, file_path: str) -> Tuple[Optional[np.ndarray], None]:
350349
# test split has no disparity maps
351350
if file_path is None:
352351
return None, None
@@ -566,7 +565,7 @@ def _read_img(self, file_path: Union[str, Path]) -> Image.Image:
566565
file_path = random.choice(ambient_file_paths) # type: ignore
567566
return super()._read_img(file_path)
568567

569-
def _read_disparity(self, file_path: str) -> Union[Tuple[None, None], Tuple[npt.NDArray, npt.NDArray]]:
568+
def _read_disparity(self, file_path: str) -> Union[Tuple[None, None], Tuple[np.ndarray, np.ndarray]]:
570569
# test split has not disparity maps
571570
if file_path is None:
572571
return None, None
@@ -696,7 +695,7 @@ def __init__(
696695
disparities = self._scan_pairs(left_disparity_pattern, right_disparity_pattern)
697696
self._disparities += disparities
698697

699-
def _read_disparity(self, file_path: str) -> Tuple[npt.NDArray, None]:
698+
def _read_disparity(self, file_path: str) -> Tuple[np.ndarray, None]:
700699
disparity_map = np.asarray(Image.open(file_path), dtype=np.float32)
701700
# unsqueeze the disparity map into (C, H, W) format
702701
disparity_map = disparity_map[None, :, :] / 32.0
@@ -790,7 +789,7 @@ def __init__(self, root: Union[str, Path], variant: str = "single", transforms:
790789
right_disparity_pattern = str(root / s / split_prefix[s] / "*.right.depth.png")
791790
self._disparities += self._scan_pairs(left_disparity_pattern, right_disparity_pattern)
792791

793-
def _read_disparity(self, file_path: str) -> Tuple[npt.NDArray, None]:
792+
def _read_disparity(self, file_path: str) -> Tuple[np.ndarray, None]:
794793
# (H, W) image
795794
depth = np.asarray(Image.open(file_path))
796795
# as per https://research.nvidia.com/sites/default/files/pubs/2018-06_Falling-Things/readme_0.txt
@@ -913,7 +912,7 @@ def __init__(
913912
right_disparity_pattern = str(root / "disparity" / prefix_directories[variant] / "right" / "*.pfm")
914913
self._disparities += self._scan_pairs(left_disparity_pattern, right_disparity_pattern)
915914

916-
def _read_disparity(self, file_path: str) -> Tuple[npt.NDArray, None]:
915+
def _read_disparity(self, file_path: str) -> Tuple[np.ndarray, None]:
917916
disparity_map = _read_pfm_file(file_path)
918917
disparity_map = np.abs(disparity_map) # ensure that the disparity is positive
919918
valid_mask = None
@@ -1022,7 +1021,7 @@ def _get_occlussion_mask_paths(self, file_path: str) -> Tuple[str, str]:
10221021

10231022
return occlusion_path, outofframe_path
10241023

1025-
def _read_disparity(self, file_path: str) -> Union[Tuple[None, None], Tuple[npt.NDArray, npt.NDArray]]:
1024+
def _read_disparity(self, file_path: str) -> Union[Tuple[None, None], Tuple[np.ndarray, np.ndarray]]:
10261025
if file_path is None:
10271026
return None, None
10281027

@@ -1103,7 +1102,7 @@ def __init__(self, root: Union[str, Path], split: str = "train", transforms: Opt
11031102
right_disparity_pattern = str(root / "*" / "right_disp.png")
11041103
self._disparities = self._scan_pairs(left_disparity_pattern, right_disparity_pattern)
11051104

1106-
def _read_disparity(self, file_path: str) -> Tuple[npt.NDArray, None]:
1105+
def _read_disparity(self, file_path: str) -> Tuple[np.ndarray, None]:
11071106
disparity_map = np.asarray(Image.open(file_path), dtype=np.float32)
11081107
# unsqueeze disparity to (C, H, W)
11091108
disparity_map = disparity_map[None, :, :] / 1024.0
@@ -1197,7 +1196,7 @@ def __init__(self, root: Union[str, Path], split: str = "train", transforms: Opt
11971196
disparity_pattern = str(root / anot_dir / "*" / "disp0GT.pfm")
11981197
self._disparities = self._scan_pairs(disparity_pattern, None)
11991198

1200-
def _read_disparity(self, file_path: str) -> Union[Tuple[None, None], Tuple[npt.NDArray, npt.NDArray]]:
1199+
def _read_disparity(self, file_path: str) -> Union[Tuple[None, None], Tuple[np.ndarray, np.ndarray]]:
12011200
# test split has no disparity maps
12021201
if file_path is None:
12031202
return None, None

torchvision/datasets/phototour.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from typing import Any, Callable, List, Optional, Tuple, Union
44

55
import numpy as np
6-
import numpy.typing as npt
76
import torch
87
from PIL import Image
98

@@ -188,7 +187,7 @@ def extra_repr(self) -> str:
188187
def read_image_file(data_dir: str, image_ext: str, n: int) -> torch.Tensor:
189188
"""Return a Tensor containing the patches"""
190189

191-
def PIL2array(_img: Image.Image) -> npt.NDArray:
190+
def PIL2array(_img: Image.Image) -> np.ndarray:
192191
"""Convert PIL image type to numpy 2D array"""
193192
return np.array(_img.getdata(), dtype=np.uint8).reshape(64, 64)
194193

torchvision/datasets/sbd.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from typing import Any, Callable, Optional, Tuple, Union
55

66
import numpy as np
7-
import numpy.typing as npt
87
from PIL import Image
98

109
from .utils import download_and_extract_archive, download_url, verify_str_arg
@@ -103,7 +102,7 @@ def _get_segmentation_target(self, filepath: str) -> Image.Image:
103102
mat = self._loadmat(filepath)
104103
return Image.fromarray(mat["GTcls"][0]["Segmentation"][0])
105104

106-
def _get_boundaries_target(self, filepath: str) -> npt.NDArray:
105+
def _get_boundaries_target(self, filepath: str) -> np.ndarray:
107106
mat = self._loadmat(filepath)
108107
return np.concatenate(
109108
[np.expand_dims(mat["GTcls"][0]["Boundaries"][0][i][0].toarray(), axis=0) for i in range(self.num_classes)],

torchvision/datasets/stl10.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from typing import Any, Callable, cast, Optional, Tuple, Union
44

55
import numpy as np
6-
import numpy.typing as npt
76
from PIL import Image
87

98
from .utils import check_integrity, download_and_extract_archive, verify_str_arg
@@ -64,7 +63,7 @@ def __init__(
6463
raise RuntimeError("Dataset not found or corrupted. You can use download=True to download it")
6564

6665
# now load the picked numpy arrays
67-
self.labels: Optional[npt.NDArray]
66+
self.labels: Optional[np.ndarray]
6867
if self.split == "train":
6968
self.data, self.labels = self.__loadfile(self.train_list[0][0], self.train_list[1][0])
7069
self.labels = cast(np.ndarray, self.labels)
@@ -130,7 +129,7 @@ def __getitem__(self, index: int) -> Tuple[Any, Any]:
130129
def __len__(self) -> int:
131130
return self.data.shape[0]
132131

133-
def __loadfile(self, data_file: str, labels_file: Optional[str] = None) -> Tuple[npt.NDArray, Optional[npt.NDArray]]:
132+
def __loadfile(self, data_file: str, labels_file: Optional[str] = None) -> Tuple[np.ndarray, Optional[np.ndarray]]:
134133
labels = None
135134
if labels_file:
136135
path_to_labels = os.path.join(self.root, self.base_folder, labels_file)

torchvision/datasets/utils.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
from urllib.parse import urlparse
1717

1818
import numpy as np
19-
import numpy.typing as npt
2019
import torch
2120
from torch.utils.model_zoo import tqdm
2221

@@ -435,7 +434,7 @@ def verify_str_arg(
435434
return value
436435

437436

438-
def _read_pfm(file_name: Union[str, pathlib.Path], slice_channels: int = 2) -> npt.NDArray:
437+
def _read_pfm(file_name: Union[str, pathlib.Path], slice_channels: int = 2) -> np.ndarray:
439438
"""Read file in .pfm format. Might contain either 1 or 3 channels of data.
440439
441440
Args:

torchvision/prototype/datasets/_builtin/cifar.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from typing import Any, BinaryIO, cast, Dict, Iterator, List, Optional, Tuple, Union
66

77
import numpy as np
8-
import numpy.typing as npt
98
from torchdata.datapipes.iter import Filter, IterDataPipe, Mapper
109
from torchvision.prototype.datasets.utils import Dataset, HttpResource, OnlineResource
1110
from torchvision.prototype.datasets.utils._internal import (
@@ -25,7 +24,7 @@ def __init__(self, datapipe: IterDataPipe[Dict[str, Any]], *, labels_key: str) -
2524
self.datapipe = datapipe
2625
self.labels_key = labels_key
2726

28-
def __iter__(self) -> Iterator[Tuple[npt.NDArray, int]]:
27+
def __iter__(self) -> Iterator[Tuple[np.ndarray, int]]:
2928
for mapping in self.datapipe:
3029
image_arrays = mapping["data"].reshape((-1, 3, 32, 32))
3130
category_idcs = mapping[self.labels_key]
@@ -68,7 +67,7 @@ def _unpickle(self, data: Tuple[str, io.BytesIO]) -> Dict[str, Any]:
6867
file.close()
6968
return content
7069

71-
def _prepare_sample(self, data: Tuple[npt.NDArray, int]) -> Dict[str, Any]:
70+
def _prepare_sample(self, data: Tuple[np.ndarray, int]) -> Dict[str, Any]:
7271
image_array, category_idx = data
7372
return dict(
7473
image=Image(image_array),

0 commit comments

Comments
 (0)