Skip to content

fix: xy_grid drops homogeneous channel when unsqueeze is set - #104

Open
andrewwhitecdw wants to merge 1 commit into
NVlabs:mainfrom
andrewwhitecdw:bugfix/geometry-xy-grid-drops-homogeneous-channel-when
Open

fix: xy_grid drops homogeneous channel when unsqueeze is set#104
andrewwhitecdw wants to merge 1 commit into
NVlabs:mainfrom
andrewwhitecdw:bugfix/geometry-xy-grid-drops-homogeneous-channel-when

Conversation

@andrewwhitecdw

Copy link
Copy Markdown

Problem

fix: xy_grid drops homogeneous channel when unsqueeze is set

Fix

Replace:

    if device is None:
        # numpy
        arange, meshgrid, stack, ones = np.arange, np.meshgrid, np.stack, np.ones
    else:
        # torch
        arange = lambda *a, **kw: torch.arange(*a, device=device, **kw)
        meshgrid, stack = torch.meshgrid, torch.stack
        ones = lambda *a: torch.ones(*a, device=device)

    tw, th = [arange(o, o + s, **arange_kw) for s, o in zip((W, H), origin)]
    grid = meshgrid(tw, th, indexing='xy')
    if homogeneous:
        grid = grid + (ones((H, W)),)
    if unsqueeze is not None:
        grid = (grid[0].unsqueeze(unsqueeze), grid[1].unsqueeze(unsqueeze))
    if cat_dim is not None:
        grid = stack(grid, cat_dim)
    return grid

with:

    if device is None:
        # numpy
        arange, meshgrid, stack, ones = np.arange, np.meshgrid, np.stack, np.ones
        unsqueeze_fn = lambda x, dim: np.expand_dims(x, dim)
    else:
        # torch
        arange = lambda *a, **kw: torch.arange(*a, device=device, **kw)
        meshgrid, stack = torch.meshgrid, torch.stack
        ones = lambda *a: torch.ones(*a, device=device)
        unsqueeze_fn = lambda x, dim: x.unsqueeze(dim)

    tw, th = [arange(o, o + s, **arange_kw) for s, o in zip((W, H), origin)]
    grid = meshgrid(tw, th, indexing='xy')
    if homogeneous:
        grid = grid + (ones((H, W)),)
    if unsqueeze is not None:
        grid = tuple(unsqueeze_fn(g, unsqueeze) for g in grid)
    if cat_dim is not None:
        grid = stack(grid, cat_dim)
    return grid

Files changed

  • dust3r/utils/geometry.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant