
segmentation_models.pytorch
Python library of PyTorch neural networks for labeling each pixel in an image, with pretrained encoders.
- Stars
- 11.8k
- Forks
- 1.9k
- Licence
- MIT
- Language
- Python
- Last update
- 4 days ago
- Type
- Library
What it is
Segmentation Models PyTorch (SMP) is a Python library for semantic segmentation, the task of labeling every pixel in an image by category. You can create a model in about two lines of code using a high-level API, and choose from many architectures such as Unet, Unet++, Segformer and DPT. Each model can use a pretrained encoder, so you can start from weights already trained on ImageNet instead of from scratch.
- Create a segmentation model with smp.Unet, choosing an encoder such as resnet34 and the number of output classes
- Prepare input images with the matching preprocessing function for a pretrained encoder
- Train a binary or multiclass segmentation model using the example notebooks (for example on OxfordPets or CamVid)
- Load and run pretrained Segformer, DPT or UPerNet models using the provided inference notebooks
- Export a trained model to ONNX using the included example
Great for
- Python developers building image segmentation models in PyTorch
- Researchers comparing segmentation architectures and encoders
- Teams that want pretrained encoders to speed up training on their own labeled images
- People who want to export a trained model to ONNX
Not ideal for
- Non-programmers looking for a ready-made app, since the README documents a code library only
- Projects that do not use PyTorch, because the library is built on it
- Anyone without labeled training data for their task, since the README covers training with your own dataset and examples
How to get it
- 1
See the README
You'll need: Python 3.9+ (per README badge) · PyTorch 1.9+ (per README badge)
Clone the repository
git clone https://github.com/qubvel-org/segmentation_models.pytorch - 2
Run it
- Install Python 3.9+ and PyTorch 1.9+
- Clone the repository or install the package as described in the project docs
- Import segmentation_models_pytorch as smp in a Python script
- Create a model, for example smp.Unet(encoder_name="resnet34", encoder_weights="imagenet", in_channels=3, classes=3)
- Run the model or train it with your own data, following the example notebooks
- 3
Get the most out of it
- Use get_preprocessing_fn with the same encoder to prepare inputs the way its pretrained weights expect
- Try different architectures such as Unet++, Segformer or DPT and compare results on your data
- Use the built-in losses and metrics such as Dice, Jaccard and Tversky for training
- Export trained models to ONNX for deployment, as shown in the example notebook
- Save and share models through the Hugging Face Hub, following the provided notebook
Downloads
Strengths
- Two-line API to build a segmentation network, according to the README
- Many pretrained encoders and architectures in one library, with timm support
- Includes example notebooks you can open in Colab
Trade-offs
- The README is truncated, so details of installation and full model lists are not visible here
- The README says 800+ encoders while the repository description says 500+, so the exact count is unclear
- Requires PyTorch and Python knowledge to use, so it is not beginner-friendly for non-coders
How it compares
| Project | Stars | Type | Level | Updated | Best for |
|---|---|---|---|---|---|
| segmentation_models.pytorch (this) | 11.8k | Library | intermediate | 4 days ago | Python developers building image segmentation models in PyTorch |
| albumentations | 15.3k | Library | beginner | 1.4 years ago | Machine learning engineers training image classification or segmentation models with limited data |
| Swin-Transformer | 16.1k | AI model / agent | advanced | 2.3 years ago | Researchers reproducing results from the Swin Transformer paper |
| supervision | 51.5k | Library | intermediate | 4 days ago | Python developers building apps on top of object detection or segmentation models |
| nano-vllm | 16.3k | Library | intermediate | 6 months ago | Developers who want to understand how LLM inference engines work internally |
| nni | 14.4k | Library | intermediate | 2.3 years ago | Researchers comparing hyperparameter tuning algorithms such as TPE, Hyperband, or Bayesian methods |
Stats synced from GitHub. The assessment above was drafted with AI from the project's README on 2026-10-29 and may miss recent changes — check the README before relying on a command. MIT licence: free to use, modify and distribute, including commercially, as long as you keep the copyright notice.