SemTorch


NameSemTorch JSON
Version 0.1.1 PyPI version JSON
download
home_pagehttps://github.com/WaterKnight1998/SemTorch
SummaryDeep Leaarning segmentation architectures for PyTorch and FastAI
upload_time2020-09-08 21:49:32
maintainerDavid Lacalle Castillo
docs_urlNone
authorDavid Lacalle Castillo
requires_python
licenseApache License Version 2.0
keywords instance semantic segmentation pytorch fastai fastai2 fastaiv2 saliend object detection
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # SemTorch

This repository contains different deep learning architectures definitions that can be applied to image segmentation. 

All the architectures are implemented in [PyTorch](https://pytorch.org/) and can been trained easily with [FastAI 2](https://github.com/fastai/fastaihttps://github.com/fastai/fastai). 

In [Deep-Tumour-Spheroid repository](https://github.com/WaterKnight1998/Deep-Tumour-Spheroid) can be found and example of how to apply it with a custom dataset, in that case brain tumours images are used.

These architectures are classified as:

* **Semantic Segmentation:** each pixel of an image is linked to a class label.
![Semantic Segmentation](https://raw.githubusercontent.com/WaterKnight1998/SemTorch/develop/readme_images/semantic_segmentation.png)
* **Instance Segmentation:** is similar to semantic segmentation, but goes a bit deeper, it identifies , for each pixel, the object instance it belongs to.
![Instance Segmentation](https://raw.githubusercontent.com/WaterKnight1998/SemTorch/develop/readme_images/instance_segmentation.png)
* **Salient Object Detection (Binary clases only):** detection of the most noticeable/important object in an image.
![Salient Object Detection](https://raw.githubusercontent.com/WaterKnight1998/SemTorch/develop/readme_images/salient_object_detection.png)

## 🚀 Getting Started

To start using this package, install it using `pip`:

For example, for installing it in Ubuntu use:
```bash
pip3 install SemTorch
```

## 👩‍💻 Usage
This package creates an abstract API to access a segmentation model of different architectures. This method returns a FastAI 2 learner that can be combined with all the fastai's functionalities.

```
# SemTorch
from semtorch import get_segmentation_learner

learn = get_segmentation_learner(dls=dls, number_classes=2, segmentation_type="Semantic Segmentation",
                                 architecture_name="deeplabv3+", backbone_name="resnet50", 
                                 metrics=[tumour, Dice(), JaccardCoeff()],wd=1e-2,
                                 splitter=segmentron_splitter).to_fp16()
```

You can find a deeper example in [Deep-Tumour-Spheroid repository](https://github.com/WaterKnight1998/Deep-Tumour-Spheroid/tree/feature/notebooks), in this repo the package is used for the segmentation of brain tumours.

```
def get_segmentation_learner(dls, number_classes, segmentation_type, architecture_name, backbone_name,
                             loss_func=None, opt_func=Adam, lr=defaults.lr, splitter=trainable_params, 
                             cbs=None, pretrained=True, normalize=True, image_size=None, metrics=None, 
                             path=None, model_dir='models', wd=None, wd_bn_bias=False, train_bn=True,
                             moms=(0.95,0.85,0.95)):
```

This function return a learner for the provided architecture and backbone

### **Parameters:**

* **dls (DataLoader):** the dataloader to use with the learner
* **number_classes (int):** the number of clases in the project. It should be >=2
* **segmentation_type (str):** just `Semantic Segmentation` accepted for now 
* **architecture_name (str):** name of the architecture. The following ones are supported: `unet`, `deeplabv3+`, `hrnet`, `maskrcnn` and `u2^net`
* **backbone_name (str):** name of the backbone
* **loss_func ():** loss function.
* **opt_func ():** opt function.
* **lr ():** learning rates
* **splitter ():** splitter function for freazing the learner
* **cbs (List[cb]):** list of callbacks
* **pretrained (bool):** it defines if a trained backbone is needed
* **normalize (bool):** if normalization  is applied
* **image_size (int):** REQUIRED for MaskRCNN. It indicates the desired size of the image.
* **metrics (List[metric]):** list of metrics
* **path ():** path parameter
* **model_dir (str):** the path in which save models
* **wd (float):** wieght decay
* **wd_bn_bias (bool):**
* **train_bn (bool):**
* **moms (Tuple(float)):** tuple of different momentuns

### **Returns:**

* **learner:** value containing the learner object

### **Supported configs**

| Architecture |                           supported config                           |                                                                                                                               backbones                                                                                                                              |
|--------------|:--------------------------------------------------------------------:|:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|
| unet         |  `Semantic Segmentation`,`binary` `Semantic Segmentation`,`multiple` | `resnet18`, `resnet34`, `resnet50`, `resnet101`, `resnet152`, `xresnet18`, `xresnet34`, `xresnet50`, `xresnet101`, `xresnet152`, `squeezenet1_0`, `squeezenet1_1`, `densenet121`, `densenet169`, `densenet201`, `densenet161`, `vgg11_bn`, `vgg13_bn`, `vgg16_bn`, `vgg19_bn`, `alexnet` |
| deeplabv3+   |  `Semantic Segmentation`,`binary` `Semantic Segmentation`,`multiple` |                                                                  `resnet18`,  `resnet34`,  `resnet50`,  `resnet101`,  `resnet152`,  `resnet50c`,  `resnet101c`,  `resnet152c`,  `xception65`,  `mobilenet_v2`                                                                 |
| hrnet        | `Semantic Segmentation`,`binary`  `Semantic Segmentation`,`multiple` |                                                                              `hrnet_w18_small_model_v1`,  `hrnet_w18_small_model_v2`,  `hrnet_w18`,  `hrnet_w30`,  `hrnet_w32`,  `hrnet_w48`                                                                              |
| maskrcnn     |                   `Semantic Segmentation`,`binary`                   |                                                                                                                               `resnet50`                                                                                                                               |
| u2^net       |                   `Semantic Segmentation`,`binary`                   |                                                                                                                           `small`,  `normal`                                                                                                                          |

## 📩 Contact
📧 dvdlacallecastillo@gmail.com

💼 Linkedin [David Lacalle Castillo](https://es.linkedin.com/in/david-lacalle-castillo-5b6280173)
            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/WaterKnight1998/SemTorch",
    "name": "SemTorch",
    "maintainer": "David Lacalle Castillo",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "dvdlacallecastillo@gmail.com",
    "keywords": "instance semantic segmentation pytorch fastai fastai2 fastaiv2 saliend object detection",
    "author": "David Lacalle Castillo",
    "author_email": "dvdlacallecastillo@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/78/59/e41afbd4cf5f8bcbf6d0b8117f60586e87f9053610fcb262d2af950ab7b4/SemTorch-0.1.1.tar.gz",
    "platform": "",
    "description": "# SemTorch\n\nThis repository contains different deep learning architectures definitions that can be applied to image segmentation. \n\nAll the architectures are implemented in [PyTorch](https://pytorch.org/) and can been trained easily with [FastAI 2](https://github.com/fastai/fastaihttps://github.com/fastai/fastai). \n\nIn [Deep-Tumour-Spheroid repository](https://github.com/WaterKnight1998/Deep-Tumour-Spheroid) can be found and example of how to apply it with a custom dataset, in that case brain tumours images are used.\n\nThese architectures are classified as:\n\n* **Semantic Segmentation:** each pixel of an image is linked to a class label.\n![Semantic Segmentation](https://raw.githubusercontent.com/WaterKnight1998/SemTorch/develop/readme_images/semantic_segmentation.png)\n* **Instance Segmentation:** is similar to semantic segmentation, but goes a bit deeper, it identifies , for each pixel, the object instance it belongs to.\n![Instance Segmentation](https://raw.githubusercontent.com/WaterKnight1998/SemTorch/develop/readme_images/instance_segmentation.png)\n* **Salient Object Detection (Binary clases only):** detection of the most noticeable/important object in an image.\n![Salient Object Detection](https://raw.githubusercontent.com/WaterKnight1998/SemTorch/develop/readme_images/salient_object_detection.png)\n\n## \ud83d\ude80 Getting Started\n\nTo start using this package, install it using `pip`:\n\nFor example, for installing it in Ubuntu use:\n```bash\npip3 install SemTorch\n```\n\n## \ud83d\udc69\u200d\ud83d\udcbb Usage\nThis package creates an abstract API to access a segmentation model of different architectures. This method returns a FastAI 2 learner that can be combined with all the fastai's functionalities.\n\n```\n# SemTorch\nfrom semtorch import get_segmentation_learner\n\nlearn = get_segmentation_learner(dls=dls, number_classes=2, segmentation_type=\"Semantic Segmentation\",\n                                 architecture_name=\"deeplabv3+\", backbone_name=\"resnet50\", \n                                 metrics=[tumour, Dice(), JaccardCoeff()],wd=1e-2,\n                                 splitter=segmentron_splitter).to_fp16()\n```\n\nYou can find a deeper example in [Deep-Tumour-Spheroid repository](https://github.com/WaterKnight1998/Deep-Tumour-Spheroid/tree/feature/notebooks), in this repo the package is used for the segmentation of brain tumours.\n\n```\ndef get_segmentation_learner(dls, number_classes, segmentation_type, architecture_name, backbone_name,\n                             loss_func=None, opt_func=Adam, lr=defaults.lr, splitter=trainable_params, \n                             cbs=None, pretrained=True, normalize=True, image_size=None, metrics=None, \n                             path=None, model_dir='models', wd=None, wd_bn_bias=False, train_bn=True,\n                             moms=(0.95,0.85,0.95)):\n```\n\nThis function return a learner for the provided architecture and backbone\n\n### **Parameters:**\n\n* **dls (DataLoader):** the dataloader to use with the learner\n* **number_classes (int):** the number of clases in the project. It should be >=2\n* **segmentation_type (str):** just `Semantic Segmentation` accepted for now \n* **architecture_name (str):** name of the architecture. The following ones are supported: `unet`, `deeplabv3+`, `hrnet`, `maskrcnn` and `u2^net`\n* **backbone_name (str):** name of the backbone\n* **loss_func ():** loss function.\n* **opt_func ():** opt function.\n* **lr ():** learning rates\n* **splitter ():** splitter function for freazing the learner\n* **cbs (List[cb]):** list of callbacks\n* **pretrained (bool):** it defines if a trained backbone is needed\n* **normalize (bool):** if normalization  is applied\n* **image_size (int):** REQUIRED for MaskRCNN. It indicates the desired size of the image.\n* **metrics (List[metric]):** list of metrics\n* **path ():** path parameter\n* **model_dir (str):** the path in which save models\n* **wd (float):** wieght decay\n* **wd_bn_bias (bool):**\n* **train_bn (bool):**\n* **moms (Tuple(float)):** tuple of different momentuns\n\n### **Returns:**\n\n* **learner:** value containing the learner object\n\n### **Supported configs**\n\n| Architecture |                           supported config                           |                                                                                                                               backbones                                                                                                                              |\n|--------------|:--------------------------------------------------------------------:|:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|\n| unet         |  `Semantic Segmentation`,`binary` `Semantic Segmentation`,`multiple` | `resnet18`, `resnet34`, `resnet50`, `resnet101`, `resnet152`, `xresnet18`, `xresnet34`, `xresnet50`, `xresnet101`, `xresnet152`, `squeezenet1_0`, `squeezenet1_1`, `densenet121`, `densenet169`, `densenet201`, `densenet161`, `vgg11_bn`, `vgg13_bn`, `vgg16_bn`, `vgg19_bn`, `alexnet` |\n| deeplabv3+   |  `Semantic Segmentation`,`binary` `Semantic Segmentation`,`multiple` |                                                                  `resnet18`,  `resnet34`,  `resnet50`,  `resnet101`,  `resnet152`,  `resnet50c`,  `resnet101c`,  `resnet152c`,  `xception65`,  `mobilenet_v2`                                                                 |\n| hrnet        | `Semantic Segmentation`,`binary`  `Semantic Segmentation`,`multiple` |                                                                              `hrnet_w18_small_model_v1`,  `hrnet_w18_small_model_v2`,  `hrnet_w18`,  `hrnet_w30`,  `hrnet_w32`,  `hrnet_w48`                                                                              |\n| maskrcnn     |                   `Semantic Segmentation`,`binary`                   |                                                                                                                               `resnet50`                                                                                                                               |\n| u2^net       |                   `Semantic Segmentation`,`binary`                   |                                                                                                                           `small`,  `normal`                                                                                                                          |\n\n## \ud83d\udce9 Contact\n\ud83d\udce7 dvdlacallecastillo@gmail.com\n\n\ud83d\udcbc Linkedin [David Lacalle Castillo](https://es.linkedin.com/in/david-lacalle-castillo-5b6280173)",
    "bugtrack_url": null,
    "license": "Apache License Version 2.0",
    "summary": "Deep Leaarning segmentation architectures for PyTorch and FastAI",
    "version": "0.1.1",
    "project_urls": {
        "Homepage": "https://github.com/WaterKnight1998/SemTorch"
    },
    "split_keywords": [
        "instance",
        "semantic",
        "segmentation",
        "pytorch",
        "fastai",
        "fastai2",
        "fastaiv2",
        "saliend",
        "object",
        "detection"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7859e41afbd4cf5f8bcbf6d0b8117f60586e87f9053610fcb262d2af950ab7b4",
                "md5": "f4ae1f6ec463150b9565f3dbed53d42a",
                "sha256": "f0814cd387fc03581fbff4a63b63a50dc889e19780b52273d5a734328c5f1647"
            },
            "downloads": -1,
            "filename": "SemTorch-0.1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "f4ae1f6ec463150b9565f3dbed53d42a",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 41795,
            "upload_time": "2020-09-08T21:49:32",
            "upload_time_iso_8601": "2020-09-08T21:49:32.764124Z",
            "url": "https://files.pythonhosted.org/packages/78/59/e41afbd4cf5f8bcbf6d0b8117f60586e87f9053610fcb262d2af950ab7b4/SemTorch-0.1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2020-09-08 21:49:32",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "WaterKnight1998",
    "github_project": "SemTorch",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "semtorch"
}
        
Elapsed time: 2.49666s