<div align="center">
<h1>
Pretrained Backbones with UNet
</h1>
<div>
**A [PyTorch](https://pytorch.org/)-based Python library with UNet architecture and multiple backbones for Image Semantic Segmentation.**
[![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)
[![PyPI](https://img.shields.io/pypi/v/pretrained-backbones-unet?color=blue&style=for-the-badge&logo=pypi&logoColor=white)](https://pypi.org/project/pretrained-backbones-unet/)
[![PyPI - Downloads](https://img.shields.io/pypi/dm/pretrained-backbones-unet?style=for-the-badge&color=blue)](https://pepy.tech/project/pretrained-backbones-unet)
<br>
[![PyTorch - Version](https://img.shields.io/badge/PYTORCH-1.9+-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>
</div>
## <div align="center">Overview</div>
This is a simple package for semantic segmentation with [UNet](https://arxiv.org/pdf/1505.04597.pdf) and pretrained backbones. This package utilizes the [timm models](https://pypi.org/project/timm/) for the pre-trained encoders.
When dealing with relatively limited datasets, initializing a model using pre-trained weights from a large dataset can be an excellent choice for ensuring successful network training. By utilizing state-of-the-art models, such as ConvNeXt, as an encoder, you can effortlessly solve the problem at hand while achieving optimal performance in this context.
The primary characteristics of this library are as follows:
* 430 pre-trained backbone networks are available for the UNet semantic segmentation model.
* Supports backbone networks such as ConvNext, ResNet, EfficientNet, DenseNet, RegNet, and VGG... which are popular and SOTA performers, for the UNet model.
* It is possible to adjust which layers of the backbone of the model are trainable parametrically.
* It includes a DataSet class for binary and multi-class semantic segmentation.
* And it comes with a pre-built rapid custom training class.
## Installation
### Pypi version:
```
pip install pretrained-backbones-unet
```
### Source code version:
```
pip install git+https://github.com/mberkay0/pretrained-backbones-unet
```
## Usage
```python
from backbones_unet.model.unet import Unet
from backbones_unet.utils.dataset import SemanticSegmentationDataset
from backbones_unet.model.losses import DiceLoss
from backbones_unet.utils.trainer import Trainer
# create a torch.utils.data.Dataset/DataLoader
train_img_path = 'example_data/train/images'
train_mask_path = 'example_data/train/masks'
val_img_path = 'example_data/val/images'
val_mask_path = 'example_data/val/masks'
train_dataset = SemanticSegmentationDataset(train_img_path, train_mask_path)
val_dataset = SemanticSegmentationDataset(val_img_path, val_mask_path)
train_loader = DataLoader(train_dataset, batch_size=2)
val_loader = DataLoader(val_dataset, batch_size=2)
model = Unet(
backbone='convnext_base', # backbone network name
in_channels=3, # input channels (1 for gray-scale images, 3 for RGB, etc.)
num_classes=1, # output channels (number of classes in your dataset)
)
params = [p for p in model.parameters() if p.requires_grad]
optimizer = torch.optim.AdamW(params, 1e-4)
trainer = Trainer(
model, # UNet model with pretrained backbone
criterion=DiceLoss(), # loss function for model convergence
optimizer, # optimizer for regularization
10 # number of epochs for model training
)
trainer.fit(train_loader, val_loader)
```
## Available Pretrained Backbones
```python
import backbones_unet
print(backbones_unet.__available_models__)
```
Raw data
{
"_id": null,
"home_page": "https://github.com/mberkay0/pretrained-backbones-unet",
"name": "pretrained-backbones-unet",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": "",
"keywords": "machine-learning,deep-learning,pytorch,vision,semantic-segmentation,image-pixel-classification,object-detection,convnext,unet",
"author": "Berkay Mayali",
"author_email": "Example Author <author@example.com>",
"download_url": "https://files.pythonhosted.org/packages/54/a5/3587d59abd6375a79ea0627a169c0ff79de2685c7e6c087601d65ab5b1d3/pretrained-backbones-unet-0.0.1.tar.gz",
"platform": null,
"description": "<div align=\"center\">\r\n<h1>\r\n Pretrained Backbones with UNet\r\n</h1>\r\n<div>\r\n\r\n**A [PyTorch](https://pytorch.org/)-based Python library with UNet architecture and multiple backbones for Image Semantic Segmentation.**\r\n\r\n\r\n[![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) \r\n[![PyPI](https://img.shields.io/pypi/v/pretrained-backbones-unet?color=blue&style=for-the-badge&logo=pypi&logoColor=white)](https://pypi.org/project/pretrained-backbones-unet/) \r\n[![PyPI - Downloads](https://img.shields.io/pypi/dm/pretrained-backbones-unet?style=for-the-badge&color=blue)](https://pepy.tech/project/pretrained-backbones-unet) \r\n<br>\r\n[![PyTorch - Version](https://img.shields.io/badge/PYTORCH-1.9+-red?style=for-the-badge&logo=pytorch)](https://pepy.tech/project/segmentation-models-pytorch) \r\n[![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) \r\n</div>\r\n</div>\r\n\r\n## <div align=\"center\">Overview</div>\r\n\r\nThis is a simple package for semantic segmentation with [UNet](https://arxiv.org/pdf/1505.04597.pdf) and pretrained backbones. This package utilizes the [timm models](https://pypi.org/project/timm/) for the pre-trained encoders.\r\n\r\nWhen dealing with relatively limited datasets, initializing a model using pre-trained weights from a large dataset can be an excellent choice for ensuring successful network training. By utilizing state-of-the-art models, such as ConvNeXt, as an encoder, you can effortlessly solve the problem at hand while achieving optimal performance in this context.\r\n\r\nThe primary characteristics of this library are as follows:\r\n* 430 pre-trained backbone networks are available for the UNet semantic segmentation model.\r\n\r\n* Supports backbone networks such as ConvNext, ResNet, EfficientNet, DenseNet, RegNet, and VGG... which are popular and SOTA performers, for the UNet model.\r\n\r\n* It is possible to adjust which layers of the backbone of the model are trainable parametrically.\r\n\r\n* It includes a DataSet class for binary and multi-class semantic segmentation.\r\n\r\n* And it comes with a pre-built rapid custom training class.\r\n## Installation\r\n\r\n### Pypi version:\r\n```\r\npip install pretrained-backbones-unet\r\n```\r\n\r\n### Source code version:\r\n```\r\npip install git+https://github.com/mberkay0/pretrained-backbones-unet\r\n```\r\n\r\n## Usage\r\n```python\r\nfrom backbones_unet.model.unet import Unet\r\nfrom backbones_unet.utils.dataset import SemanticSegmentationDataset\r\nfrom backbones_unet.model.losses import DiceLoss\r\nfrom backbones_unet.utils.trainer import Trainer\r\n\r\n# create a torch.utils.data.Dataset/DataLoader\r\ntrain_img_path = 'example_data/train/images' \r\ntrain_mask_path = 'example_data/train/masks'\r\n\r\nval_img_path = 'example_data/val/images' \r\nval_mask_path = 'example_data/val/masks'\r\n\r\ntrain_dataset = SemanticSegmentationDataset(train_img_path, train_mask_path)\r\nval_dataset = SemanticSegmentationDataset(val_img_path, val_mask_path)\r\n\r\ntrain_loader = DataLoader(train_dataset, batch_size=2)\r\nval_loader = DataLoader(val_dataset, batch_size=2)\r\n\r\nmodel = Unet(\r\n backbone='convnext_base', # backbone network name\r\n in_channels=3, # input channels (1 for gray-scale images, 3 for RGB, etc.)\r\n num_classes=1, # output channels (number of classes in your dataset)\r\n)\r\n\r\nparams = [p for p in model.parameters() if p.requires_grad]\r\noptimizer = torch.optim.AdamW(params, 1e-4) \r\n\r\ntrainer = Trainer(\r\n model, # UNet model with pretrained backbone\r\n criterion=DiceLoss(), # loss function for model convergence\r\n optimizer, # optimizer for regularization\r\n 10 # number of epochs for model training\r\n)\r\n\r\ntrainer.fit(train_loader, val_loader)\r\n```\r\n\r\n## Available Pretrained Backbones\r\n```python\r\nimport backbones_unet\r\n\r\nprint(backbones_unet.__available_models__)\r\n```\r\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A small example package",
"version": "0.0.1",
"split_keywords": [
"machine-learning",
"deep-learning",
"pytorch",
"vision",
"semantic-segmentation",
"image-pixel-classification",
"object-detection",
"convnext",
"unet"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "dc85b0b91ef867b431cb7c778496e612190b0f83acae543006967855fe7e6d4a",
"md5": "d01f924a7bd3bcffd31df66ce4867d26",
"sha256": "27d3438b935736e95ea930c9c8c05167c2304d52c1096ce0022b327c025cd6f1"
},
"downloads": -1,
"filename": "pretrained_backbones_unet-0.0.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "d01f924a7bd3bcffd31df66ce4867d26",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 15712,
"upload_time": "2023-03-10T22:26:35",
"upload_time_iso_8601": "2023-03-10T22:26:35.877543Z",
"url": "https://files.pythonhosted.org/packages/dc/85/b0b91ef867b431cb7c778496e612190b0f83acae543006967855fe7e6d4a/pretrained_backbones_unet-0.0.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "54a53587d59abd6375a79ea0627a169c0ff79de2685c7e6c087601d65ab5b1d3",
"md5": "d50b2172d3284444c3fef7ed51425fae",
"sha256": "cfc00f7ac5040667da43672dec55bb4d158afa8f85c696ab0daf08642feef239"
},
"downloads": -1,
"filename": "pretrained-backbones-unet-0.0.1.tar.gz",
"has_sig": false,
"md5_digest": "d50b2172d3284444c3fef7ed51425fae",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 16313,
"upload_time": "2023-03-10T22:26:38",
"upload_time_iso_8601": "2023-03-10T22:26:38.208308Z",
"url": "https://files.pythonhosted.org/packages/54/a5/3587d59abd6375a79ea0627a169c0ff79de2685c7e6c087601d65ab5b1d3/pretrained-backbones-unet-0.0.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-03-10 22:26:38",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "mberkay0",
"github_project": "pretrained-backbones-unet",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [],
"lcname": "pretrained-backbones-unet"
}