Skip to content

[pull] master from qubvel:master #72

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 53 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
a469f86
Add metrics (#531)
qubvel Jan 5, 2022
bc597e9
Add black and flake8 (#532)
qubvel Jan 5, 2022
f29cb95
Add preprocessing for timm (#533)
qubvel Jan 6, 2022
c48c906
Add MCC loss (#534)
qubvel Jan 6, 2022
06fdd31
Update badges
qubvel Jan 11, 2022
428cddc
Fix the wrong stat & accuracy calculation (#539)
AlbertYang0112 Jan 17, 2022
2447352
Stale workflow
qubvel Jan 30, 2022
7b22ad7
Fix ignore_index for multiclass metric computation (#547)
qubvel Jan 30, 2022
e0d8320
Correct exception for dilated models
qubvel Jan 30, 2022
15fede2
Add check for input shape (#549)
qubvel Jan 30, 2022
40d0a71
Update stale.yaml
qubvel Jan 31, 2022
8bf52c7
Update __version__.py
qubvel Feb 2, 2022
740dab5
Update black
qubvel Apr 6, 2022
d316fbf
Modifying efficientnet version requirement (#581)
cmamba Jul 29, 2022
560e8ff
Update dice.py (#608)
yashika-git Jul 29, 2022
84535fa
Correct docstring FNs -> False Negatives (#592)
vietanhdev Jul 29, 2022
13d5653
Update black formatting
qubvel Jul 29, 2022
2b6878c
Update version 0.3.0
qubvel Jul 29, 2022
66f998a
Update README.md
qubvel Jul 29, 2022
d7d46bd
Add dependabot
qubvel Jul 29, 2022
c98c88d
Merge branch 'master' of github.com:qubvel/segmentation_models.pytorch
qubvel Jul 29, 2022
b5981e7
Fix link to colab #628
qubvel Aug 5, 2022
f58fd6d
Update the description of TverskyLoss (#626)
gracikk-ds Aug 7, 2022
792c273
Segformer backbone Mix Visual Transformer (#632)
qubvel Aug 8, 2022
69c053a
Fix markdown for table (#650)
MichaelMonashev Sep 1, 2022
1fa49d0
typo correction (#638)
lappemic Sep 1, 2022
5be2567
fix return type of get_stats (#676)
kaczmarj Nov 11, 2022
369df25
Fix PyPI link in README (#658)
remram44 Nov 11, 2022
6bcf287
Yakubovskiy -> Iakubovskii (#656)
MichaelMonashev Nov 11, 2022
7dc22c8
Create devcontainer.json
qubvel Nov 28, 2022
ed22b42
Update README.md
qubvel Nov 29, 2022
fdb024b
Bump version
qubvel Nov 30, 2022
b3cbb75
Change error string in functional.py (#694)
NitzanMadar Dec 14, 2022
5ab92db
Correct functional.py _compute_metric (#659)
Abd-elr4hman Dec 14, 2022
fa3ac89
Fix formatting
qubvel Dec 14, 2022
519d358
timm upgrade 0.6.12 (#696)
VadimLevin Dec 15, 2022
c2fce7b
Add Apple's MobileOne encoder (#693)
kevinpl07 Dec 15, 2022
478b7d2
Update README.md
qubvel Dec 15, 2022
c39de0c
Release update 0.3.2 (#705)
qubvel Jan 7, 2023
8523324
Fix the python min version (#711)
qubvel Jan 21, 2023
95f4635
Bump timm from 0.6.12 to 0.6.13 (#739)
dependabot[bot] Mar 24, 2023
e7cbea0
Update HALLOFFAME.md (#740)
Mar 24, 2023
e5d3db2
Bump timm from 0.6.13 to 0.9.2 (#768)
qubvel May 28, 2023
67aceba
Bump timm from 0.9.2 to 0.9.5 (#799)
dependabot[bot] Aug 7, 2023
6db76a1
Bump timm from 0.9.5 to 0.9.7 (#807)
dependabot[bot] Sep 4, 2023
b081758
In albumentations >= 1.4.0 the "imgaug" library was removed. some fun…
CallShaul Apr 23, 2024
3bf4d6e
Updated false positve and false negative rate functions in functional…
vermavinay982 Apr 30, 2024
f09be0a
Add HF hub mixin (#876)
qubvel May 30, 2024
8fcc1a3
use precommit for code linting (#829)
Borda May 30, 2024
ded60a4
Add Ruff for formatting and linting (#877)
qubvel May 30, 2024
b948136
Add docs config (#878)
qubvel May 31, 2024
3d6da1d
Update docs (#879)
qubvel May 31, 2024
bd7f877
Add create model to docs (#883)
qubvel Jun 5, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"image": "mcr.microsoft.com/devcontainers/universal:2",
"features": {
"ghcr.io/devcontainers/features/python:1": {
"verison": 3.6
}
}
}
11 changes: 11 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: 2
updates:
- package-ecosystem: "pip"
directory: "/"
schedule:
interval: "daily"
# Allow up to 2 open pull requests at a time
open-pull-requests-limit: 2
allow:
- dependency-name: "timm"
dependency-type: "all"
17 changes: 0 additions & 17 deletions .github/stale.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.6'
python-version: '3.7'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
Expand Down
21 changes: 21 additions & 0 deletions .github/workflows/stale.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: 'Close stale issues and PRs'
on:
schedule:
- cron: '30 1 * * *'

jobs:
stale:
runs-on: ubuntu-latest
steps:
- uses: actions/stale@v4
with:
stale-issue-message: 'This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days.'
stale-pr-message: 'This PR is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 15 days.'
close-issue-message: 'This issue was closed because it has been stalled for 7 days with no activity.'
close-pr-message: 'This PR was closed because it has been stalled for 15 days with no activity.'
days-before-issue-stale: 60
days-before-pr-stale: 60
days-before-issue-close: 7
days-before-pr-close: 15
operations-per-run: 100
ascending: true
37 changes: 26 additions & 11 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,39 @@ on:
branches: [ master ]

jobs:
test:

runs-on: ubuntu-18.04
style:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install ruff==0.4.6
# Update output format to enable automatic inline annotations.
- name: Run Ruff Linter
run: ruff check --output-format=github
- name: Run Ruff Formatter
run: ruff format --check

test:
runs-on: ubuntu-latest
needs: [style]
steps:
- uses: actions/checkout@v2

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: 3.6

python-version: 3.7
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install codecov pytest mock
pip3 install torch==1.9.0+cpu torchvision==0.10.0+cpu torchaudio==0.9.0 -f https://download.pytorch.org/whl/torch_stable.html
pip install .
- name: Test
run: |
python -m pytest -s tests
pip install torch==1.9.0+cpu torchvision==0.10.0+cpu -f https://download.pytorch.org/whl/torch_stable.html
make install_dev
- name: Test with pytest
run: make test

8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ __pycache__/
*.py[cod]
*$py.class
.idea/
.venv*
examples/images*
examples/annotations*

# C extensions
*.so
Expand Down Expand Up @@ -102,4 +105,7 @@ venv.bak/
/site

# mypy
.mypy_cache/
.mypy_cache/

# ruff
.ruff_cache/
22 changes: 22 additions & 0 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Read the Docs configuration file for Sphinx projects
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details

# Required
version: 2

# Set the OS, Python version and other tools you might need
build:
os: ubuntu-22.04
tools:
python: "3.12"

# Build documentation in the "docs/" directory with Sphinx
sphinx:
configuration: docs/conf.py

# Optional but recommended, declare the Python requirements required
# to build your documentation
# See https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html
python:
install:
- requirements: docs/requirements.txt
12 changes: 9 additions & 3 deletions HALLOFFAME.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Please, follow these rules, when adding a solution to the "Hall of Fame":
[[description](https://www.kaggle.com/c/severstal-steel-defect-detection/discussion/114465#latest-659615)]

- 12th place.
[Pavel Yakubovskiy](https://www.linkedin.com/in/pavel-yakubovskiy/),
[Pavel Iakubovskii](https://www.linkedin.com/in/pavel-iakubovskii/),
[Ilya Dobrynin](https://www.linkedin.com/in/ilya-dobrynin-79a89b106/),
[Denis Kolpakov](https://www.linkedin.com/in/denis-kolpakov-ab3137197/)
[[description](https://www.kaggle.com/c/severstal-steel-defect-detection/discussion/114309#latest-661404)]
Expand Down Expand Up @@ -72,7 +72,7 @@ Please, follow these rules, when adding a solution to the "Hall of Fame":
[[code](https://github.com/khornlund/understanding-cloud-organization)]

- 55th place.
[Pavel Yakubovskiy](https://www.linkedin.com/in/pavel-yakubovskiy/)
[Pavel Iakubovskii](https://www.linkedin.com/in/pavel-iakubovskii/)
[[description](https://www.kaggle.com/c/understanding_cloud_organization/discussion/118019#latest-678626)]

## Other platforms
Expand All @@ -85,7 +85,7 @@ Please, follow these rules, when adding a solution to the "Hall of Fame":

### [Open Cities AI Challenge: Segmenting Buildings for Disaster Resilience](https://www.drivendata.org/competitions/60/building-segmentation-disaster-resilience/)
- 1st place.
[Pavel Yakubovskiy](https://www.linkedin.com/in/pavel-yakubovskiy/).
[Pavel Iakubovskii](https://www.linkedin.com/in/pavel-iakubovskii/).
[[code and description](https://github.com/qubvel/open-cities-challenge)]

### [Machine Learning based feature extraction of Electrical Substations from Satellite Data ](https://competitions.codalab.org/competitions/32132#learn_the_details)
Expand All @@ -95,3 +95,9 @@ Please, follow these rules, when adding a solution to the "Hall of Fame":
[Aarsh chaube](https://github.com/Aarsh2001)
[[code](https://github.com/Aarsh2001/ML_Challenge_NRSC)]
[[Pre-Print](https://github.com/Aarsh2001/ML_Challenge_NRSC/blob/main/3rd%20Rank%20Submission.pdf)]

### [NeurIPS2022 Cell Segmentation Challenge](https://neurips22-cellseg.grand-challenge.org/)

- 1st place. [Gihun Lee](https://github.com/Lee-Gihun), [Sangmook Kim](https://github.com/ElvinKim), [Joonkee Kim](https://github.com/joonkeekim)
- [[code](https://github.com/Lee-Gihun/MEDIAR)]
[[Paper](https://arxiv.org/abs/2212.03465)]
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License

Copyright (c) 2019, Pavel Yakubovskiy
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 "Software"), to deal
Expand Down
23 changes: 23 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
.PHONY: test

.venv:
python3 -m venv .venv

install_dev: .venv
.venv/bin/pip install -e ".[test]"

test: .venv
.venv/bin/pytest -p no:cacheprovider tests/

table:
.venv/bin/python misc/generate_table.py

table_timm:
.venv/bin/python misc/generate_table_timm.py

fixup:
.venv/bin/ruff check --fix
.venv/bin/ruff format

all: fixup test

91 changes: 76 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,25 @@
**Python library with Neural Networks for Image
Segmentation based on [PyTorch](https://pytorch.org/).**

![PyPI version](https://badge.fury.io/py/segmentation-models-pytorch.svg) [![Build Status](https://travis-ci.com/qubvel/segmentation_models.pytorch.svg?branch=master)](https://travis-ci.com/qubvel/segmentation_models.pytorch) [![Documentation Status](https://readthedocs.org/projects/smp/badge/?version=latest)](https://smp.readthedocs.io/en/latest/?badge=latest) <br> ![Downloads](https://pepy.tech/badge/segmentation-models-pytorch) [![Generic badge](https://img.shields.io/badge/License-MIT-<COLOR>.svg)](https://shields.io/)
[![Generic badge](https://img.shields.io/badge/License-MIT-<COLOR>.svg?style=for-the-badge)](https://github.com/qubvel/segmentation_models.pytorch/blob/master/LICENSE)
[![GitHub Workflow Status (branch)](https://img.shields.io/github/actions/workflow/status/qubvel/segmentation_models.pytorch/tests.yml?branch=master&style=for-the-badge)](https://github.com/qubvel/segmentation_models.pytorch/actions/workflows/tests.yml)
[![Read the Docs](https://img.shields.io/readthedocs/smp?style=for-the-badge&logo=readthedocs&logoColor=white)](https://smp.readthedocs.io/en/latest/)
<br>
[![PyPI](https://img.shields.io/pypi/v/segmentation-models-pytorch?color=blue&style=for-the-badge&logo=pypi&logoColor=white)](https://pypi.org/project/segmentation-models-pytorch/)
[![PyPI - Downloads](https://img.shields.io/pypi/dm/segmentation-models-pytorch?style=for-the-badge&color=blue)](https://pepy.tech/project/segmentation-models-pytorch)
<br>
[![PyTorch - Version](https://img.shields.io/badge/PYTORCH-1.4+-red?style=for-the-badge&logo=pytorch)](https://pepy.tech/project/segmentation-models-pytorch)
[![Python - Version](https://img.shields.io/badge/PYTHON-3.7+-red?style=for-the-badge&logo=python&logoColor=white)](https://pepy.tech/project/segmentation-models-pytorch)

</div>

The main features of this library are:

- High level API (just two lines to create a neural network)
- 9 models architectures for binary and multi class segmentation (including legendary Unet)
- 113 available encoders
- 124 available encoders (and 500+ encoders from [timm](https://github.com/rwightman/pytorch-image-models))
- All encoders have pre-trained weights for faster and better convergence
- Popular metrics and losses for training routines

### [📚 Project Documentation 📚](http://smp.readthedocs.io/)

Expand Down Expand Up @@ -57,7 +66,7 @@ model = smp.Unet(

#### 2. Configure data preprocessing

All encoders have pretrained weights. Preparing your data the same way as during weights pre-training may give your better results (higher metric score and faster convergence). But it is relevant only for 1-2-3-channels images and **not necessary** in case you train the whole model, not only decoder.
All 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 decoder.

```python
from segmentation_models_pytorch.encoders import get_preprocessing_fn
Expand All @@ -68,9 +77,10 @@ preprocess_input = get_preprocessing_fn('resnet18', pretrained='imagenet')
Congratulations! You are done! Now you can train your model with your favorite framework!

### 💡 Examples <a name="examples"></a>
- Training model for pets binary segmentation with Pytorch-Lightning [notebook](https://github.com/qubvel/segmentation_models.pytorch/blob/master/examples/binary_segmentation_intro.ipynb) and [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/qubvel/segmentation_models.pytorch/blob/master/examples/binary_segmentation_intro.ipynb)
- Training model for cars segmentation on CamVid dataset [here](https://github.com/qubvel/segmentation_models.pytorch/blob/master/examples/cars%20segmentation%20(camvid).ipynb).
- Training SMP model with [Catalyst](https://github.com/catalyst-team/catalyst) (high-level framework for PyTorch), [TTAch](https://github.com/qubvel/ttach) (TTA library for PyTorch) and [Albumentations](https://github.com/albu/albumentations) (fast image augmentation library) - [here](https://github.com/catalyst-team/catalyst/blob/master/examples/notebooks/segmentation-tutorial.ipynb) [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/catalyst-team/catalyst/blob/master/examples/notebooks/segmentation-tutorial.ipynb)
- Training SMP model with [Pytorch-Lightning](https://pytorch-lightning.readthedocs.io) framework - [here](https://github.com/ternaus/cloths_segmentation) (clothes binary segmentation by [@teranus](https://github.com/ternaus)).
- Training SMP model with [Catalyst](https://github.com/catalyst-team/catalyst) (high-level framework for PyTorch), [TTAch](https://github.com/qubvel/ttach) (TTA library for PyTorch) and [Albumentations](https://github.com/albu/albumentations) (fast image augmentation library) - [here](https://github.com/catalyst-team/catalyst/blob/v21.02rc0/examples/notebooks/segmentation-tutorial.ipynb) [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/catalyst-team/catalyst/blob/v21.02rc0/examples/notebooks/segmentation-tutorial.ipynb)
- Training SMP model with [Pytorch-Lightning](https://pytorch-lightning.readthedocs.io) framework - [here](https://github.com/ternaus/cloths_segmentation) (clothes binary segmentation by [@ternaus](https://github.com/ternaus)).

### 📦 Models <a name="models"></a>

Expand Down Expand Up @@ -342,6 +352,48 @@ The following is a list of supported encoders in the SMP. Select the appropriate
</div>
</details>

<details>
<summary style="margin-left: 25px;">Mix Vision Transformer</summary>
<div style="margin-left: 25px;">

Backbone from SegFormer pretrained on Imagenet! Can be used with other decoders from package, you can combine Mix Vision Transformer with Unet, FPN and others!

Limitations:

- encoder is **not** supported by Linknet, Unet++
- encoder is supported by FPN only for encoder **depth = 5**

|Encoder |Weights |Params, M |
|--------------------------------|:------------------------------:|:------------------------------:|
|mit_b0 |imagenet |3M |
|mit_b1 |imagenet |13M |
|mit_b2 |imagenet |24M |
|mit_b3 |imagenet |44M |
|mit_b4 |imagenet |60M |
|mit_b5 |imagenet |81M |

</div>
</details>

<details>
<summary style="margin-left: 25px;">MobileOne</summary>
<div style="margin-left: 25px;">

Apple's "sub-one-ms" Backbone pretrained on Imagenet! Can be used with all decoders.

Note: In the official github repo the s0 variant has additional num_conv_branches, leading to more params than s1.

|Encoder |Weights |Params, M |
|--------------------------------|:------------------------------:|:------------------------------:|
|mobileone_s0 |imagenet |4.6M |
|mobileone_s1 |imagenet |4.0M |
|mobileone_s2 |imagenet |6.5M |
|mobileone_s3 |imagenet |8.8M |
|mobileone_s4 |imagenet |13.6M |

</div>
</details>


\* `ssl`, `swsl` - semi-supervised and weakly-supervised learning on ImageNet ([repo](https://github.com/facebookresearch/semi-supervised-ImageNet1K-models)).

Expand All @@ -351,10 +403,10 @@ The following is a list of supported encoders in the SMP. Select the appropriate

Pytorch Image Models (a.k.a. timm) has a lot of pretrained models and interface which allows using these models as encoders in smp, however, not all models are supported

- transformer models do not have ``features_only`` functionality implemented
- some models do not have appropriate strides
- not all transformer models have ``features_only`` functionality implemented that is required for encoder
- some models have inappropriate strides

Total number of supported encoders: 467
Total number of supported encoders: 549
- [table with available encoders](https://smp.readthedocs.io/en/latest/encoders_timm.html)

### 🔁 Models API <a name="api"></a>
Expand Down Expand Up @@ -417,21 +469,30 @@ $ pip install git+https://github.com/qubvel/segmentation_models.pytorch

### 🤝 Contributing

##### Run test
#### Install SMP

```bash
$ docker build -f docker/Dockerfile.dev -t smp:dev . && docker run --rm smp:dev pytest -p no:cacheprovider
make install_dev # create .venv, install SMP in dev mode
```
##### Generate table

#### Run tests and code checks

```bash
make fixup # Ruff for formatting and lint checks
```

#### Update table with encoders

```bash
$ docker build -f docker/Dockerfile.dev -t smp:dev . && docker run --rm smp:dev python misc/generate_table.py
make table # generate table with encoders and print to stdout
```

### 📝 Citing
```
@misc{Yakubovskiy:2019,
Author = {Pavel Yakubovskiy},
@misc{Iakubovskii:2019,
Author = {Pavel Iakubovskii},
Title = {Segmentation Models Pytorch},
Year = {2020},
Year = {2019},
Publisher = {GitHub},
Journal = {GitHub repository},
Howpublished = {\url{https://github.com/qubvel/segmentation_models.pytorch}}
Expand Down
1 change: 0 additions & 1 deletion __init__.py

This file was deleted.

Loading