Skip to content

BUG: Nonrigid registration with a single block along one dimension fails. #1211

@sylviaschroeder

Description

@sylviaschroeder

Describe the issue:

When settings["registration"]["block_size"] is set to (Ly, x) or (y, Lx), non-rigid registration fails.

I believe you can fix this by replacing code in nonrigid.transform_data with:

# Ensure interpolate output size is valid even for a single block in a dimension

Lyc = max(1, int(yb.max() - yb.min()))

Lxc = max(1, int(xb.max() - xb.min()))



yxup = F.interpolate(

    torch.stack((ymax1, xmax1), dim=1),

    size=(Lyc, Lxc),

    mode="bilinear",

    align_corners=True,
)



# If you pad later, make the single-block case safe (right/bottom must be non-negative)

xb_min = int(xb.min())

xb_max = int(xb.max())

yb_min = int(yb.min())

yb_max = int(yb.max())



pad_left = max(0, xb_min)

pad_right = max(0, Lx - xb_max)

pad_top = max(0, yb_min)

pad_bottom = max(0, Ly - yb_max)



yxup = F.pad(yxup, (pad_left, pad_right, pad_top, pad_bottom), mode="replicate")

Reproduce the code example:

pseudo-code:

from suite2p.registration import register

settings["registration"]["block_size"] = [64, 256]
# f_reg.shape: [500, 256, 256]
register.registration_wrapper(f_reg, settings=settings)

Example input dataset used to reproduce the issue:

No response

Error message:

File "C:\dev\workspaces\SchroederLab\depth-for-2p\.venv\Lib\site-packages\suite2p\registration\register.py", line 933, in registration_wrapper
    outputs = register_frames(f_align_in, f_align_out=f_align_out, bidiphase=bidiphase,
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\dev\workspaces\SchroederLab\depth-for-2p\.venv\Lib\site-packages\suite2p\registration\register.py", line 609, in register_frames
    frames = shift_frames(fr_torch, ymax, xmax, ymax1, xmax1, blocks, 
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\dev\workspaces\SchroederLab\depth-for-2p\.venv\Lib\site-packages\suite2p\registration\register.py", line 447, in shift_frames
    fr_torch = nonrigid.transform_data(fr_torch, blocks[2], blocks[1], blocks[0], 
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\dev\workspaces\SchroederLab\depth-for-2p\.venv\Lib\site-packages\suite2p\registration\nonrigid.py", line 414, in transform_data
    yxup = F.interpolate(torch.stack((ymax1, xmax1), dim=1), 
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\dev\workspaces\SchroederLab\depth-for-2p\.venv\Lib\site-packages\torch\nn\functional.py", line 4867, in interpolate
    return torch._C._nn.upsample_bilinear2d(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: Input and output sizes should be greater than 0, but got input (H: 6, W: 1) output (H: 192, W: 0)

Version information:

suite2p v1.0.0.2.dev11+g20ea7e15e

Context for the issue:

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions