Skip to content

Added Middlebury2014 dataset #6350

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Sep 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/source/datasets.rst
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ Stereo Matching
SintelStereo
InStereo2k
ETH3DStereo
Middlebury2014Stereo

Image pairs
~~~~~~~~~~~
Expand Down
93 changes: 93 additions & 0 deletions test/test_datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -3218,5 +3218,98 @@ def test_bad_input(self):
pass


class Middlebury2014StereoTestCase(datasets_utils.ImageDatasetTestCase):
DATASET_CLASS = datasets.Middlebury2014Stereo
ADDITIONAL_CONFIGS = datasets_utils.combinations_grid(
split=("train", "additional"),
calibration=("perfect", "imperfect", "both"),
use_ambient_views=(True, False),
)
FEATURE_TYPES = (PIL.Image.Image, PIL.Image.Image, (np.ndarray, type(None)), (np.ndarray, type(None)))

@staticmethod
def _make_scene_folder(root_dir: str, scene_name: str, split: str) -> None:
calibrations = [None] if split == "test" else ["-perfect", "-imperfect"]
root_dir = pathlib.Path(root_dir)

for c in calibrations:
scene_dir = root_dir / f"{scene_name}{c}"
os.makedirs(scene_dir, exist_ok=True)
# make normal images first
datasets_utils.create_image_file(root=scene_dir, name="im0.png", size=(3, 100, 100))
datasets_utils.create_image_file(root=scene_dir, name="im1.png", size=(3, 100, 100))
datasets_utils.create_image_file(root=scene_dir, name="im1E.png", size=(3, 100, 100))
datasets_utils.create_image_file(root=scene_dir, name="im1L.png", size=(3, 100, 100))
# these are going to end up being gray scale images
datasets_utils.make_fake_pfm_file(h=100, w=100, file_name=scene_dir / "disp0.pfm")
datasets_utils.make_fake_pfm_file(h=100, w=100, file_name=scene_dir / "disp1.pfm")

def inject_fake_data(self, tmpdir, config):
split_scene_map = {
"train": ["Adirondack", "Jadeplant", "Motorcycle", "Piano"],
"additional": ["Backpack", "Bicycle1", "Cable", "Classroom1"],
"test": ["Plants", "Classroom2E", "Classroom2", "Australia"],
}

middlebury_dir = pathlib.Path(tmpdir, "Middlebury2014")
os.makedirs(middlebury_dir, exist_ok=True)

split_dir = middlebury_dir / config["split"]
os.makedirs(split_dir, exist_ok=True)

num_examples = {"train": 2, "additional": 3, "test": 4}.get(config["split"], 0)
for idx in range(num_examples):
scene_name = split_scene_map[config["split"]][idx]
self._make_scene_folder(root_dir=split_dir, scene_name=scene_name, split=config["split"])

if config["calibration"] == "both":
num_examples *= 2
return num_examples

def test_train_splits(self):
for split, calibration in itertools.product(["train", "additional"], ["perfect", "imperfect", "both"]):
with self.create_dataset(split=split, calibration=calibration) as (dataset, _):
for left, right, disparity, mask in dataset:
datasets_utils.shape_test_for_stereo(left, right, disparity, mask)

def test_test_split(self):
for split in ["test"]:
with self.create_dataset(split=split, calibration=None) as (dataset, _):
for left, right, disparity, mask in dataset:
datasets_utils.shape_test_for_stereo(left, right)

def test_augmented_view_usage(self):
with self.create_dataset(split="train", use_ambient_views=True) as (dataset, _):
for left, right, disparity, mask in dataset:
datasets_utils.shape_test_for_stereo(left, right, disparity, mask)

def test_value_err_train(self):
# train set invalid
split = "train"
calibration = None
with pytest.raises(
ValueError,
match=f"Split '{split}' has calibration settings, however None was provided as an argument."
f"\nSetting calibration to 'perfect' for split '{split}'. Available calibration settings are: 'perfect', 'imperfect', 'both'.",
):
with self.create_dataset(split=split, calibration=calibration):
pass

def test_value_err_test(self):
# test set invalid
split = "test"
calibration = "perfect"
with pytest.raises(
ValueError, match="Split 'test' has only no calibration settings, please set `calibration=None`."
):
with self.create_dataset(split=split, calibration=calibration):
pass

def test_bad_input(self):
with pytest.raises(ValueError, match="Unknown value 'bad' for argument split"):
with self.create_dataset(split="bad"):
pass


if __name__ == "__main__":
unittest.main()
2 changes: 2 additions & 0 deletions torchvision/datasets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
InStereo2k,
Kitti2012Stereo,
Kitti2015Stereo,
Middlebury2014Stereo,
SceneFlowStereo,
SintelStereo,
)
Expand Down Expand Up @@ -119,6 +120,7 @@
"Kitti2012Stereo",
"Kitti2015Stereo",
"CarlaStereo",
"Middlebury2014Stereo",
"CREStereo",
"FallingThingsStereo",
"SceneFlowStereo",
Expand Down
Loading