@@ -3218,5 +3218,98 @@ def test_bad_input(self):
32183218 pass
32193219
32203220
3221+ class Middlebury2014StereoTestCase (datasets_utils .ImageDatasetTestCase ):
3222+ DATASET_CLASS = datasets .Middlebury2014Stereo
3223+ ADDITIONAL_CONFIGS = datasets_utils .combinations_grid (
3224+ split = ("train" , "additional" ),
3225+ calibration = ("perfect" , "imperfect" , "both" ),
3226+ use_ambient_views = (True , False ),
3227+ )
3228+ FEATURE_TYPES = (PIL .Image .Image , PIL .Image .Image , (np .ndarray , type (None )), (np .ndarray , type (None )))
3229+
3230+ @staticmethod
3231+ def _make_scene_folder (root_dir : str , scene_name : str , split : str ) -> None :
3232+ calibrations = [None ] if split == "test" else ["-perfect" , "-imperfect" ]
3233+ root_dir = pathlib .Path (root_dir )
3234+
3235+ for c in calibrations :
3236+ scene_dir = root_dir / f"{ scene_name } { c } "
3237+ os .makedirs (scene_dir , exist_ok = True )
3238+ # make normal images first
3239+ datasets_utils .create_image_file (root = scene_dir , name = "im0.png" , size = (3 , 100 , 100 ))
3240+ datasets_utils .create_image_file (root = scene_dir , name = "im1.png" , size = (3 , 100 , 100 ))
3241+ datasets_utils .create_image_file (root = scene_dir , name = "im1E.png" , size = (3 , 100 , 100 ))
3242+ datasets_utils .create_image_file (root = scene_dir , name = "im1L.png" , size = (3 , 100 , 100 ))
3243+ # these are going to end up being gray scale images
3244+ datasets_utils .make_fake_pfm_file (h = 100 , w = 100 , file_name = scene_dir / "disp0.pfm" )
3245+ datasets_utils .make_fake_pfm_file (h = 100 , w = 100 , file_name = scene_dir / "disp1.pfm" )
3246+
3247+ def inject_fake_data (self , tmpdir , config ):
3248+ split_scene_map = {
3249+ "train" : ["Adirondack" , "Jadeplant" , "Motorcycle" , "Piano" ],
3250+ "additional" : ["Backpack" , "Bicycle1" , "Cable" , "Classroom1" ],
3251+ "test" : ["Plants" , "Classroom2E" , "Classroom2" , "Australia" ],
3252+ }
3253+
3254+ middlebury_dir = pathlib .Path (tmpdir , "Middlebury2014" )
3255+ os .makedirs (middlebury_dir , exist_ok = True )
3256+
3257+ split_dir = middlebury_dir / config ["split" ]
3258+ os .makedirs (split_dir , exist_ok = True )
3259+
3260+ num_examples = {"train" : 2 , "additional" : 3 , "test" : 4 }.get (config ["split" ], 0 )
3261+ for idx in range (num_examples ):
3262+ scene_name = split_scene_map [config ["split" ]][idx ]
3263+ self ._make_scene_folder (root_dir = split_dir , scene_name = scene_name , split = config ["split" ])
3264+
3265+ if config ["calibration" ] == "both" :
3266+ num_examples *= 2
3267+ return num_examples
3268+
3269+ def test_train_splits (self ):
3270+ for split , calibration in itertools .product (["train" , "additional" ], ["perfect" , "imperfect" , "both" ]):
3271+ with self .create_dataset (split = split , calibration = calibration ) as (dataset , _ ):
3272+ for left , right , disparity , mask in dataset :
3273+ datasets_utils .shape_test_for_stereo (left , right , disparity , mask )
3274+
3275+ def test_test_split (self ):
3276+ for split in ["test" ]:
3277+ with self .create_dataset (split = split , calibration = None ) as (dataset , _ ):
3278+ for left , right , disparity , mask in dataset :
3279+ datasets_utils .shape_test_for_stereo (left , right )
3280+
3281+ def test_augmented_view_usage (self ):
3282+ with self .create_dataset (split = "train" , use_ambient_views = True ) as (dataset , _ ):
3283+ for left , right , disparity , mask in dataset :
3284+ datasets_utils .shape_test_for_stereo (left , right , disparity , mask )
3285+
3286+ def test_value_err_train (self ):
3287+ # train set invalid
3288+ split = "train"
3289+ calibration = None
3290+ with pytest .raises (
3291+ ValueError ,
3292+ match = f"Split '{ split } ' has calibration settings, however None was provided as an argument."
3293+ f"\n Setting calibration to 'perfect' for split '{ split } '. Available calibration settings are: 'perfect', 'imperfect', 'both'." ,
3294+ ):
3295+ with self .create_dataset (split = split , calibration = calibration ):
3296+ pass
3297+
3298+ def test_value_err_test (self ):
3299+ # test set invalid
3300+ split = "test"
3301+ calibration = "perfect"
3302+ with pytest .raises (
3303+ ValueError , match = "Split 'test' has only no calibration settings, please set `calibration=None`."
3304+ ):
3305+ with self .create_dataset (split = split , calibration = calibration ):
3306+ pass
3307+
3308+ def test_bad_input (self ):
3309+ with pytest .raises (ValueError , match = "Unknown value 'bad' for argument split" ):
3310+ with self .create_dataset (split = "bad" ):
3311+ pass
3312+
3313+
32213314if __name__ == "__main__" :
32223315 unittest .main ()
0 commit comments