|
9 | 9 | from typing import Callable, cast, List, Optional, Tuple, Union |
10 | 10 |
|
11 | 11 | import numpy as np |
| 12 | +import numpy.typing as npt |
12 | 13 | from PIL import Image |
13 | 14 |
|
14 | 15 | from .utils import _read_pfm, download_and_extract_archive, verify_str_arg |
@@ -92,7 +93,7 @@ def _scan_pairs( |
92 | 93 | return paths |
93 | 94 |
|
94 | 95 | @abstractmethod |
95 | | - def _read_disparity(self, file_path: str) -> Tuple[Optional[np.ndarray], Optional[np.ndarray]]: |
| 96 | + def _read_disparity(self, file_path: str) -> Tuple[Optional[npt.NDArray], Optional[npt.NDArray]]: |
96 | 97 | # function that returns a disparity map and an occlusion map |
97 | 98 | pass |
98 | 99 |
|
@@ -178,7 +179,7 @@ def __init__(self, root: Union[str, Path], transforms: Optional[Callable] = None |
178 | 179 | disparities = self._scan_pairs(left_disparity_pattern, right_disparity_pattern) |
179 | 180 | self._disparities = disparities |
180 | 181 |
|
181 | | - def _read_disparity(self, file_path: str) -> Tuple[np.ndarray, None]: |
| 182 | + def _read_disparity(self, file_path: str) -> Tuple[npt.NDArray, None]: |
182 | 183 | disparity_map = _read_pfm_file(file_path) |
183 | 184 | disparity_map = np.abs(disparity_map) # ensure that the disparity is positive |
184 | 185 | valid_mask = None |
@@ -257,7 +258,7 @@ def __init__(self, root: Union[str, Path], split: str = "train", transforms: Opt |
257 | 258 | else: |
258 | 259 | self._disparities = list((None, None) for _ in self._images) |
259 | 260 |
|
260 | | - def _read_disparity(self, file_path: str) -> Tuple[Optional[np.ndarray], None]: |
| 261 | + def _read_disparity(self, file_path: str) -> Tuple[Optional[npt.NDArray], None]: |
261 | 262 | # test split has no disparity maps |
262 | 263 | if file_path is None: |
263 | 264 | return None, None |
@@ -345,7 +346,7 @@ def __init__(self, root: Union[str, Path], split: str = "train", transforms: Opt |
345 | 346 | else: |
346 | 347 | self._disparities = list((None, None) for _ in self._images) |
347 | 348 |
|
348 | | - def _read_disparity(self, file_path: str) -> Tuple[Optional[np.ndarray], None]: |
| 349 | + def _read_disparity(self, file_path: str) -> Tuple[Optional[npt.NDArray], None]: |
349 | 350 | # test split has no disparity maps |
350 | 351 | if file_path is None: |
351 | 352 | return None, None |
@@ -565,7 +566,7 @@ def _read_img(self, file_path: Union[str, Path]) -> Image.Image: |
565 | 566 | file_path = random.choice(ambient_file_paths) # type: ignore |
566 | 567 | return super()._read_img(file_path) |
567 | 568 |
|
568 | | - def _read_disparity(self, file_path: str) -> Union[Tuple[None, None], Tuple[np.ndarray, np.ndarray]]: |
| 569 | + def _read_disparity(self, file_path: str) -> Union[Tuple[None, None], Tuple[npt.NDArray, npt.NDArray]]: |
569 | 570 | # test split has not disparity maps |
570 | 571 | if file_path is None: |
571 | 572 | return None, None |
@@ -694,7 +695,7 @@ def __init__( |
694 | 695 | disparities = self._scan_pairs(left_disparity_pattern, right_disparity_pattern) |
695 | 696 | self._disparities += disparities |
696 | 697 |
|
697 | | - def _read_disparity(self, file_path: str) -> Tuple[np.ndarray, None]: |
| 698 | + def _read_disparity(self, file_path: str) -> Tuple[npt.NDArray, None]: |
698 | 699 | disparity_map = np.asarray(Image.open(file_path), dtype=np.float32) |
699 | 700 | # unsqueeze the disparity map into (C, H, W) format |
700 | 701 | disparity_map = disparity_map[None, :, :] / 32.0 |
@@ -788,7 +789,7 @@ def __init__(self, root: Union[str, Path], variant: str = "single", transforms: |
788 | 789 | right_disparity_pattern = str(root / s / split_prefix[s] / "*.right.depth.png") |
789 | 790 | self._disparities += self._scan_pairs(left_disparity_pattern, right_disparity_pattern) |
790 | 791 |
|
791 | | - def _read_disparity(self, file_path: str) -> Tuple[np.ndarray, None]: |
| 792 | + def _read_disparity(self, file_path: str) -> Tuple[npt.NDArray, None]: |
792 | 793 | # (H, W) image |
793 | 794 | depth = np.asarray(Image.open(file_path)) |
794 | 795 | # as per https://research.nvidia.com/sites/default/files/pubs/2018-06_Falling-Things/readme_0.txt |
@@ -911,7 +912,7 @@ def __init__( |
911 | 912 | right_disparity_pattern = str(root / "disparity" / prefix_directories[variant] / "right" / "*.pfm") |
912 | 913 | self._disparities += self._scan_pairs(left_disparity_pattern, right_disparity_pattern) |
913 | 914 |
|
914 | | - def _read_disparity(self, file_path: str) -> Tuple[np.ndarray, None]: |
| 915 | + def _read_disparity(self, file_path: str) -> Tuple[npt.NDArray, None]: |
915 | 916 | disparity_map = _read_pfm_file(file_path) |
916 | 917 | disparity_map = np.abs(disparity_map) # ensure that the disparity is positive |
917 | 918 | valid_mask = None |
@@ -1020,7 +1021,7 @@ def _get_occlussion_mask_paths(self, file_path: str) -> Tuple[str, str]: |
1020 | 1021 |
|
1021 | 1022 | return occlusion_path, outofframe_path |
1022 | 1023 |
|
1023 | | - def _read_disparity(self, file_path: str) -> Union[Tuple[None, None], Tuple[np.ndarray, np.ndarray]]: |
| 1024 | + def _read_disparity(self, file_path: str) -> Union[Tuple[None, None], Tuple[npt.NDArray, npt.NDArray]]: |
1024 | 1025 | if file_path is None: |
1025 | 1026 | return None, None |
1026 | 1027 |
|
@@ -1101,7 +1102,7 @@ def __init__(self, root: Union[str, Path], split: str = "train", transforms: Opt |
1101 | 1102 | right_disparity_pattern = str(root / "*" / "right_disp.png") |
1102 | 1103 | self._disparities = self._scan_pairs(left_disparity_pattern, right_disparity_pattern) |
1103 | 1104 |
|
1104 | | - def _read_disparity(self, file_path: str) -> Tuple[np.ndarray, None]: |
| 1105 | + def _read_disparity(self, file_path: str) -> Tuple[npt.NDArray, None]: |
1105 | 1106 | disparity_map = np.asarray(Image.open(file_path), dtype=np.float32) |
1106 | 1107 | # unsqueeze disparity to (C, H, W) |
1107 | 1108 | disparity_map = disparity_map[None, :, :] / 1024.0 |
@@ -1195,7 +1196,7 @@ def __init__(self, root: Union[str, Path], split: str = "train", transforms: Opt |
1195 | 1196 | disparity_pattern = str(root / anot_dir / "*" / "disp0GT.pfm") |
1196 | 1197 | self._disparities = self._scan_pairs(disparity_pattern, None) |
1197 | 1198 |
|
1198 | | - def _read_disparity(self, file_path: str) -> Union[Tuple[None, None], Tuple[np.ndarray, np.ndarray]]: |
| 1199 | + def _read_disparity(self, file_path: str) -> Union[Tuple[None, None], Tuple[npt.NDArray, npt.NDArray]]: |
1199 | 1200 | # test split has no disparity maps |
1200 | 1201 | if file_path is None: |
1201 | 1202 | return None, None |
|
0 commit comments