Skip to main content

Image segmentation models training of popular architectures.

Project description

pytorch_segmentation_models_trainer

Torch Pytorch Lightning Hydra Segmentation Models Python application Upload Python Package PyPI Publish Docker image maintainer DOI codecov Open in Visual Studio Code

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}
}


Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Built Distribution

File details

Details for the file pytorch_segmentation_models_trainer-0.8.1.tar.gz.

File metadata

  • Download URL: pytorch_segmentation_models_trainer-0.8.1.tar.gz
  • Upload date:
  • Size: 86.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.6

File hashes

Hashes for pytorch_segmentation_models_trainer-0.8.1.tar.gz
Algorithm Hash digest
SHA256 59ed9cd8883bd6fab3e439d5a5dd161e0ee4e95d759ee73a5abdc71340c34de0
MD5 2d8d6b961e44575ae68d11d9a5b323e8
BLAKE2b-256 19a72defa3561d279568a6ba134c5382c29a405aa173e4bba5d0f5560a3f6220

See more details on using hashes here.

File details

Details for the file pytorch_segmentation_models_trainer-0.8.1-py3-none-any.whl.

File metadata

File hashes

Hashes for pytorch_segmentation_models_trainer-0.8.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c493f80fc5b287ca1d1ddf5c90ae4a983f4fa049a1d3672f4f5d722a575f8ae7
MD5 75b438784a4a4bbdb290758b12b5e033
BLAKE2b-256 9a81b27798254baa4dc183f3051721deba94d1b103b5c16e5855f49fa0060d8f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page