MrBlankness/LightM-UNet

free(): invalid pointer

Qu1n-22 opened this issue · 2 comments

我以以下代码方式尝试运行代码,能够输出结果,但是会有指针错误,错误信息如下图:

import torch
from LightMUNet import LightMUNet
model = LightMUNet(
            spatial_dims = 32,
            init_filters = 32,
            in_channels=3,
            out_channels=1,
            blocks_down=[1, 2, 2, 4],
            blocks_up=[1, 1, 1],
        )

model.cuda() 
x = torch.randn(4, 3, 256, 256).cuda()
outputs = model(x)
outputs = torch.sigmoid(outputs)
print(outputs.shape)

image

Not sure exactly what went wrong but spatial_dims=32 doesn't look right. It should be either 2 or 3. Most likely 2 in your case if you have a 256x256 image with 3 input channels and a batch size of 4.

class LightMUNet(nn.Module):

    def __init__(
        self,
        spatial_dims: int = 3, 
        init_filters: int = 8,
        in_channels: int = 1,
        out_channels: int = 2,
        dropout_prob: float | None = None,
        act: tuple | str = ("RELU", {"inplace": True}),
        norm: tuple | str = ("GROUP", {"num_groups": 8}),
        norm_name: str = "",
        num_groups: int = 8,
        use_conv_final: bool = True,
        blocks_down: tuple = (1, 2, 2, 4),
        blocks_up: tuple = (1, 1, 1),
        upsample_mode: UpsampleMode | str = UpsampleMode.NONTRAINABLE,
    ):
        super().__init__()

        if spatial_dims not in (2, 3):
            raise ValueError("`spatial_dims` can only be 2 or 3.")

Maybe try something like:

model = LightMUNet(spatial_dims=2, 
        init_filters=32, 
        in_channels=3, 
        out_channels=1, 
        blocks_down=[1, 2, 2, 4], 
        blocks_up=[1, 1, 1])

Not sure exactly what went wrong but spatial_dims=32 doesn't look right. It should be either 2 or 3. Most likely 2 in your case if you have a 256x256 image with 3 input channels and a batch size of 4.

class LightMUNet(nn.Module):

    def __init__(
        self,
        spatial_dims: int = 3, 
        init_filters: int = 8,
        in_channels: int = 1,
        out_channels: int = 2,
        dropout_prob: float | None = None,
        act: tuple | str = ("RELU", {"inplace": True}),
        norm: tuple | str = ("GROUP", {"num_groups": 8}),
        norm_name: str = "",
        num_groups: int = 8,
        use_conv_final: bool = True,
        blocks_down: tuple = (1, 2, 2, 4),
        blocks_up: tuple = (1, 1, 1),
        upsample_mode: UpsampleMode | str = UpsampleMode.NONTRAINABLE,
    ):
        super().__init__()

        if spatial_dims not in (2, 3):
            raise ValueError("`spatial_dims` can only be 2 or 3.")

Maybe try something like:

model = LightMUNet(spatial_dims=2, 
        init_filters=32, 
        in_channels=3, 
        out_channels=1, 
        blocks_down=[1, 2, 2, 4], 
        blocks_up=[1, 1, 1])

yeah,I got some of the parameters wrong.Thanks for your help.