-
Notifications
You must be signed in to change notification settings - Fork 7.1k
Add stereo preset transforms #6549
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
TeodorPoncu
merged 35 commits into
pytorch:main
from
TeodorPoncu:add-stereo-preset-transforms
Sep 22, 2022
Merged
Changes from 8 commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
9de8cc9
Added transforms for Stereo Matching
TeodorPoncu 376b81b
changed implicit Y scaling to 0.
TeodorPoncu ec0c3b1
Adressed some comments
TeodorPoncu f5cec5a
addressed type hint
TeodorPoncu bce5e7d
Added interpolation random interpolation strategy
TeodorPoncu efc1087
Aligned crop get params
TeodorPoncu 28c89ad
Merge branch 'main' into add-stereo-preset-transforms
TeodorPoncu bf93fc0
fixed bug in RandomErase
TeodorPoncu f67a21e
Adressed scaling and typos
TeodorPoncu 3a80766
Adressed occlusion typo
TeodorPoncu dad77fb
Changed parameter order in F.erase
TeodorPoncu 1bc61a4
fixed random erase
TeodorPoncu 279ec0f
Added inference preset transform for stereo matching
TeodorPoncu 98de4a4
added contiguous reshape to output tensors
TeodorPoncu ab0d54c
Adressed comments
TeodorPoncu a9c3682
Modified the transform preset to use Tuple[int, int]
TeodorPoncu a99ebb5
adressed NITs
TeodorPoncu bb6632d
added grayscale transform, align resize -> mask
TeodorPoncu 5570313
changed max disparity default behaviour
TeodorPoncu df3461d
added fixed resize, changed masking in sparse flow masking
TeodorPoncu e294d92
Merge branch 'main' into add-stereo-preset-transforms
TeodorPoncu 568544c
update to align with argparse
TeodorPoncu 11154ea
Merge branch 'add-stereo-preset-transforms' of https://github.com/Teo…
TeodorPoncu 5683601
changed default mask in asymetric pairs
TeodorPoncu f5a4423
moved grayscale order
TeodorPoncu c121c2f
changed grayscale api to accept to tensor variant
TeodorPoncu 19a43c6
mypy fix
TeodorPoncu c55e555
changed resize specs
TeodorPoncu d9a726e
adressed nits
TeodorPoncu 655cb18
Merge branch 'main' into add-stereo-preset-transforms
jdsgomes 872703b
added type hints
TeodorPoncu e3a3e0f
mypy fix
TeodorPoncu 6e04c24
mypy fix
TeodorPoncu d1fe636
mypy fix
TeodorPoncu c7f0f74
Merge branch 'main' into add-stereo-preset-transforms
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 |
---|---|---|
@@ -0,0 +1,111 @@ | ||
from typing import Tuple, Union | ||
|
||
import torch | ||
import transforms as T | ||
|
||
|
||
class StereoMatchingEvalPreset(torch.nn.Module): | ||
def __init__( | ||
self, mean: float = 0.5, std: float = 0.5, resize_size=None, interpolation_type: str = "bilinear" | ||
) -> None: | ||
super().__init__() | ||
|
||
transforms = [ | ||
T.ToTensor(), | ||
T.MakeValidDisparityMask(512), # we keep this transform for API consistency | ||
YosuaMichael marked this conversation as resolved.
Show resolved
Hide resolved
|
||
T.ConvertImageDtype(torch.float32), | ||
T.Normalize(mean=mean, std=std), | ||
T.ValidateModelInput(), | ||
] | ||
|
||
if resize_size is not None: | ||
transforms.append(T.Resize(resize_size, interpolation_type=interpolation_type)) | ||
|
||
self.transforms = T.Compose(transforms) | ||
|
||
def forward(self, images, disparities, masks): | ||
return self.transforms(images, disparities, masks) | ||
|
||
|
||
class StereoMatchingTrainPreset(torch.nn.Module): | ||
def __init__( | ||
self, | ||
*, | ||
# RandomResizeAndCrop params | ||
crop_size: Tuple[int, int], | ||
resize_prob: float = 1.0, | ||
scaling_type: str = "exponential", | ||
scale_range: Tuple[float, float] = (-0.2, 0.5), | ||
scale_interpolation_type: str = "bilinear", | ||
# normalization params: | ||
mean: float = 0.5, | ||
std: float = 0.5, | ||
# processing device | ||
gpu_transforms=False, | ||
YosuaMichael marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# masking | ||
max_disparity: int = 256, | ||
# SpatialShift params | ||
spatial_shift_prob: float = 0.5, | ||
spatial_shift_max_angle: float = 0.5, | ||
spatial_shift_max_displacement: float = 0.5, | ||
spatial_shift_interpolation_type: str = "bilinear", | ||
# AssymetricColorJitter | ||
gamma_range: Tuple[float, float] = (0.8, 1.2), | ||
brightness: Union[int, Tuple[int, int]] = (0.8, 1.2), | ||
contrast: Union[int, Tuple[int, int]] = (0.8, 1.2), | ||
saturation: Union[int, Tuple[int, int]] = 0.0, | ||
hue: Union[int, Tuple[int, int]] = 0.0, | ||
asymmetric_jitter_prob: float = 1.0, | ||
# RandomHorizontalFlip | ||
horizontal_flip_prob=0.5, | ||
YosuaMichael marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# RandomOcclusion | ||
occlusion_prob: float = 0.0, | ||
occlusion_px_range: Tuple[int, int] = (50, 100), | ||
# RandomErase | ||
erase_prob: float = 0.0, | ||
erase_px_range: Tuple[int, int] = (50, 100), | ||
erase_num_repeats: int = 1, | ||
) -> None: | ||
|
||
if scaling_type not in ["linear", "exponential"]: | ||
raise ValueError(f"Unknown scaling type: {scaling_type}. Available types: linear, exponential") | ||
|
||
super().__init__() | ||
transforms = [T.ToTensor()] | ||
if gpu_transforms: | ||
transforms.append(T.ToGPU()) | ||
|
||
transforms.extend( | ||
[ | ||
T.AsymmetricColorJitter( | ||
brightness=brightness, contrast=contrast, saturation=saturation, hue=hue, p=asymmetric_jitter_prob | ||
), | ||
T.AsymetricGammaAdjust(p=asymmetric_jitter_prob, gamma_range=gamma_range), | ||
T.RandomSpatialShift( | ||
p=spatial_shift_prob, | ||
max_angle=spatial_shift_max_angle, | ||
max_displacement=spatial_shift_max_displacement, | ||
interpolation_type=spatial_shift_interpolation_type, | ||
), | ||
T.ConvertImageDtype(torch.float32), | ||
T.RandomResizeAndCrop( | ||
crop_size=crop_size, | ||
scale_range=scale_range, | ||
resize_prob=resize_prob, | ||
scaling_type=scaling_type, | ||
interpolation_type=scale_interpolation_type, | ||
), | ||
T.RandomHorizontalFlip(horizontal_flip_prob), | ||
# occlusion after flip, otherwise we're occluding the reference image | ||
T.RandomOcclusion(p=occlusion_prob, occlusion_px_range=occlusion_px_range), | ||
T.RandomErase(p=erase_prob, erase_px_range=erase_px_range, num_repeats=erase_num_repeats), | ||
T.Normalize(mean=mean, std=std), | ||
T.MakeValidDisparityMask(max_disparity), | ||
T.ValidateModelInput(), | ||
] | ||
) | ||
|
||
self.transforms = T.Compose(transforms) | ||
|
||
def forward(self, images, disparties, mask): | ||
return self.transforms(images, disparties, mask) |
Oops, something went wrong.
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.
Please add type hint for resize_size (I think it should be
Optional[Tuple[int, int]]
in this case)