segmentation-models-pytorch
Image segmentation models with pre-trained backbones. PyTorch.
What it is and what it does
Segmentation Models PyTorch (SMP) is a library that wraps semantic segmentation architectures on top of PyTorch, combining encoder-decoder pairs to produce pixel-level classification masks. It abstracts away the boilerplate of building segmentation models by providing 12 pre-built architectures (Unet, Unet++, Segformer, DPT, DeepLabV3+, and others) that can be instantiated with a choice of encoder backbone and pretrained weights in minimal code.
The library's main value is its breadth of pretrained encoders—800+ convolution and transformer-based models sourced from timm and huggingface-hub—which you can mix and match with any decoder architecture. It includes training utilities (Dice, Jaccard, Tversky losses and metrics), supports ONNX export and torch.compile, and integrates with huggingface-hub for model sharing. The typical workflow is to instantiate a model, optionally load pretrained encoder weights, configure data preprocessing to match the encoder's training regime, then train or fine-tune on your segmentation task.
Use it for:
- Train a binary segmentation model on custom image data (e.g., object boundaries) by choosing an encoder and decoder, then fine-tuning with your labeled dataset.
- Load a pretrained Segformer or DPT model for immediate inference on new images without training.
- Export a trained segmentation model to ONNX format for deployment in non-Python environments or edge devices.
- Experiment with different encoder-decoder combinations to find the best accuracy-speed tradeoff for your segmentation task.
- Build a multiclass segmentation pipeline that assigns multiple semantic labels to different regions of an image.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Provides PyTorch-based neural network models for image semantic segmentation, with 12 encoder-decoder architectures and 800+ pretrained encoders, usable in two lines of code.
Yes. The library is actively maintained, has low install friction, carries no known vulnerabilities, and offers a well-designed API for a common computer vision task. Install it if you need to build or fine-tune semantic segmentation models; the breadth of pretrained encoders and multiple architectures make it a practical choice over building from scratch. The MIT license poses no restrictions.
Install
segmentation-models-pytorch on PyPI
pip
pip install segmentation-models-pytorchuv
uv add segmentation-models-pytorchpoetry
poetry add segmentation-models-pytorchInstalling segmentation-models-pytorch
Before you install
Low friction installation with a pure Python wheel. Active maintenance with recent commits and 11691 repository stars. Requires torch, torchvision, and timm as runtime dependencies, which are substantial but standard for PyTorch vision work.
License in practice
MIT License permits commercial and private use with minimal restrictions. You may use, modify, and distribute the software freely as long as you include the original license and copyright notice.
Quickstart
import segmentation_models_pytorch as smp
model = smp.Unet(
encoder_name="resnet34",
encoder_weights="imagenet",
in_channels=3,
classes=1
)
from segmentation_models_pytorch.encoders import get_preprocessing_fn
preprocess_input = get_preprocessing_fn('resnet34', pretrained='imagenet')
Requires PyTorch and torchvision installed; models expect input images preprocessed according to the encoder's training regime for best results.
Verify before relying
- Whether the 800+ pretrained encoders include all major vision transformer and CNN architectures or a subset thereof.
- Performance characteristics (inference speed, memory footprint) for different model sizes and input resolutions.
- Whether ONNX export preserves all model features or has known limitations.
Package facts
| License | The MIT License Copyright (c) 2019, Pavel Iakubovskii Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the… (full text in the JSON record) (permissive) |
| Python support | supports the current Python release (>=3.9) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 8 — huggingface-hub, numpy, pillow, safetensors, timm, torch, torchvision, tqdm |
| Maintenance | actively maintained — 484 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 692,350/month — #5,321 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: segmentation_models_pytorch-0.5.0-py3-none-any.whl
Tags
More Artificial Intelligence packages
LiteLLM provides a unified Python interface to…
permissive · top 100 on PyPI
huggingface-hubClient library and CLI tool for downloading,…
permissive · top 100 on PyPI
langchainLangChain provides a framework for building…
permissive · top 1,000 on PyPI
hf-xethf-xet provides chunk-based deduplication and…
permissive · top 1,000 on PyPI
tokenizersTokenizers converts raw text into token…
permissive · top 1,000 on PyPI
transformersTransformers provides a unified framework for…
permissive · top 1,000 on PyPI
nnunetv2nnU-Net is a semantic segmentation framework…
permissive · top 15,000 on PyPI
timmTimm provides a large collection of pretrained…
permissive · top 5,000 on PyPI
pytorchcvProvides a collection of pretrained computer…
unclear · top 15,000 on PyPI
torchxrayvisionTorchXRayVision provides pre-trained deep…
permissive · top 15,000 on PyPI
cellposeCellpose segments cells and nuclei in…
permissive · top 15,000 on PyPI
efficientnet-pytorchLoads and runs pretrained EfficientNet image…
permissive · top 15,000 on PyPI
effdetPyTorch implementation of EfficientDet object…
permissive · top 15,000 on PyPI
pretrainedmodelsProvides a unified interface to load pretrained…
permissive · top 15,000 on PyPI
thincThinc is a lightweight deep learning library…
permissive · top 1,000 on PyPI
mmdetMMDetection is an object detection and instance…
permissive · top 15,000 on PyPI