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

In other programs, the data used is 3D image data. If I want to use class MambaLayer(nn.Module): part of the code, is it necessary to divide the original data into patches first #52

Open
lxy51 opened this issue Jul 15, 2024 · 0 comments

Comments

@lxy51
Copy link

lxy51 commented Jul 15, 2024

In other programs, the data used is 3D image data. If I want to use class MambaLayer(nn.Module): part of the code, is it necessary to divide the original data into patches first

class MambaLayer(nn.Module):
def init(self, dim, d_state = 16, d_conv = 4, expand = 2):
super().init()
self.dim = dim
self.norm = nn.LayerNorm(dim)
self.mamba = Mamba(
d_model=dim, # Model dimension d_model
d_state=d_state, # SSM state expansion factor
d_conv=d_conv, # Local convolution width
expand=expand, # Block expansion factor
)

@autocast(enabled=False)
def forward(self, x):
    if x.dtype == torch.float16:
        x = x.type(torch.float32)
    B, C = x.shape[:2]
    assert C == self.dim
    n_tokens = x.shape[2:].numel()
    img_dims = x.shape[2:]
    x_flat = x.reshape(B, C, n_tokens).transpose(-1, -2)
    x_norm = self.norm(x_flat)
    x_mamba = self.mamba(x_norm)
    out = x_mamba.transpose(-1, -2).reshape(B, C, *img_dims)

    return out
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

1 participant