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

win incorrect in sim.gaussian filter? #57

Open
peterlionelnewman opened this issue Aug 3, 2024 · 1 comment
Open

win incorrect in sim.gaussian filter? #57

peterlionelnewman opened this issue Aug 3, 2024 · 1 comment

Comments

@peterlionelnewman
Copy link

peterlionelnewman commented Aug 3, 2024

For 3d images was getting the error:

out = conv(out, weight=win.transpose(2 + i, -1), stride=1, padding=0, groups=C)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: expected stride to be a single integer value or a list of 2 values to match the convolution dimensions, but got stride=[1, 1, 1]

though weight was 4D? is this incorrect and requires and undate?

def gaussian_filter(input: Tensor, win: Tensor) -> Tensor:
    r""" Blur input with 1-D kernel
    Args:
        input (torch.Tensor): a batch of tensors to be blurred
        window (torch.Tensor): 1-D gauss kernel
    Returns:
        torch.Tensor: blurred tensors
    """
    ndim = input.dim()

    assert all([ws == 1 for ws in win.shape[1:-1]]), win.shape
    if ndim == 4:
        conv = F.conv2d
    elif ndim == 5:
        conv = F.conv3d
    else:
        raise NotImplementedError(input.shape)

    C = input.shape[1]
    out = input
    for i, s in enumerate(input.shape[2:]):
        if ndim == 5:
            weight = win.view(1, 1, 1, 1, win.shape[-1])
        elif ndim == 4:
            weight = win.view(1, 1, 1, win.shape[-1])

        if s >= win.shape[-1]:
            out = conv(out, weight=weight, stride=1, padding=0, groups=C)
        else:
            warnings.warn(
                f"Skipping Gaussian Smoothing at dimension 2+{i} for input: {input.shape} and win size: {win.shape[-1]}"
            )

    return out

Let me know,

@lxy51
Copy link

lxy51 commented Dec 2, 2024

Same question

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

No branches or pull requests

2 participants