pytorch-segmentation-models-trainer


Namepytorch-segmentation-models-trainer JSON
Version 0.8.1 PyPI version JSON
download
home_pagehttps://github.com/phborba/pytorch_segmentation_models_trainer
SummaryImage segmentation models training of popular architectures.
upload_time2021-07-20 20:56:56
maintainer
docs_urlNone
authorPhilipe Borba
requires_python>=3.6.0
licenseGPL
keywords pytorch hydra semantic-segmentation deep-learning deep learning
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage
            
# pytorch_segmentation_models_trainer


[![Torch](https://img.shields.io/badge/-PyTorch-red?logo=pytorch&labelColor=gray)](https://pytorch.org/get-started/locally/)
[![Pytorch Lightning](https://img.shields.io/badge/code-Lightning-blueviolet)](https://pytorchlightning.ai/)
[![Hydra](https://img.shields.io/badge/conf-hydra-blue)](https://hydra.cc/)
[![Segmentation Models](https://img.shields.io/badge/models-segmentation_models_pytorch-yellow)](https://github.com/qubvel/segmentation_models.pytorch)
[![Python application](https://github.com/phborba/pytorch_segmentation_models_trainer/actions/workflows/python-app.yml/badge.svg)](https://github.com/phborba/pytorch_segmentation_models_trainer/actions/workflows/python-app.yml)
[![Upload Python Package](https://github.com/phborba/pytorch_segmentation_models_trainer/actions/workflows/python-publish.yml/badge.svg)](https://github.com/phborba/pytorch_segmentation_models_trainer/actions/workflows/python-publish.yml)
[![PyPI](https://img.shields.io/pypi/v/pytorch-segmentation-models-trainer)](https://pypi.org/project/pytorch-segmentation-models-trainer/)
[![Publish Docker image](https://github.com/phborba/pytorch_segmentation_models_trainer/actions/workflows/docker-publish.yml/badge.svg)](https://github.com/phborba/pytorch_segmentation_models_trainer/actions/workflows/docker-publish.yml)
[![maintainer](https://img.shields.io/badge/maintainer-phborba-blue.svg)](https://github.com/phborba)
[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.4573996.svg)](https://doi.org/10.5281/zenodo.4573996)
[![codecov](https://codecov.io/gh/phborba/pytorch_segmentation_models_trainer/branch/main/graph/badge.svg?token=PRJL5GVOL2)](https://codecov.io/gh/phborba/pytorch_segmentation_models_trainer)
[![Open in Visual Studio Code](https://open.vscode.dev/badges/open-in-vscode.svg)](https://open.vscode.dev/phborba/pytorch_segmentation_models_trainer)

Framework based on Pytorch, Pytorch Lightning,  segmentation_models.pytorch and hydra to train semantic segmentation models using yaml config files as follows:

```
model:
  _target_: segmentation_models_pytorch.Unet
  encoder_name: resnet34
  encoder_weights: imagenet
  in_channels: 3
  classes: 1

loss:
  _target_: segmentation_models_pytorch.utils.losses.DiceLoss

optimizer:
  _target_: torch.optim.AdamW
  lr: 0.001
  weight_decay: 1e-4

hyperparameters:
  batch_size: 1
  epochs: 2
  max_lr: 0.1

pl_trainer:
  max_epochs: ${hyperparameters.batch_size}
  gpus: 0

train_dataset:
  _target_: pytorch_segmentation_models_trainer.dataset_loader.dataset.SegmentationDataset
  input_csv_path: /path/to/input.csv
  data_loader:
    shuffle: True
    num_workers: 1
    pin_memory: True
    drop_last: True
    prefetch_factor: 1
  augmentation_list:
    - _target_: albumentations.HueSaturationValue
      always_apply: false
      hue_shift_limit: 0.2
      p: 0.5
    - _target_: albumentations.RandomBrightnessContrast
      brightness_limit: 0.2
      contrast_limit: 0.2
      p: 0.5
    - _target_: albumentations.RandomCrop
      always_apply: true
      height: 256
      width: 256
      p: 1.0
    - _target_: albumentations.Flip
      always_apply: true
    - _target_: albumentations.Normalize
      p: 1.0
    - _target_: albumentations.pytorch.transforms.ToTensorV2
      always_apply: true

val_dataset:
  _target_: pytorch_segmentation_models_trainer.dataset_loader.dataset.SegmentationDataset
  input_csv_path: /path/to/input.csv
  data_loader:
    shuffle: True
    num_workers: 1
    pin_memory: True
    drop_last: True
    prefetch_factor: 1
  augmentation_list:
    - _target_: albumentations.Resize
      always_apply: true
      height: 256
      width: 256
      p: 1.0
    - _target_: albumentations.Normalize
      p: 1.0
    - _target_: albumentations.pytorch.transforms.ToTensorV2
      always_apply: true
```

To train a model with configuration path ```/path/to/config/folder``` and name ```test.yaml```:

```
pytorch-smt --config-dir /path/to/config/folder --config-name test +mode=train
```

The mode can be stored in configuration yaml as well. In this case, do not pass the +mode= argument. If the mode is stored in the yaml and you want to overwrite the value, do not use the + clause, just mode= .

This module suports hydra features such as configuration composition. For further information, please visit https://hydra.cc/docs/intro

# Install

If you are not using docker and if you want to enable gpu acceleration, before installing this package, you should install pytorch_scatter as instructed in https://github.com/rusty1s/pytorch_scatter 

After installing pytorch_scatter, just do

```
pip install pytorch_segmentation_models_trainer
```

We have a docker container in which all dependencies are installed and ready for gpu usage. You can pull the image from dockerhub:

```
docker pull phborba/pytorch_segmentation_models_trainer:latest
```

# Citing:

```

@software{philipe_borba_2021_5115127,
  author       = {Philipe Borba},
  title        = {{phborba/pytorch\_segmentation\_models\_trainer: 
                   Version 0.8.0}},
  month        = jul,
  year         = 2021,
  publisher    = {Zenodo},
  version      = {v0.8.0},
  doi          = {10.5281/zenodo.5115127},
  url          = {https://doi.org/10.5281/zenodo.5115127}
}



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/phborba/pytorch_segmentation_models_trainer",
    "name": "pytorch-segmentation-models-trainer",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.6.0",
    "maintainer_email": "",
    "keywords": "pytorch hydra semantic-segmentation deep-learning deep learning",
    "author": "Philipe Borba",
    "author_email": "philipeborba@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/19/a7/2defa3561d279568a6ba134c5382c29a405aa173e4bba5d0f5560a3f6220/pytorch_segmentation_models_trainer-0.8.1.tar.gz",
    "platform": "",
    "description": "\n# pytorch_segmentation_models_trainer\n\n\n[![Torch](https://img.shields.io/badge/-PyTorch-red?logo=pytorch&labelColor=gray)](https://pytorch.org/get-started/locally/)\n[![Pytorch Lightning](https://img.shields.io/badge/code-Lightning-blueviolet)](https://pytorchlightning.ai/)\n[![Hydra](https://img.shields.io/badge/conf-hydra-blue)](https://hydra.cc/)\n[![Segmentation Models](https://img.shields.io/badge/models-segmentation_models_pytorch-yellow)](https://github.com/qubvel/segmentation_models.pytorch)\n[![Python application](https://github.com/phborba/pytorch_segmentation_models_trainer/actions/workflows/python-app.yml/badge.svg)](https://github.com/phborba/pytorch_segmentation_models_trainer/actions/workflows/python-app.yml)\n[![Upload Python Package](https://github.com/phborba/pytorch_segmentation_models_trainer/actions/workflows/python-publish.yml/badge.svg)](https://github.com/phborba/pytorch_segmentation_models_trainer/actions/workflows/python-publish.yml)\n[![PyPI](https://img.shields.io/pypi/v/pytorch-segmentation-models-trainer)](https://pypi.org/project/pytorch-segmentation-models-trainer/)\n[![Publish Docker image](https://github.com/phborba/pytorch_segmentation_models_trainer/actions/workflows/docker-publish.yml/badge.svg)](https://github.com/phborba/pytorch_segmentation_models_trainer/actions/workflows/docker-publish.yml)\n[![maintainer](https://img.shields.io/badge/maintainer-phborba-blue.svg)](https://github.com/phborba)\n[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.4573996.svg)](https://doi.org/10.5281/zenodo.4573996)\n[![codecov](https://codecov.io/gh/phborba/pytorch_segmentation_models_trainer/branch/main/graph/badge.svg?token=PRJL5GVOL2)](https://codecov.io/gh/phborba/pytorch_segmentation_models_trainer)\n[![Open in Visual Studio Code](https://open.vscode.dev/badges/open-in-vscode.svg)](https://open.vscode.dev/phborba/pytorch_segmentation_models_trainer)\n\nFramework based on Pytorch, Pytorch Lightning,  segmentation_models.pytorch and hydra to train semantic segmentation models using yaml config files as follows:\n\n```\nmodel:\n  _target_: segmentation_models_pytorch.Unet\n  encoder_name: resnet34\n  encoder_weights: imagenet\n  in_channels: 3\n  classes: 1\n\nloss:\n  _target_: segmentation_models_pytorch.utils.losses.DiceLoss\n\noptimizer:\n  _target_: torch.optim.AdamW\n  lr: 0.001\n  weight_decay: 1e-4\n\nhyperparameters:\n  batch_size: 1\n  epochs: 2\n  max_lr: 0.1\n\npl_trainer:\n  max_epochs: ${hyperparameters.batch_size}\n  gpus: 0\n\ntrain_dataset:\n  _target_: pytorch_segmentation_models_trainer.dataset_loader.dataset.SegmentationDataset\n  input_csv_path: /path/to/input.csv\n  data_loader:\n    shuffle: True\n    num_workers: 1\n    pin_memory: True\n    drop_last: True\n    prefetch_factor: 1\n  augmentation_list:\n    - _target_: albumentations.HueSaturationValue\n      always_apply: false\n      hue_shift_limit: 0.2\n      p: 0.5\n    - _target_: albumentations.RandomBrightnessContrast\n      brightness_limit: 0.2\n      contrast_limit: 0.2\n      p: 0.5\n    - _target_: albumentations.RandomCrop\n      always_apply: true\n      height: 256\n      width: 256\n      p: 1.0\n    - _target_: albumentations.Flip\n      always_apply: true\n    - _target_: albumentations.Normalize\n      p: 1.0\n    - _target_: albumentations.pytorch.transforms.ToTensorV2\n      always_apply: true\n\nval_dataset:\n  _target_: pytorch_segmentation_models_trainer.dataset_loader.dataset.SegmentationDataset\n  input_csv_path: /path/to/input.csv\n  data_loader:\n    shuffle: True\n    num_workers: 1\n    pin_memory: True\n    drop_last: True\n    prefetch_factor: 1\n  augmentation_list:\n    - _target_: albumentations.Resize\n      always_apply: true\n      height: 256\n      width: 256\n      p: 1.0\n    - _target_: albumentations.Normalize\n      p: 1.0\n    - _target_: albumentations.pytorch.transforms.ToTensorV2\n      always_apply: true\n```\n\nTo train a model with configuration path ```/path/to/config/folder``` and name ```test.yaml```:\n\n```\npytorch-smt --config-dir /path/to/config/folder --config-name test +mode=train\n```\n\nThe mode can be stored in configuration yaml as well. In this case, do not pass the +mode= argument. If the mode is stored in the yaml and you want to overwrite the value, do not use the + clause, just mode= .\n\nThis module suports hydra features such as configuration composition. For further information, please visit https://hydra.cc/docs/intro\n\n# Install\n\nIf you are not using docker and if you want to enable gpu acceleration, before installing this package, you should install pytorch_scatter as instructed in https://github.com/rusty1s/pytorch_scatter \n\nAfter installing pytorch_scatter, just do\n\n```\npip install pytorch_segmentation_models_trainer\n```\n\nWe have a docker container in which all dependencies are installed and ready for gpu usage. You can pull the image from dockerhub:\n\n```\ndocker pull phborba/pytorch_segmentation_models_trainer:latest\n```\n\n# Citing:\n\n```\n\n@software{philipe_borba_2021_5115127,\n  author       = {Philipe Borba},\n  title        = {{phborba/pytorch\\_segmentation\\_models\\_trainer: \n                   Version 0.8.0}},\n  month        = jul,\n  year         = 2021,\n  publisher    = {Zenodo},\n  version      = {v0.8.0},\n  doi          = {10.5281/zenodo.5115127},\n  url          = {https://doi.org/10.5281/zenodo.5115127}\n}\n\n\n",
    "bugtrack_url": null,
    "license": "GPL",
    "summary": "Image segmentation models training of popular architectures.",
    "version": "0.8.1",
    "split_keywords": [
        "pytorch",
        "hydra",
        "semantic-segmentation",
        "deep-learning",
        "deep",
        "learning"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "75b438784a4a4bbdb290758b12b5e033",
                "sha256": "c493f80fc5b287ca1d1ddf5c90ae4a983f4fa049a1d3672f4f5d722a575f8ae7"
            },
            "downloads": -1,
            "filename": "pytorch_segmentation_models_trainer-0.8.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "75b438784a4a4bbdb290758b12b5e033",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6.0",
            "size": 127188,
            "upload_time": "2021-07-20T20:56:54",
            "upload_time_iso_8601": "2021-07-20T20:56:54.380452Z",
            "url": "https://files.pythonhosted.org/packages/9a/81/b27798254baa4dc183f3051721deba94d1b103b5c16e5855f49fa0060d8f/pytorch_segmentation_models_trainer-0.8.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "2d8d6b961e44575ae68d11d9a5b323e8",
                "sha256": "59ed9cd8883bd6fab3e439d5a5dd161e0ee4e95d759ee73a5abdc71340c34de0"
            },
            "downloads": -1,
            "filename": "pytorch_segmentation_models_trainer-0.8.1.tar.gz",
            "has_sig": false,
            "md5_digest": "2d8d6b961e44575ae68d11d9a5b323e8",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6.0",
            "size": 86354,
            "upload_time": "2021-07-20T20:56:56",
            "upload_time_iso_8601": "2021-07-20T20:56:56.280193Z",
            "url": "https://files.pythonhosted.org/packages/19/a7/2defa3561d279568a6ba134c5382c29a405aa173e4bba5d0f5560a3f6220/pytorch_segmentation_models_trainer-0.8.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2021-07-20 20:56:56",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "phborba",
    "github_project": "pytorch_segmentation_models_trainer",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": true,
    "requirements": [],
    "lcname": "pytorch-segmentation-models-trainer"
}
        
Elapsed time: 0.32845s