ResUNet 2D¶
ConvNet Segmentation ConvNet
- class lucid.models.ResUNet2d(config: UNetConfig)¶
ResUNet2d is a residual variant of lucid.models.UNet2d that reuses the
same configurable encoder-decoder structure but forces residual blocks
throughout the network. It is useful when deeper stage stacks or stronger
gradient flow are desirable while keeping the same segmentation-oriented U-Net
topology.
For volumetric inputs with shape \((N, C, D, H, W)\), see
lucid.models.ResUNet3d.
Class Signature¶
class ResUNet2d(UNet2d):
def __init__(self, config: UNetConfig) -> None
Parameters¶
config (UNetConfig): U-Net configuration describing the encoder/decoder stage layout, channel widths, sampling strategy, and segmentation output space. ResUNet2d reuses this config and enforces block=”res”.
Methods¶
Examples¶
Build a ResUNet2d from `from_channels`
import lucid
import lucid.models as models
cfg = models.UNetConfig.from_channels(
in_channels=3,
out_channels=2,
channels=(64, 128, 256, 512),
num_blocks=(2, 2, 2, 3),
norm="group",
act="silu",
upsample_mode="bilinear",
)
model = models.ResUNet2d(cfg)
x = lucid.random.randn(1, 3, 256, 256)
logits = model(x)
print(logits.shape) # (1, 2, 256, 256)
Build a Custom ResUNet2d with Stage-Level Configuration
import lucid
import lucid.models as models
cfg = models.UNetConfig(
in_channels=1,
out_channels=3,
encoder_stages=[
models.UNetStageConfig(channels=32, num_blocks=2),
models.UNetStageConfig(channels=64, num_blocks=2),
models.UNetStageConfig(channels=128, num_blocks=3, use_attention=True),
models.UNetStageConfig(channels=256, num_blocks=3),
],
norm="group",
act="silu",
downsample_mode="conv",
upsample_mode="transpose",
deep_supervision=True,
)
model = models.ResUNet2d(cfg)
x = lucid.random.randn(2, 1, 256, 256)
out = model(x)
print(out["out"].shape) # (2, 3, 256, 256)
print(len(out["aux"])) # 2
Notes¶
ResUNet2d reuses
lucid.models.UNetConfigandlucid.models.UNetStageConfig; there is no separate config class.If config.block is not already res,
lucid.models.ResUNet2doverrides it internally.ResUNet2d expects input tensors with shape \((N, C, H, W)\). For 3D volumetric inputs, use
lucid.models.ResUNet3d.