14
14
from .utils import _read_pfm , download_and_extract_archive , verify_str_arg
15
15
from .vision import VisionDataset
16
16
17
- T1 = Tuple [Image .Image , Image .Image , Optional [np .ndarray ], np .ndarray ]
18
- T2 = Tuple [Image .Image , Image .Image , Optional [np .ndarray ]]
17
+ T1 = tuple [Image .Image , Image .Image , Optional [np .ndarray ], np .ndarray ]
18
+ T2 = tuple [Image .Image , Image .Image , Optional [np .ndarray ]]
19
19
20
20
__all__ = ()
21
21
@@ -65,11 +65,11 @@ def _scan_pairs(
65
65
self ,
66
66
paths_left_pattern : str ,
67
67
paths_right_pattern : Optional [str ] = None ,
68
- ) -> List [ Tuple [str , Optional [str ]]]:
68
+ ) -> list [ tuple [str , Optional [str ]]]:
69
69
70
70
left_paths = list (sorted (glob (paths_left_pattern )))
71
71
72
- right_paths : List [Union [None , str ]]
72
+ right_paths : list [Union [None , str ]]
73
73
if paths_right_pattern :
74
74
right_paths = list (sorted (glob (paths_right_pattern )))
75
75
else :
@@ -92,7 +92,7 @@ def _scan_pairs(
92
92
return paths
93
93
94
94
@abstractmethod
95
- def _read_disparity (self , file_path : str ) -> Tuple [Optional [np .ndarray ], Optional [np .ndarray ]]:
95
+ def _read_disparity (self , file_path : str ) -> tuple [Optional [np .ndarray ], Optional [np .ndarray ]]:
96
96
# function that returns a disparity map and an occlusion map
97
97
pass
98
98
@@ -178,7 +178,7 @@ def __init__(self, root: Union[str, Path], transforms: Optional[Callable] = None
178
178
disparities = self ._scan_pairs (left_disparity_pattern , right_disparity_pattern )
179
179
self ._disparities = disparities
180
180
181
- def _read_disparity (self , file_path : str ) -> Tuple [np .ndarray , None ]:
181
+ def _read_disparity (self , file_path : str ) -> tuple [np .ndarray , None ]:
182
182
disparity_map = _read_pfm_file (file_path )
183
183
disparity_map = np .abs (disparity_map ) # ensure that the disparity is positive
184
184
valid_mask = None
@@ -257,7 +257,7 @@ def __init__(self, root: Union[str, Path], split: str = "train", transforms: Opt
257
257
else :
258
258
self ._disparities = list ((None , None ) for _ in self ._images )
259
259
260
- def _read_disparity (self , file_path : str ) -> Tuple [Optional [np .ndarray ], None ]:
260
+ def _read_disparity (self , file_path : str ) -> tuple [Optional [np .ndarray ], None ]:
261
261
# test split has no disparity maps
262
262
if file_path is None :
263
263
return None , None
@@ -345,7 +345,7 @@ def __init__(self, root: Union[str, Path], split: str = "train", transforms: Opt
345
345
else :
346
346
self ._disparities = list ((None , None ) for _ in self ._images )
347
347
348
- def _read_disparity (self , file_path : str ) -> Tuple [Optional [np .ndarray ], None ]:
348
+ def _read_disparity (self , file_path : str ) -> tuple [Optional [np .ndarray ], None ]:
349
349
# test split has no disparity maps
350
350
if file_path is None :
351
351
return None , None
@@ -549,7 +549,7 @@ def _read_img(self, file_path: Union[str, Path]) -> Image.Image:
549
549
When ``use_ambient_views`` is True, the dataset will return at random one of ``[im1.png, im1E.png, im1L.png]``
550
550
as the right image.
551
551
"""
552
- ambient_file_paths : List [Union [str , Path ]] # make mypy happy
552
+ ambient_file_paths : list [Union [str , Path ]] # make mypy happy
553
553
554
554
if not isinstance (file_path , Path ):
555
555
file_path = Path (file_path )
@@ -565,7 +565,7 @@ def _read_img(self, file_path: Union[str, Path]) -> Image.Image:
565
565
file_path = random .choice (ambient_file_paths ) # type: ignore
566
566
return super ()._read_img (file_path )
567
567
568
- def _read_disparity (self , file_path : str ) -> Union [Tuple [None , None ], Tuple [np .ndarray , np .ndarray ]]:
568
+ def _read_disparity (self , file_path : str ) -> Union [tuple [None , None ], tuple [np .ndarray , np .ndarray ]]:
569
569
# test split has not disparity maps
570
570
if file_path is None :
571
571
return None , None
@@ -694,7 +694,7 @@ def __init__(
694
694
disparities = self ._scan_pairs (left_disparity_pattern , right_disparity_pattern )
695
695
self ._disparities += disparities
696
696
697
- def _read_disparity (self , file_path : str ) -> Tuple [np .ndarray , None ]:
697
+ def _read_disparity (self , file_path : str ) -> tuple [np .ndarray , None ]:
698
698
disparity_map = np .asarray (Image .open (file_path ), dtype = np .float32 )
699
699
# unsqueeze the disparity map into (C, H, W) format
700
700
disparity_map = disparity_map [None , :, :] / 32.0
@@ -788,13 +788,13 @@ def __init__(self, root: Union[str, Path], variant: str = "single", transforms:
788
788
right_disparity_pattern = str (root / s / split_prefix [s ] / "*.right.depth.png" )
789
789
self ._disparities += self ._scan_pairs (left_disparity_pattern , right_disparity_pattern )
790
790
791
- def _read_disparity (self , file_path : str ) -> Tuple [np .ndarray , None ]:
791
+ def _read_disparity (self , file_path : str ) -> tuple [np .ndarray , None ]:
792
792
# (H, W) image
793
793
depth = np .asarray (Image .open (file_path ))
794
794
# as per https://research.nvidia.com/sites/default/files/pubs/2018-06_Falling-Things/readme_0.txt
795
795
# in order to extract disparity from depth maps
796
796
camera_settings_path = Path (file_path ).parent / "_camera_settings.json"
797
- with open (camera_settings_path , "r" ) as f :
797
+ with open (camera_settings_path ) as f :
798
798
# inverse of depth-from-disparity equation: depth = (baseline * focal) / (disparity * pixel_constant)
799
799
intrinsics = json .load (f )
800
800
focal = intrinsics ["camera_settings" ][0 ]["intrinsic_settings" ]["fx" ]
@@ -911,7 +911,7 @@ def __init__(
911
911
right_disparity_pattern = str (root / "disparity" / prefix_directories [variant ] / "right" / "*.pfm" )
912
912
self ._disparities += self ._scan_pairs (left_disparity_pattern , right_disparity_pattern )
913
913
914
- def _read_disparity (self , file_path : str ) -> Tuple [np .ndarray , None ]:
914
+ def _read_disparity (self , file_path : str ) -> tuple [np .ndarray , None ]:
915
915
disparity_map = _read_pfm_file (file_path )
916
916
disparity_map = np .abs (disparity_map ) # ensure that the disparity is positive
917
917
valid_mask = None
@@ -999,7 +999,7 @@ def __init__(self, root: Union[str, Path], pass_name: str = "final", transforms:
999
999
disparity_pattern = str (root / "training" / "disparities" / "*" / "*.png" )
1000
1000
self ._disparities += self ._scan_pairs (disparity_pattern , None )
1001
1001
1002
- def _get_occlussion_mask_paths (self , file_path : str ) -> Tuple [str , str ]:
1002
+ def _get_occlussion_mask_paths (self , file_path : str ) -> tuple [str , str ]:
1003
1003
# helper function to get the occlusion mask paths
1004
1004
# a path will look like .../.../.../training/disparities/scene1/img1.png
1005
1005
# we want to get something like .../.../.../training/occlusions/scene1/img1.png
@@ -1020,7 +1020,7 @@ def _get_occlussion_mask_paths(self, file_path: str) -> Tuple[str, str]:
1020
1020
1021
1021
return occlusion_path , outofframe_path
1022
1022
1023
- def _read_disparity (self , file_path : str ) -> Union [Tuple [None , None ], Tuple [np .ndarray , np .ndarray ]]:
1023
+ def _read_disparity (self , file_path : str ) -> Union [tuple [None , None ], tuple [np .ndarray , np .ndarray ]]:
1024
1024
if file_path is None :
1025
1025
return None , None
1026
1026
@@ -1101,7 +1101,7 @@ def __init__(self, root: Union[str, Path], split: str = "train", transforms: Opt
1101
1101
right_disparity_pattern = str (root / "*" / "right_disp.png" )
1102
1102
self ._disparities = self ._scan_pairs (left_disparity_pattern , right_disparity_pattern )
1103
1103
1104
- def _read_disparity (self , file_path : str ) -> Tuple [np .ndarray , None ]:
1104
+ def _read_disparity (self , file_path : str ) -> tuple [np .ndarray , None ]:
1105
1105
disparity_map = np .asarray (Image .open (file_path ), dtype = np .float32 )
1106
1106
# unsqueeze disparity to (C, H, W)
1107
1107
disparity_map = disparity_map [None , :, :] / 1024.0
@@ -1195,7 +1195,7 @@ def __init__(self, root: Union[str, Path], split: str = "train", transforms: Opt
1195
1195
disparity_pattern = str (root / anot_dir / "*" / "disp0GT.pfm" )
1196
1196
self ._disparities = self ._scan_pairs (disparity_pattern , None )
1197
1197
1198
- def _read_disparity (self , file_path : str ) -> Union [Tuple [None , None ], Tuple [np .ndarray , np .ndarray ]]:
1198
+ def _read_disparity (self , file_path : str ) -> Union [tuple [None , None ], tuple [np .ndarray , np .ndarray ]]:
1199
1199
# test split has no disparity maps
1200
1200
if file_path is None :
1201
1201
return None , None
0 commit comments