Image segmentation models training of popular architectures.
Project description
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
Citing:
@software{philipe_borba_2021_4574256,
author = {Philipe Borba},
title = {{phborba/pytorch\_segmentation\_models\_trainer:
Version 0.1.2}},
month = mar,
year = 2021,
publisher = {Zenodo},
version = {v0.1.2},
doi = {10.5281/zenodo.4574256},
url = {https://doi.org/10.5281/zenodo.4574256}
}
Project details
Release history Release notifications | RSS feed
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
Hashes for pytorch_segmentation_models_trainer-0.2.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | b29ba33f3496f26e7cd46c96da7fe6200d67f638ff08fbd3c17399a5e95a5097 |
|
MD5 | 35beb6cd40113726c68cc256e9abd45f |
|
BLAKE2b-256 | d39236a45ae89e6ad4e84ce1d2bf5a7377e0f33182ad3ec0ccc5ce6049b3546f |
Hashes for pytorch_segmentation_models_trainer-0.2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 626abcf0b686b93c2a9cfbb46aca370f4ff20ef2029d9ce1c16fb0a81b36da15 |
|
MD5 | 11dbaf00ba48d3543524d5f55581a7c5 |
|
BLAKE2b-256 | e8e95083496584022e1034a251acd8f234027248af5a58434ffbd0d60bdeedef |