-
Notifications
You must be signed in to change notification settings - Fork 7.1k
Added ETH3D stereo dataset #6349
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
Changes from 2 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
b6933ff
Added ETH3D stereo dataset
TeodorPoncu eac1590
Small doc-reformating
TeodorPoncu 1478a8c
Removed assertions with no use, changed np conversion
TeodorPoncu a4eac5f
Added ETH3D stereo dataset
TeodorPoncu a63500d
Removed assertions with no use, changed np conversion
TeodorPoncu 5dff9d6
rebased on main
TeodorPoncu ed09514
Merge branch 'add-eth3d-stereo-dataset' of https://github.com/pytorch…
TeodorPoncu c5ec95e
Merge branch 'main' into add-eth3d-stereo-dataset
TeodorPoncu 9a002d3
Revert "Removed assertions with no use, changed np conversion"
TeodorPoncu 8c08a31
Merge branch 'add-eth3d-stereo-dataset' of https://github.com/pytorch…
TeodorPoncu 7ebea4a
Merge branch 'main' into add-eth3d-stereo-dataset
TeodorPoncu a8c3f4d
Update to np.bool instead of np.bool_
TeodorPoncu 335c8e6
lint and mypy nit fix
TeodorPoncu a8b8c22
Merge branch 'main' into add-eth3d-stereo-dataset
TeodorPoncu 750fee3
Merge branch 'main' into add-eth3d-stereo-dataset
TeodorPoncu 02292e7
test nit
TeodorPoncu 8f89208
Merge branch 'add-eth3d-stereo-dataset' of https://github.com/pytorch…
TeodorPoncu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -111,6 +111,7 @@ Stereo Matching | |
CarlaStereo | ||
Kitti2012Stereo | ||
Kitti2015Stereo | ||
ETH3DStereo | ||
|
||
Image pairs | ||
~~~~~~~~~~~ | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -359,3 +359,103 @@ def __getitem__(self, index: int) -> Tuple: | |
Both ``disparity`` and ``valid_mask`` are ``None`` if the dataset split is test. | ||
""" | ||
return super().__getitem__(index) | ||
|
||
|
||
class ETH3DStereo(StereoMatchingDataset): | ||
"""ETH3D `Low-Res Two-View <https://www.eth3d.net/datasets>`_ dataset. | ||
|
||
The dataset is expected to have the following structure: :: | ||
|
||
root | ||
ETH3D | ||
two_view_training | ||
scene1 | ||
im1.png | ||
im0.png | ||
images.txt | ||
cameras.txt | ||
calib.txt | ||
scene2 | ||
im1.png | ||
im0.png | ||
images.txt | ||
cameras.txt | ||
calib.txt | ||
... | ||
two_view_training_gt | ||
scene1 | ||
disp0GT.pfm | ||
mask0nocc.png | ||
scene2 | ||
disp0GT.pfm | ||
mask0nocc.png | ||
... | ||
two_view_testing | ||
scene1 | ||
im1.png | ||
im0.png | ||
images.txt | ||
cameras.txt | ||
calib.txt | ||
scene2 | ||
im1.png | ||
im0.png | ||
images.txt | ||
cameras.txt | ||
calib.txt | ||
... | ||
|
||
Args: | ||
root (string): Root directory of the ETH3D Dataset. | ||
split (string, optional): The dataset split of scenes, either "train" (default) or "test". | ||
transforms (callable, optional): A function/transform that takes in a sample and returns a transformed version. | ||
""" | ||
|
||
_has_built_in_disparity_mask = True | ||
|
||
def __init__(self, root: str, split: str = "train", transforms: Optional[Callable] = None): | ||
super().__init__(root, transforms) | ||
|
||
verify_str_arg(split, "split", valid_values=("train", "test")) | ||
|
||
root = Path(root) / "ETH3D" | ||
|
||
img_dir = "two_view_training" if split == "train" else "two_view_test" | ||
anot_dir = "two_view_training_gt" | ||
|
||
left_img_pattern = str(root / img_dir / "*" / "im0.png") | ||
right_img_pattern = str(root / img_dir / "*" / "im1.png") | ||
self._images = self._scan_pairs(left_img_pattern, right_img_pattern) | ||
|
||
if split == "test": | ||
self._disparities = list((None, None) for _ in self._images) | ||
else: | ||
disparity_pattern = str(root / anot_dir / "*" / "disp0GT.pfm") | ||
self._disparities = self._scan_pairs(disparity_pattern, None) | ||
|
||
def _read_disparity(self, file_path: str) -> Tuple: | ||
# test split has no disparity maps | ||
if file_path is None: | ||
return None, None | ||
|
||
disparity_map = _read_pfm_file(file_path) | ||
disparity_map = np.abs(disparity_map) # ensure that the disparity is positive | ||
mask_path = Path(file_path).parent / "mask0nocc.png" | ||
valid_mask = Image.open(mask_path) | ||
valid_mask = np.asarray(valid_mask).astype(np.bool_) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was surprised by the us of |
||
return disparity_map, valid_mask | ||
|
||
def __getitem__(self, index: int) -> Tuple: | ||
"""Return example at given index. | ||
|
||
Args: | ||
index(int): The index of the example to retrieve | ||
|
||
Returns: | ||
tuple: A 4-tuple with ``(img_left, img_right, disparity, valid_mask)``. | ||
The disparity is a numpy array of shape (1, H, W) and the images are PIL images. | ||
``valid_mask`` is implicitly ``None`` if the ``transforms`` parameter does not | ||
generate a valid mask. | ||
Both ``disparity`` and ``valid_mask`` are ``None`` if the dataset split is test. | ||
""" | ||
return super().__getitem__(index) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Curious why we need this assertion. Isn't it taken care of in the
shape_test_...
call below?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That assertion is unnecessary indeed! Thanks!