Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Segformer model and recipe #754

Merged
merged 23 commits into from
Apr 17, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
2495138
initial commit
eran-deci Feb 27, 2023
932bb73
Update segformer.py
eran-deci Feb 27, 2023
78aa770
Update segformer.py
eran-deci Feb 27, 2023
a321c22
Update segformer.py
eran-deci Feb 28, 2023
3950a34
Merge branch 'master' into segformer_model_and_recipe
eran-deci Feb 28, 2023
abb99b8
update segformer.py, cityscapes_segformer_dataset_params.yaml
eran-deci Mar 1, 2023
99e3cdb
Merge branch 'segformer_model_and_recipe' of https://github.com/Deci-…
eran-deci Mar 1, 2023
25e74a0
Merge branch 'master' into segformer_model_and_recipe
eran-deci Mar 1, 2023
1b4fa9e
Merge branch 'master' into segformer_model_and_recipe
BloodAxe Mar 6, 2023
49102e6
Merge branch 'master' into segformer_model_and_recipe
BloodAxe Mar 7, 2023
20448d0
Merge branch 'master' into segformer_model_and_recipe
eran-deci Mar 10, 2023
e30b6bf
Update all_architectures.py
eran-deci Mar 10, 2023
6bc26a2
Update segformer.py
eran-deci Mar 10, 2023
73c40c1
update segformer.py, unite all segformer recipes
eran-deci Mar 15, 2023
75ca2ad
Update cityscapes_segformer.yaml
eran-deci Mar 15, 2023
d3533d1
Merge branch 'master' into segformer_model_and_recipe
eran-deci Mar 15, 2023
3590819
Update segformer.py
eran-deci Mar 15, 2023
3a7421a
Merge branch 'segformer_model_and_recipe' of https://github.com/Deci-…
eran-deci Mar 15, 2023
f79da1d
Merge branch 'master' into segformer_model_and_recipe
eran-deci Mar 16, 2023
77e33ef
Merge branch 'master' into segformer_model_and_recipe
eran-deci Apr 17, 2023
9c5f1e2
Update segformer.py
eran-deci Apr 17, 2023
0e853ed
Update __init__.py
eran-deci Apr 17, 2023
e60c1af
Merge branch 'master' into segformer_model_and_recipe
eran-deci Apr 17, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/super_gradients/common/object_names.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,12 @@ class Models:
PP_YOLOE_M = "ppyoloe_m"
PP_YOLOE_L = "ppyoloe_l"
PP_YOLOE_X = "ppyoloe_x"
SEGFORMER_B0 = "segformer_b0"
SEGFORMER_B1 = "segformer_b1"
SEGFORMER_B2 = "segformer_b2"
SEGFORMER_B3 = "segformer_b3"
SEGFORMER_B4 = "segformer_b4"
SEGFORMER_B5 = "segformer_b5"

DEKR_CUSTOM = "dekr_custom"

Expand Down
107 changes: 107 additions & 0 deletions src/super_gradients/recipes/cityscapes_segformer_b0.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# SegFormer-B0 segmentation training example with Cityscapes dataset.
# Reproduction of paper:
# Enze Xie, Wenhai Wang, Zhiding Yu, Anima Anandkumar, Jose M. Alvarez, Ping Luo
# "SegFormer: Simple and Efficient Design for Semantic Segmentation with Transformers"
# ( https://arxiv.org/pdf/2105.15203.pdf )
#
# Official git repo:
# https://github.com/NVlabs/SegFormer
#
# Imagenet-1k pre-trained backbone weights taken and adapted from:
# https://github.com/sithu31296/semantic-segmentation
#
# Instructions:
# 1. We recommend preparing the data according to SG's CityScapes readme file:
# https://github.com/Deci-AI/super-gradients/blob/master/src/super_gradients/training/datasets/Dataset_Setup_Instructions.md
# 2. Note: if you change the dataset's internal directory structure, make changes to the fields "list_file" and
# "labels_csv_path" of both "train_dataset_params" and "val_dataset_params" accordingly
# 3. Edit the "data_root_dir" field below to point to the absolute path of the data root directory
# 4. Edit the "ckpt_root_dir" field to the path where you want to save checkpoints and logs
# 5. Move to the project root (where you will find the ReadMe and src folder)
# 6. Run the command:
# python src/super_gradients/examples/train_from_recipe_example/train_from_recipe.py --config-name=cityscapes_segformer_b0
#
ofrimasad marked this conversation as resolved.
Show resolved Hide resolved
#
# Imagenet-1K pre-trained backbone:
# MiT (Mix Transformer) B0: https://deci-pretrained-models.s3.amazonaws.com/mit_backbones/mit_b0.pth
#
# 1. Download the weights from the above link and put them in a directory of your choice
# 2. Below, insert the weights file's full path to checkpoint_params.checkpoint_path
# 3. Ensure checkpoint_params.load_backbone: True


defaults:
- training_hyperparams: default_train_params
- dataset_params: cityscapes_segformer_dataset_params
- checkpoint_params: default_checkpoint_params
- _self_

architecture: segformer_b0

data_root_dir: /data/cityscapes
dataset_params:
train_dataset_params:
root_dir: ${data_root_dir}
val_dataset_params:
root_dir: ${data_root_dir}

experiment_name: ${architecture}_cityscapes
ckpt_root_dir:

train_dataloader: cityscapes_train
val_dataloader: cityscapes_val

cityscapes_ignored_label: 19 # convenience parameter since it is used in many places in the YAML

arch_params:
num_classes: 19

checkpoint_params:
checkpoint_path:
load_backbone: True
load_weights_only: True
strict_load: no_key_matching

load_checkpoint: False

resume: False
training_hyperparams:

resume: ${resume}

max_epochs: 400

lr_mode: poly
initial_lr: 0.0002 # for effective batch_size=8

optimizer: AdamW
zero_weight_decay_on_bias_and_bn: True

sync_bn: True

loss: cross_entropy
criterion_params:
ignore_index: ${cityscapes_ignored_label}

train_metrics_list:
- IoU:
num_classes: 20
ignore_index: ${cityscapes_ignored_label}

valid_metrics_list:
- IoU:
num_classes: 20
ignore_index: ${cityscapes_ignored_label}

metric_to_watch: IoU
greater_metric_to_watch_is_better: True

multi_gpu: DDP
num_gpus: 4


# THE FOLLOWING PARAMS ARE DIRECTLY USED BY HYDRA
hydra:
run:
# Set the output directory (i.e. where .hydra folder that logs all the input params will be generated)
dir: ${hydra_output_dir:${ckpt_root_dir}, ${experiment_name}}
109 changes: 109 additions & 0 deletions src/super_gradients/recipes/cityscapes_segformer_b1.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
# SegFormer-B1 segmentation training example with Cityscapes dataset.
# Reproduction of paper:
# Enze Xie, Wenhai Wang, Zhiding Yu, Anima Anandkumar, Jose M. Alvarez, Ping Luo
# "SegFormer: Simple and Efficient Design for Semantic Segmentation with Transformers"
# ( https://arxiv.org/pdf/2105.15203.pdf )
#
# Official git repo:
# https://github.com/NVlabs/SegFormer
#
#
# Imagenet-1k pre-trained backbone weights taken and adapted from:
# https://github.com/sithu31296/semantic-segmentation
#
#
# Instructions:
# 1. We recommend preparing the data according to SG's CityScapes readme file:
# https://github.com/Deci-AI/super-gradients/blob/master/src/super_gradients/training/datasets/Dataset_Setup_Instructions.md
# 2. Note: if you change the dataset's internal directory structure, make changes to the fields "list_file" and
# "labels_csv_path" of both "train_dataset_params" and "val_dataset_params" accordingly
# 3. Edit the "data_root_dir" field below to point to the absolute path of the data root directory
# 4. Edit the "ckpt_root_dir" field to the path where you want to save checkpoints and logs
# 5. Move to the project root (where you will find the ReadMe and src folder)
# 6. Run the command:
# python src/super_gradients/examples/train_from_recipe_example/train_from_recipe.py --config-name=cityscapes_segformer_b1
#
#
# Imagenet-1K pre-trained backbone:
# MiT (Mix Transformer) B1: https://deci-pretrained-models.s3.amazonaws.com/mit_backbones/mit_b1.pth
#
# 1. Download the weights from the above link and put them in a directory of your choice
# 2. Below, insert the weights file's full path to checkpoint_params.checkpoint_path
# 3. Ensure checkpoint_params.load_backbone: True


defaults:
ofrimasad marked this conversation as resolved.
Show resolved Hide resolved
- training_hyperparams: default_train_params
- dataset_params: cityscapes_segformer_dataset_params
- checkpoint_params: default_checkpoint_params
- _self_

architecture: segformer_b1

data_root_dir: /data/cityscapes
dataset_params:
train_dataset_params:
root_dir: ${data_root_dir}
val_dataset_params:
root_dir: ${data_root_dir}

experiment_name: ${architecture}_cityscapes
ckpt_root_dir:

train_dataloader: cityscapes_train
val_dataloader: cityscapes_val

cityscapes_ignored_label: 19 # convenience parameter since it is used in many places in the YAML

arch_params:
num_classes: 19

checkpoint_params:
checkpoint_path:
load_backbone: True
load_weights_only: True
strict_load: no_key_matching

load_checkpoint: False

resume: False
training_hyperparams:

resume: ${resume}

max_epochs: 400

lr_mode: poly
initial_lr: 0.0002 # for effective batch_size=8

optimizer: AdamW
zero_weight_decay_on_bias_and_bn: True

sync_bn: True

loss: cross_entropy
criterion_params:
ignore_index: ${cityscapes_ignored_label}

train_metrics_list:
- IoU:
num_classes: 20
ignore_index: ${cityscapes_ignored_label}

valid_metrics_list:
- IoU:
num_classes: 20
ignore_index: ${cityscapes_ignored_label}

metric_to_watch: IoU
greater_metric_to_watch_is_better: True

multi_gpu: DDP
num_gpus: 4


# THE FOLLOWING PARAMS ARE DIRECTLY USED BY HYDRA
hydra:
run:
# Set the output directory (i.e. where .hydra folder that logs all the input params will be generated)
dir: ${hydra_output_dir:${ckpt_root_dir}, ${experiment_name}}
109 changes: 109 additions & 0 deletions src/super_gradients/recipes/cityscapes_segformer_b2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
# SegFormer-B2 segmentation training example with Cityscapes dataset.
# Reproduction of paper:
# Enze Xie, Wenhai Wang, Zhiding Yu, Anima Anandkumar, Jose M. Alvarez, Ping Luo
# "SegFormer: Simple and Efficient Design for Semantic Segmentation with Transformers"
# ( https://arxiv.org/pdf/2105.15203.pdf )
#
# Official git repo:
# https://github.com/NVlabs/SegFormer
#
#
# Imagenet-1k pre-trained backbone weights taken and adapted from:
# https://github.com/sithu31296/semantic-segmentation
#
#
# Instructions:
# 1. We recommend preparing the data according to SG's CityScapes readme file:
# https://github.com/Deci-AI/super-gradients/blob/master/src/super_gradients/training/datasets/Dataset_Setup_Instructions.md
# 2. Note: if you change the dataset's internal directory structure, make changes to the fields "list_file" and
# "labels_csv_path" of both "train_dataset_params" and "val_dataset_params" accordingly
# 3. Edit the "data_root_dir" field below to point to the absolute path of the data root directory
# 4. Edit the "ckpt_root_dir" field to the path where you want to save checkpoints and logs
# 5. Move to the project root (where you will find the ReadMe and src folder)
# 6. Run the command:
# python src/super_gradients/examples/train_from_recipe_example/train_from_recipe.py --config-name=cityscapes_segformer_b2
#
#
# Imagenet-1K pre-trained backbone:
# MiT (Mix Transformer) B2: https://deci-pretrained-models.s3.amazonaws.com/mit_backbones/mit_b2.pth
#
# 1. Download the weights from the above link and put them in a directory of your choice
# 2. Below, insert the weights file's full path to checkpoint_params.checkpoint_path
# 3. Ensure checkpoint_params.load_backbone: True


defaults:
- training_hyperparams: default_train_params
- dataset_params: cityscapes_segformer_dataset_params
- checkpoint_params: default_checkpoint_params
- _self_

architecture: segformer_b2

data_root_dir: /data/cityscapes
dataset_params:
train_dataset_params:
root_dir: ${data_root_dir}
val_dataset_params:
root_dir: ${data_root_dir}

experiment_name: ${architecture}_cityscapes
ckpt_root_dir:

train_dataloader: cityscapes_train
val_dataloader: cityscapes_val

cityscapes_ignored_label: 19 # convenience parameter since it is used in many places in the YAML

arch_params:
num_classes: 19

checkpoint_params:
checkpoint_path:
load_backbone: True
load_weights_only: True
strict_load: no_key_matching

load_checkpoint: False

resume: False
training_hyperparams:

resume: ${resume}

max_epochs: 400

lr_mode: poly
initial_lr: 0.0002 # for effective batch_size=8

optimizer: AdamW
zero_weight_decay_on_bias_and_bn: True

sync_bn: True

loss: cross_entropy
criterion_params:
ignore_index: ${cityscapes_ignored_label}

train_metrics_list:
- IoU:
num_classes: 20
ignore_index: ${cityscapes_ignored_label}

valid_metrics_list:
- IoU:
num_classes: 20
ignore_index: ${cityscapes_ignored_label}

metric_to_watch: IoU
greater_metric_to_watch_is_better: True

multi_gpu: DDP
num_gpus: 4


# THE FOLLOWING PARAMS ARE DIRECTLY USED BY HYDRA
hydra:
run:
# Set the output directory (i.e. where .hydra folder that logs all the input params will be generated)
dir: ${hydra_output_dir:${ckpt_root_dir}, ${experiment_name}}
Loading