Segmentation Models PyTorch (SMP) is a Python library offering a high-level API for various neural network architectures, pre-trained backbones, losses, and metrics for image semantic segmentation. It supports 12 encoder-decoder architectures and over 800 pre-trained convolutional and transformer-based encoders, leveraging `timm` for a vast selection. The library focuses on simplicity, fast convergence, and compatibility with PyTorch's `torch.jit.script`, `torch.compile`, and `torch.export` features. It is currently at version 0.5.0 and maintains an active release cadence with frequent updates and new model integrations.
pip install segmentation-models-pytorchVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to instantiate a U-Net model with a pre-trained ResNet34 encoder, configure input and output channels, and set an activation function. It also shows how to obtain and apply the correct preprocessing function required for models with pre-trained backbones to ensure optimal performance.
Re-train UperNet models with SMP v0.5.0 or ensure strict versioning. For fine-tuning, load the new `smp-hub` checkpoints.
Update `encoder_name` arguments to use the `tu-` prefix for all `timm` encoders.
Update import paths and usage from `smp.utils.losses` to `smp.losses`.
Ensure your environment uses Python 3.7 or newer.
Review release notes for v0.3.4 and `albumentations` documentation for affected function names if custom integrations are breaking. Upgrade `albumentations` if issues persist.
Always integrate `get_preprocessing_fn` into your data loading pipeline to preprocess images before feeding them to the model.
Ensure input image height and width are compatible with the chosen model architecture and encoder, often powers of 2 (e.g., 256x256, 512x512). Refer to specific model documentation for exact requirements.