Skip to content

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
Step-by-step guide: how to use segmentation_models.pytorchInstall, first run, examples, tips and FAQs

How to get it

  1. 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. 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. 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

ProjectStarsTypeLevelUpdatedBest for
segmentation_models.pytorch (this)11.8kLibraryintermediate4 days agoPython developers building image segmentation models in PyTorch
albumentations15.3kLibrarybeginner1.4 years agoMachine learning engineers training image classification or segmentation models with limited data
Swin-Transformer16.1kAI model / agentadvanced2.3 years agoResearchers reproducing results from the Swin Transformer paper
supervision51.5kLibraryintermediate4 days agoPython developers building apps on top of object detection or segmentation models
nano-vllm16.3kLibraryintermediate6 months agoDevelopers who want to understand how LLM inference engines work internally
nni14.4kLibraryintermediate2.3 years agoResearchers 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.