Skip to content
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

Fix type mis-match during mixed-precision training with extract_patches_from_pyramid #84

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
5 changes: 3 additions & 2 deletions kornia/feature/laf.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,11 +438,12 @@ def extract_patches_from_pyramid(
scale_mask = (pyr_idx[i] == cur_pyr_level).squeeze()
if (scale_mask.float().sum().item()) == 0:
continue
scale_mask = (scale_mask > 0).view(-1)
scale_mask = (scale_mask > 0).view(-1).to(nlaf.dtype).to(nlaf.device)
grid = generate_patch_grid_from_normalized_LAF(cur_img[i : i + 1], nlaf[i : i + 1, scale_mask, :, :], PS)
patches = F.grid_sample(
cur_img[i : i + 1].expand(grid.shape[0], ch, h, w), grid, padding_mode="border", align_corners=False
)
).to(nlaf.dtype).to(nlaf.device)

out[i].masked_scatter_(scale_mask.view(-1, 1, 1, 1), patches)
we_are_in_business = min(cur_img.size(2), cur_img.size(3)) >= PS
if not we_are_in_business:
Expand Down
Loading