skillfed

segmentation-models-pytorch

Image segmentation models with pre-trained backbones. PyTorch.

segmentation-models-pytorch v0.5.0 692.4K downloads/30d#5,321 on PyPI11,691
Permissive 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) Active released

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-pytorch

uv

uv add segmentation-models-pytorch

poetry

poetry add segmentation-models-pytorch

Installing 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

License :: OSI Approved :: MIT LicenseProgramming Language :: PythonProgramming Language :: Python :: 3Programming Language :: Python :: Implementation :: CPythonProgramming Language :: Python :: Implementation :: PyPy

Tags

image semantic segmentation pytorchpretrained segmentation modelsencoder decoder segmentationunet segmentation librarypytorch image segmentationsegmentation model architecturessemantic segmentation deep learning
computer-visionsemantic-segmentationpretrained-models

More Artificial Intelligence packages