{"id":12673665,"url":"https://github.com/qubvel-org/segmentation_models.pytorch","last_synced_at":"2025-09-09T19:53:28.294Z","repository":{"id":37405877,"uuid":"173333035","full_name":"qubvel-org/segmentation_models.pytorch","owner":"qubvel-org","description":"Semantic segmentation models with 500+ pretrained convolutional and transformer-based backbones.","archived":false,"fork":false,"pushed_at":"2025-05-05T10:34:05.000Z","size":15634,"stargazers_count":10414,"open_issues_count":58,"forks_count":1738,"subscribers_count":84,"default_branch":"main","last_synced_at":"2025-05-07T20:27:56.822Z","etag":null,"topics":["computer-vision","deeplab-v3-plus","deeplabv3","dpt","fpn","image-processing","image-segmentation","imagenet","models","pretrained-weights","pspnet","pytorch","segformer","segmentation","segmentation-models","semantic-segmentation","transformers","unet","unet-pytorch","unetplusplus"],"latest_commit_sha":null,"homepage":"https://smp.readthedocs.io/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/qubvel-org.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":null,"patreon":null,"open_collective":null,"ko_fi":"qubvel","tidelift":null,"community_bridge":null,"liberapay":"qubvel","issuehunt":null,"otechie":null,"custom":null}},"created_at":"2019-03-01T16:21:21.000Z","updated_at":"2025-05-07T09:44:34.000Z","dependencies_parsed_at":"2024-04-23T14:27:48.215Z","dependency_job_id":"2fdf67c2-9cd5-4022-8aa6-5ef634fbef41","html_url":"https://github.com/qubvel-org/segmentation_models.pytorch","commit_stats":{"total_commits":293,"total_committers":56,"mean_commits":5.232142857142857,"dds":0.4505119453924915,"last_synced_commit":"3ac1ca8ce606bad77acd748c236275fc40bddab5"},"previous_names":["qubvel-org/segmentation_models.pytorch","qubvel/segmentation_models.pytorch"],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qubvel-org%2Fsegmentation_models.pytorch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qubvel-org%2Fsegmentation_models.pytorch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qubvel-org%2Fsegmentation_models.pytorch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qubvel-org%2Fsegmentation_models.pytorch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/qubvel-org","download_url":"https://codeload.github.com/qubvel-org/segmentation_models.pytorch/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253554082,"owners_count":21926611,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["computer-vision","deeplab-v3-plus","deeplabv3","dpt","fpn","image-processing","image-segmentation","imagenet","models","pretrained-weights","pspnet","pytorch","segformer","segmentation","segmentation-models","semantic-segmentation","transformers","unet","unet-pytorch","unetplusplus"],"created_at":"2024-07-17T02:05:14.558Z","updated_at":"2025-09-09T19:53:28.281Z","avatar_url":"https://github.com/qubvel-org.png","language":"Python","funding_links":["https://ko-fi.com/qubvel","https://liberapay.com/qubvel"],"categories":["💻 Implementations","Frameworks for segmentation","Python","Computer vision","Research \u0026 Data Analysis"],"sub_categories":["🐍 PyTorch Implementations","General-purpose research / production frameworks","OGC Features"],"readme":"\u003cdiv align=\"center\"\u003e\n \n![logo](https://i.ibb.co/dc1XdhT/Segmentation-Models-V2-Side-1-1.png)  \n**Python library with Neural Networks for Image Semantic  \nSegmentation based on [PyTorch](https://pytorch.org/).**  \n\n \n[![GitHub Workflow Status (branch)](https://img.shields.io/github/actions/workflow/status/qubvel/segmentation_models.pytorch/tests.yml?branch=main\u0026style=for-the-badge)](https://github.com/qubvel/segmentation_models.pytorch/actions/workflows/tests.yml) \n![Codecov](https://img.shields.io/codecov/c/github/qubvel-org/segmentation_models.pytorch?style=for-the-badge)\n[![Read the Docs](https://img.shields.io/readthedocs/smp?style=for-the-badge\u0026logo=readthedocs\u0026logoColor=white)](https://smp.readthedocs.io/en/latest/) \n\u003cbr\u003e\n[![PyPI](https://img.shields.io/pypi/v/segmentation-models-pytorch?color=red\u0026style=for-the-badge\u0026logo=pypi\u0026logoColor=white)](https://pypi.org/project/segmentation-models-pytorch/) \n[![PyTorch - Version](https://img.shields.io/badge/PYTORCH-1.9+-red?style=for-the-badge\u0026logo=pytorch)](https://pepy.tech/project/segmentation-models-pytorch) \n[![Python - Version](https://img.shields.io/badge/PYTHON-3.9+-red?style=for-the-badge\u0026logo=python\u0026logoColor=white)](https://pepy.tech/project/segmentation-models-pytorch) \n\u003cbr\u003e\n[![Generic badge](https://img.shields.io/badge/License-MIT-\u003cCOLOR\u003e.svg?style=for-the-badge\u0026color=blue)](https://github.com/qubvel/segmentation_models.pytorch/blob/main/LICENSE)\n[![PyPI - Downloads](https://img.shields.io/pypi/dm/segmentation-models-pytorch?style=for-the-badge\u0026color=blue)](https://pepy.tech/project/segmentation-models-pytorch) \n\n\u003c/div\u003e\n\nThe main features of the library are:\n\n - Super simple high-level API (just two lines to create a neural network)\n - 12 encoder-decoder model architectures (Unet, Unet++, Segformer, DPT, ...)\n - 800+ **pretrained** convolution- and transform-based encoders, including [timm](https://github.com/huggingface/pytorch-image-models) support\n - Popular metrics and losses for training routines (Dice, Jaccard, Tversky, ...)\n - ONNX export and torch script/trace/compile friendly\n\n### Community-driven Project, Supported by GitAds\n\u003ca href=\"https://gitads.dev/v1/ad-track?source=qubvel-org/segmentation_models.pytorch@github\" target=\"_blank\" rel=\"noopener\"\u003e\n  \u003cimg \n    src=\"https://gitads.dev/v1/ad-serve?source=qubvel-org/segmentation_models.pytorch@github\" \n    alt=\"Sponsored by GitAds\" \n    style=\"width:400px; height:auto;\" /\u003e\n\u003c/a\u003e\n\n\n### [📚 Project Documentation 📚](http://smp.readthedocs.io/)\n\nVisit [Read The Docs Project Page](https://smp.readthedocs.io/) or read the following README to know more about Segmentation Models Pytorch (SMP for short) library\n\n### 📋 Table of content\n 1. [Quick start](#start)\n 2. [Examples](#examples)\n 3. [Models and encoders](#models-and-encoders)\n 4. [Models API](#api)\n    1. [Input channels](#input-channels)\n    2. [Auxiliary classification output](#auxiliary-classification-output)\n    3. [Depth](#depth)\n 5. [Installation](#installation)\n 6. [Competitions won with the library](#competitions)\n 7. [Contributing](#contributing)\n 8. [Citing](#citing)\n 9. [License](#license)\n\n## ⏳ Quick start \u003ca name=\"start\"\u003e\u003c/a\u003e\n\n#### 1. Create your first Segmentation model with SMP\n\nThe segmentation model is just a PyTorch `torch.nn.Module`, which can be created as easy as:\n\n```python\nimport segmentation_models_pytorch as smp\n\nmodel = smp.Unet(\n    encoder_name=\"resnet34\",        # choose encoder, e.g. mobilenet_v2 or efficientnet-b7\n    encoder_weights=\"imagenet\",     # use `imagenet` pre-trained weights for encoder initialization\n    in_channels=1,                  # model input channels (1 for gray-scale images, 3 for RGB, etc.)\n    classes=3,                      # model output channels (number of classes in your dataset)\n)\n```\n - see [table](#architectures) with available model architectures\n - see [table](#encoders) with available encoders and their corresponding weights\n\n#### 2. Configure data preprocessing\n\nAll encoders have pretrained weights. Preparing your data the same way as during weights pre-training may give you better results (higher metric score and faster convergence). It is **not necessary** in case you train the whole model, not only the decoder.\n\n```python\nfrom segmentation_models_pytorch.encoders import get_preprocessing_fn\n\npreprocess_input = get_preprocessing_fn('resnet18', pretrained='imagenet')\n```\n\nCongratulations! You are done! Now you can train your model with your favorite framework!\n\n## 💡 Examples \u003ca name=\"examples\"\u003e\u003c/a\u003e\n\n| Name                                      | Link                                                                                           | Colab                                                                                           |\n|-------------------------------------------|-----------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------|\n| **Train** pets binary segmentation on OxfordPets     | [Notebook](https://github.com/qubvel/segmentation_models.pytorch/blob/main/examples/binary_segmentation_intro.ipynb) | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/qubvel/segmentation_models.pytorch/blob/main/examples/binary_segmentation_intro.ipynb) |\n| **Train** cars binary segmentation on CamVid       | [Notebook](https://github.com/qubvel/segmentation_models.pytorch/blob/main/examples/cars%20segmentation%20(camvid).ipynb) | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/qubvel/segmentation_models.pytorch/blob/main/examples/cars%20segmentation%20(camvid).ipynb) |\n| **Train** multiclass segmentation on CamVid          | [Notebook](https://github.com/qubvel-org/segmentation_models.pytorch/blob/main/examples/camvid_segmentation_multiclass.ipynb) | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/qubvel-org/segmentation_models.pytorch/blob/main/examples/camvid_segmentation_multiclass.ipynb) |\n| **Train** clothes binary segmentation by @ternaus   | [Repo](https://github.com/ternaus/cloths_segmentation)                                        |     |\n| **Load and inference** pretrained Segformer | [Notebook](https://github.com/qubvel-org/segmentation_models.pytorch/blob/main/examples/segformer_inference_pretrained.ipynb) | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/qubvel/segmentation_models.pytorch/blob/main/examples/segformer_inference_pretrained.ipynb) |\n| **Load and inference** pretrained DPT | [Notebook](https://github.com/qubvel-org/segmentation_models.pytorch/blob/main/examples/dpt_inference_pretrained.ipynb) | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/qubvel/segmentation_models.pytorch/blob/main/examples/dpt_inference_pretrained.ipynb) |\n| **Load and inference** pretrained UPerNet | [Notebook](https://github.com/qubvel-org/segmentation_models.pytorch/blob/main/examples/upernet_inference_pretrained.ipynb) | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/qubvel/segmentation_models.pytorch/blob/main/examples/upernet_inference_pretrained.ipynb) |\n| **Save and load** models locally / to HuggingFace Hub |[Notebook](https://github.com/qubvel-org/segmentation_models.pytorch/blob/main/examples/save_load_model_and_share_with_hf_hub.ipynb) | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/qubvel/segmentation_models.pytorch/blob/main/examples/save_load_model_and_share_with_hf_hub.ipynb)\n| **Export** trained model to ONNX              | [Notebook](https://github.com/qubvel/segmentation_models.pytorch/blob/main/examples/convert_to_onnx.ipynb) | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/qubvel/segmentation_models.pytorch/blob/main/examples/convert_to_onnx.ipynb) |\n\n\n## 📦 Models and encoders \u003ca name=\"models-and-encoders\"\u003e\u003c/a\u003e\n\n### Architectures \u003ca name=\"architectures\"\u003e\u003c/a\u003e\n| Architecture | Paper | Documentation | Checkpoints |\n|--------------|-------|---------------|------------|\n| Unet | [paper](https://arxiv.org/abs/1505.04597) | [docs](https://smp.readthedocs.io/en/latest/models.html#unet) | |\n| Unet++ | [paper](https://arxiv.org/pdf/1807.10165.pdf) | [docs](https://smp.readthedocs.io/en/latest/models.html#unetplusplus) | |\n| MAnet | [paper](https://ieeexplore.ieee.org/abstract/document/9201310) | [docs](https://smp.readthedocs.io/en/latest/models.html#manet) | |\n| Linknet | [paper](https://arxiv.org/abs/1707.03718) | [docs](https://smp.readthedocs.io/en/latest/models.html#linknet) | |\n| FPN | [paper](http://presentations.cocodataset.org/COCO17-Stuff-FAIR.pdf) | [docs](https://smp.readthedocs.io/en/latest/models.html#fpn) | |\n| PSPNet | [paper](https://arxiv.org/abs/1612.01105) | [docs](https://smp.readthedocs.io/en/latest/models.html#pspnet) | |\n| PAN | [paper](https://arxiv.org/abs/1805.10180) | [docs](https://smp.readthedocs.io/en/latest/models.html#pan) | |\n| DeepLabV3 | [paper](https://arxiv.org/abs/1706.05587) | [docs](https://smp.readthedocs.io/en/latest/models.html#deeplabv3) | |\n| DeepLabV3+ | [paper](https://arxiv.org/abs/1802.02611) | [docs](https://smp.readthedocs.io/en/latest/models.html#deeplabv3plus) | |\n| UPerNet | [paper](https://arxiv.org/abs/1807.10221) | [docs](https://smp.readthedocs.io/en/latest/models.html#upernet) | [checkpoints](https://huggingface.co/collections/smp-hub/upernet-67fadcdbe08418c6ea94f768) |\n| Segformer | [paper](https://arxiv.org/abs/2105.15203) | [docs](https://smp.readthedocs.io/en/latest/models.html#segformer) | [checkpoints](https://huggingface.co/collections/smp-hub/segformer-6749eb4923dea2c355f29a1f) |\n| DPT | [paper](https://arxiv.org/abs/2103.13413) | [docs](https://smp.readthedocs.io/en/latest/models.html#dpt) | [checkpoints](https://huggingface.co/collections/smp-hub/dpt-67f30487327c0599a0c62d68) |\n\n### Encoders \u003ca name=\"encoders\"\u003e\u003c/a\u003e\n\nThe library provides a wide range of **pretrained** encoders (also known as backbones) for segmentation models. Instead of using features from the final layer of a classification model, we extract **intermediate features** and feed them into the decoder for segmentation tasks.  \n\nAll encoders come with **pretrained weights**, which help achieve **faster and more stable convergence** when training segmentation models.  \n\nGiven the extensive selection of supported encoders, you can choose the best one for your specific use case, for example:  \n- **Lightweight encoders** for low-latency applications or real-time inference on edge devices (mobilenet/mobileone).  \n- **High-capacity architectures** for complex tasks involving a large number of segmented classes, providing superior accuracy (convnext/swin/mit).  \n\nBy selecting the right encoder, you can balance **efficiency, performance, and model complexity** to suit your project needs.  \n\nAll encoders and corresponding pretrained weight are listed in the documentation:\n - [table](https://smp.readthedocs.io/en/latest/encoders.html) with natively ported encoders \n - [table](https://smp.readthedocs.io/en/latest/encoders_timm.html) with [timm](https://github.com/huggingface/pytorch-image-models) encoders supported\n\n## 🔁 Models API \u003ca name=\"api\"\u003e\u003c/a\u003e\n\n### Input channels\n\nThe input channels parameter allows you to create a model that can process a tensor with an arbitrary number of channels. \nIf you use pretrained weights from ImageNet, the weights of the first convolution will be reused:\n - For the 1-channel case, it would be a sum of the weights of the first convolution layer.\n - Otherwise, channels would be populated with weights like `new_weight[:, i] = pretrained_weight[:, i % 3]`, and then scaled with `new_weight * 3 / new_in_channels`.\n\n```python\nmodel = smp.FPN('resnet34', in_channels=1)\nmask = model(torch.ones([1, 1, 64, 64]))\n```\n\n### Auxiliary classification output\n\nAll models support `aux_params` parameters, which is default set to `None`. \nIf `aux_params = None` then classification auxiliary output is not created, else\nmodel produce not only `mask`, but also `label` output with shape `NC`.\nClassification head consists of GlobalPooling-\u003eDropout(optional)-\u003eLinear-\u003eActivation(optional) layers, which can be \nconfigured by `aux_params` as follows:\n```python\naux_params=dict(\n    pooling='avg',             # one of 'avg', 'max'\n    dropout=0.5,               # dropout ratio, default is None\n    activation='sigmoid',      # activation function, default is None\n    classes=4,                 # define number of output labels\n)\nmodel = smp.Unet('resnet34', classes=4, aux_params=aux_params)\nmask, label = model(x)\n```\n\n### Depth\n\nDepth parameter specify a number of downsampling operations in encoder, so you can make\nyour model lighter if specify smaller `depth`.\n```python\nmodel = smp.Unet('resnet34', encoder_depth=4)\n```\n\n## 🛠 Installation \u003ca name=\"installation\"\u003e\u003c/a\u003e\nPyPI version:\n\n```bash\n$ pip install segmentation-models-pytorch\n````\n\nThe latest version from GitHub:\n\n```bash\n$ pip install git+https://github.com/qubvel/segmentation_models.pytorch\n````\n\n## 🏆 Competitions won with the library \u003ca name=\"competitions\"\u003e\u003c/a\u003e\n\n`Segmentation Models` package is widely used in image segmentation competitions.\n[Here](https://github.com/qubvel/segmentation_models.pytorch/blob/main/HALLOFFAME.md) you can find competitions, names of the winners and links to their solutions.\n\n## 🤝 Contributing \u003ca name=\"contributing\"\u003e\u003c/a\u003e\n\n1. Install SMP in dev mode\n\n```bash\nmake install_dev  # Create .venv, install SMP in dev mode\n```\n\n2. Run tests and code checks\n\n```bash\nmake test          # Run tests suite with pytest\nmake fixup         # Ruff for formatting and lint checks\n```\n\n3. Update a table (in case you added an encoder)\n\n```bash\nmake table        # Generates a table with encoders and print to stdout\n```\n\n## 📝 Citing \u003ca name=\"citing\"\u003e\u003c/a\u003e\n```\n@misc{Iakubovskii:2019,\n  Author = {Pavel Iakubovskii},\n  Title = {Segmentation Models Pytorch},\n  Year = {2019},\n  Publisher = {GitHub},\n  Journal = {GitHub repository},\n  Howpublished = {\\url{https://github.com/qubvel/segmentation_models.pytorch}}\n}\n```\n\n## 🛡️ License \u003ca name=\"license\"\u003e\u003c/a\u003e\nThe project is primarily distributed under [MIT License](https://github.com/qubvel/segmentation_models.pytorch/blob/main/LICENSE), while some files are subject to other licenses. Please refer to [LICENSES](licenses/LICENSES.md) and license statements in each file for careful check, especially for commercial use.\n\n\u003c!-- GitAds-Verify: T1452I5Y1X6LC6PFHM9EMDOETGQEU72P --\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fqubvel-org%2Fsegmentation_models.pytorch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fqubvel-org%2Fsegmentation_models.pytorch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fqubvel-org%2Fsegmentation_models.pytorch/lists"}