Skip to content

[proto] Some fixes for crestereo #6791

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 2 commits into from
Oct 19, 2022
Merged
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
13 changes: 8 additions & 5 deletions torchvision/prototype/models/depth/stereo/crestereo.py
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,7 @@ def _get_window_type(self, iteration: int) -> str:
return "1d" if iteration % 2 == 0 else "2d"

def forward(
self, left_image: Tensor, right_image: Tensor, flow_init: Optional[Tensor], num_iters: int = 10
self, left_image: Tensor, right_image: Tensor, flow_init: Optional[Tensor] = None, num_iters: int = 10
) -> List[Tensor]:
features = torch.cat([left_image, right_image], dim=0)
features = self.feature_encoder(features)
Expand All @@ -781,10 +781,10 @@ def forward(
ctx_pyramid = self.downsampling_pyramid(ctx)

# we store in reversed order because we process the pyramid from top to bottom
l_pyramid: Dict[str, Tensor] = {res: l_pyramid[idx] for idx, res in enumerate(self.resolutions)}
r_pyramid: Dict[str, Tensor] = {res: r_pyramid[idx] for idx, res in enumerate(self.resolutions)}
net_pyramid: Dict[str, Tensor] = {res: net_pyramid[idx] for idx, res in enumerate(self.resolutions)}
ctx_pyramid: Dict[str, Tensor] = {res: ctx_pyramid[idx] for idx, res in enumerate(self.resolutions)}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My local mypy complains:

crestereo.py:784: error: Name "l_pyramid" already defined on line 778
crestereo.py:785: error: Name "r_pyramid" already defined on line 779
crestereo.py:786: error: Name "net_pyramid" already defined on line 780
crestereo.py:787: error: Name "ctx_pyramid" already defined on line 781
Found 4 errors in 1 file (checked 1 source file)

and removing the type declaration seems to fix it.

l_pyramid = {res: l_pyramid[idx] for idx, res in enumerate(self.resolutions)}
r_pyramid = {res: r_pyramid[idx] for idx, res in enumerate(self.resolutions)}
net_pyramid = {res: net_pyramid[idx] for idx, res in enumerate(self.resolutions)}
ctx_pyramid = {res: ctx_pyramid[idx] for idx, res in enumerate(self.resolutions)}

# offsets for sampling pixel candidates in the correlation ops
offsets: Dict[str, Tensor] = {}
Expand Down Expand Up @@ -1425,6 +1425,9 @@ def crestereo_base(*, weights: Optional[CREStereo_Base_Weights] = None, progress
.. autoclass:: torchvision.prototype.models.depth.stereo.CREStereo_Base_Weights
:members:
"""

weights = CREStereo_Base_Weights.verify(weights)

return _crestereo(
weights=weights,
progress=progress,
Expand Down