-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
140 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
SegFormer/local_configs/_base_/datasets/msd_lungs_balanced.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# dataset settings | ||
dataset_type = 'MSDLungsBalancedDataset' | ||
data_root = 'data/MSD/Task06_Lungs_RGB_2D_512_Balanced' | ||
img_norm_cfg = dict( | ||
mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375], to_rgb=True) | ||
crop_size = (512, 512) | ||
train_pipeline = [ | ||
dict(type='LoadImageFromFile'), | ||
dict(type='LoadAnnotations'), | ||
dict(type='Resize', img_scale=(512, 512), ratio_range=(0.5, 2.0)), | ||
dict(type='RandomCrop', crop_size=crop_size, cat_max_ratio=0.75), | ||
dict(type='RandomFlip', prob=0.5), | ||
dict(type='PhotoMetricDistortion'), | ||
dict(type='Normalize', **img_norm_cfg), | ||
dict(type='Pad', size=crop_size, pad_val=0, seg_pad_val=255), | ||
dict(type='DefaultFormatBundle'), | ||
dict(type='Collect', keys=['img', 'gt_semantic_seg']), | ||
] | ||
test_pipeline = [ | ||
dict(type='LoadImageFromFile'), | ||
dict( | ||
type='MultiScaleFlipAug', | ||
img_scale=(512, 512), | ||
# img_ratios=[0.5, 0.75, 1.0, 1.25, 1.5, 1.75], | ||
flip=False, | ||
transforms=[ | ||
dict(type='Resize', keep_ratio=True), | ||
dict(type='RandomFlip'), | ||
dict(type='Normalize', **img_norm_cfg), | ||
dict(type='ImageToTensor', keys=['img']), | ||
dict(type='Collect', keys=['img']), | ||
]) | ||
] | ||
data = dict( | ||
samples_per_gpu=2, | ||
workers_per_gpu=2, | ||
train=dict( | ||
type=dataset_type, | ||
data_root='../../data/MSD/Task06_Lungs_RGB_2D_512_Balanced', | ||
img_dir='images/training', | ||
ann_dir='annotations/training', | ||
pipeline=train_pipeline), | ||
val=dict( | ||
type=dataset_type, | ||
data_root='../../data/MSD/Task06_Lungs_RGB_2D_512_Balanced', | ||
img_dir='images/validation', | ||
ann_dir='annotations/validation', | ||
pipeline=test_pipeline), | ||
test=dict( | ||
type=dataset_type, | ||
data_root='../../data/MSD/Task06_Lungs_RGB_2D_512_Balanced', | ||
img_dir='images/training', | ||
ann_dir='annotations/validation', | ||
pipeline=test_pipeline) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
SegFormer/local_configs/segformer/MSD/segformer.512x512.msd_lungs_balanced.20k.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
_base_ = [ | ||
'../../_base_/models/segformer.py', | ||
'../../_base_/datasets/msd_lungs_balanced.py', | ||
'../../_base_/default_runtime.py', | ||
'../../_base_/schedules/schedule_20k.py' | ||
] | ||
|
||
# model settings | ||
norm_cfg = dict(type='SyncBN', requires_grad=True) | ||
find_unused_parameters = True | ||
model = dict( | ||
type='EncoderDecoder', | ||
pretrained='../../pretrained/ImageNet-1K/mit_b0.pth', | ||
backbone=dict( | ||
type='mit_b0', | ||
style='pytorch'), | ||
decode_head=dict( | ||
type='SegFormerHead', | ||
in_channels=[32, 64, 160, 256], | ||
in_index=[0, 1, 2, 3], | ||
feature_strides=[4, 8, 16, 32], | ||
channels=128, | ||
dropout_ratio=0.1, | ||
num_classes=150, | ||
norm_cfg=norm_cfg, | ||
align_corners=False, | ||
decoder_params=dict(embed_dim=256), | ||
loss_decode=dict(type='CrossEntropyLoss', use_sigmoid=False, loss_weight=1.0)), | ||
# model training and testing settings | ||
train_cfg=dict(), | ||
test_cfg=dict(mode='whole')) | ||
|
||
# optimizer | ||
optimizer = dict(_delete_=True, type='AdamW', lr=0.00006, betas=(0.9, 0.999), weight_decay=0.01, | ||
paramwise_cfg=dict(custom_keys={'pos_block': dict(decay_mult=0.), | ||
'norm': dict(decay_mult=0.), | ||
'head': dict(lr_mult=10.) | ||
})) | ||
|
||
lr_config = dict(_delete_=True, policy='poly', | ||
warmup='linear', | ||
warmup_iters=1500, | ||
warmup_ratio=1e-6, | ||
power=1.0, min_lr=0.0, by_epoch=False) | ||
|
||
data = dict(samples_per_gpu=2) | ||
evaluation = dict(interval=16000, metric='mIoU') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from .builder import DATASETS | ||
from .custom import CustomDataset | ||
|
||
|
||
@DATASETS.register_module() | ||
class MSDLungsBalancedDataset(CustomDataset): | ||
"""ADE20K dataset. | ||
In segmentation map annotation for ADE20K, 0 stands for background, which | ||
is not included in 150 categories. ``reduce_zero_label`` is fixed to True. | ||
The ``img_suffix`` is fixed to '.jpg' and ``seg_map_suffix`` is fixed to | ||
'.png'. | ||
""" | ||
CLASSES = ( | ||
"no ailment", "ailment") | ||
|
||
PALETTE = [[120, 120, 120], [92, 0, 255]] | ||
|
||
def __init__(self, **kwargs): | ||
super(MSDLungsBalancedDataset, self).__init__( | ||
img_suffix='.png', | ||
seg_map_suffix='.png', | ||
reduce_zero_label=True, | ||
**kwargs) |