Skip to main content

ml_dl.TinyUNet

ml_dl.TinyUNet(in_channels, n_classes=1, base=8)

Two-level U-Net for binary per-pixel segmentation.

The smallest practical U-Net architecture: one encoder block, one bottleneck, one decoder block, and a 1x1 head. Approximately 20,000 parameters with the default base=8. Designed for tutorial notebooks and “does my pipeline run at all?” sanity tests; trains in seconds on a laptop CPU even on a few hundred 256x256 tiles.

Parameters

Name Type Description Default
in_channels int Number of input channels (e.g. 2 for Red+NIR, 4 for Red+Green+Blue+NIR). required
n_classes int Number of output channels of the final 1x1 conv. Use 1 for single-channel binary segmentation paired with BCEWithLogitsLoss. Use >=2 for multi-class segmentation paired with CrossEntropyLoss. 1
base int Number of filters in the first encoder block. The bottleneck has 2 * base filters; the decoder shrinks back to base. 8

Notes

The output is raw logits – no sigmoid or softmax. The caller is responsible for that, typically through the loss function (BCEWithLogitsLoss does the sigmoid internally; CrossEntropyLoss does the softmax).