|
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 |
@@ -695,7 +696,7 @@ def __init__( |
695 | 696 | disparities = self._scan_pairs(left_disparity_pattern, right_disparity_pattern) |
696 | 697 | self._disparities += disparities |
697 | 698 |
|
698 | | - def _read_disparity(self, file_path: str) -> Tuple[np.ndarray, None]: |
| 699 | + def _read_disparity(self, file_path: str) -> Tuple[npt.NDArray, None]: |
699 | 700 | disparity_map = np.asarray(Image.open(file_path), dtype=np.float32) |
700 | 701 | # unsqueeze the disparity map into (C, H, W) format |
701 | 702 | disparity_map = disparity_map[None, :, :] / 32.0 |
@@ -789,7 +790,7 @@ def __init__(self, root: Union[str, Path], variant: str = "single", transforms: |
789 | 790 | right_disparity_pattern = str(root / s / split_prefix[s] / "*.right.depth.png") |
790 | 791 | self._disparities += self._scan_pairs(left_disparity_pattern, right_disparity_pattern) |
791 | 792 |
|
792 | | - def _read_disparity(self, file_path: str) -> Tuple[np.ndarray, None]: |
| 793 | + def _read_disparity(self, file_path: str) -> Tuple[npt.NDArray, None]: |
793 | 794 | # (H, W) image |
794 | 795 | depth = np.asarray(Image.open(file_path)) |
795 | 796 | # as per https://research.nvidia.com/sites/default/files/pubs/2018-06_Falling-Things/readme_0.txt |
@@ -912,7 +913,7 @@ def __init__( |
912 | 913 | right_disparity_pattern = str(root / "disparity" / prefix_directories[variant] / "right" / "*.pfm") |
913 | 914 | self._disparities += self._scan_pairs(left_disparity_pattern, right_disparity_pattern) |
914 | 915 |
|
915 | | - def _read_disparity(self, file_path: str) -> Tuple[np.ndarray, None]: |
| 916 | + def _read_disparity(self, file_path: str) -> Tuple[npt.NDArray, None]: |
916 | 917 | disparity_map = _read_pfm_file(file_path) |
917 | 918 | disparity_map = np.abs(disparity_map) # ensure that the disparity is positive |
918 | 919 | valid_mask = None |
@@ -1021,7 +1022,7 @@ def _get_occlussion_mask_paths(self, file_path: str) -> Tuple[str, str]: |
1021 | 1022 |
|
1022 | 1023 | return occlusion_path, outofframe_path |
1023 | 1024 |
|
1024 | | - def _read_disparity(self, file_path: str) -> Union[Tuple[None, None], Tuple[np.ndarray, np.ndarray]]: |
| 1025 | + def _read_disparity(self, file_path: str) -> Union[Tuple[None, None], Tuple[npt.NDArray, npt.NDArray]]: |
1025 | 1026 | if file_path is None: |
1026 | 1027 | return None, None |
1027 | 1028 |
|
@@ -1102,7 +1103,7 @@ def __init__(self, root: Union[str, Path], split: str = "train", transforms: Opt |
1102 | 1103 | right_disparity_pattern = str(root / "*" / "right_disp.png") |
1103 | 1104 | self._disparities = self._scan_pairs(left_disparity_pattern, right_disparity_pattern) |
1104 | 1105 |
|
1105 | | - def _read_disparity(self, file_path: str) -> Tuple[np.ndarray, None]: |
| 1106 | + def _read_disparity(self, file_path: str) -> Tuple[npt.NDArray, None]: |
1106 | 1107 | disparity_map = np.asarray(Image.open(file_path), dtype=np.float32) |
1107 | 1108 | # unsqueeze disparity to (C, H, W) |
1108 | 1109 | disparity_map = disparity_map[None, :, :] / 1024.0 |
@@ -1196,7 +1197,7 @@ def __init__(self, root: Union[str, Path], split: str = "train", transforms: Opt |
1196 | 1197 | disparity_pattern = str(root / anot_dir / "*" / "disp0GT.pfm") |
1197 | 1198 | self._disparities = self._scan_pairs(disparity_pattern, None) |
1198 | 1199 |
|
1199 | | - def _read_disparity(self, file_path: str) -> Union[Tuple[None, None], Tuple[np.ndarray, np.ndarray]]: |
| 1200 | + def _read_disparity(self, file_path: str) -> Union[Tuple[None, None], Tuple[npt.NDArray, npt.NDArray]]: |
1200 | 1201 | # test split has no disparity maps |
1201 | 1202 | if file_path is None: |
1202 | 1203 | return None, None |
|
0 commit comments