|
| 1 | +_base_ = [ |
| 2 | + '../_base_/datasets/cityscapes_1024x1024.py', |
| 3 | + '../_base_/default_runtime.py' |
| 4 | +] |
| 5 | + |
| 6 | +# The class_weight is borrowed from https://github.com/openseg-group/OCNet.pytorch/issues/14 # noqa |
| 7 | +# Licensed under the MIT License |
| 8 | +class_weight = [ |
| 9 | + 0.8373, 0.918, 0.866, 1.0345, 1.0166, 0.9969, 0.9754, 1.0489, 0.8786, |
| 10 | + 1.0023, 0.9539, 0.9843, 1.1116, 0.9037, 1.0865, 1.0955, 1.0865, 1.1529, |
| 11 | + 1.0507 |
| 12 | +] |
| 13 | +checkpoint_file = 'https://download.openmmlab.com/mmsegmentation/v0.5/pretrain/pidnet/pidnet-s_imagenet1k_20230306-715e6273.pth' # noqa |
| 14 | +crop_size = (1024, 1024) |
| 15 | +data_preprocessor = dict( |
| 16 | + type='SegDataPreProcessor', |
| 17 | + mean=[123.675, 116.28, 103.53], |
| 18 | + std=[58.395, 57.12, 57.375], |
| 19 | + bgr_to_rgb=True, |
| 20 | + pad_val=0, |
| 21 | + seg_pad_val=255, |
| 22 | + size=crop_size) |
| 23 | +norm_cfg = dict(type='SyncBN', requires_grad=True) |
| 24 | +model = dict( |
| 25 | + type='EncoderDecoder', |
| 26 | + data_preprocessor=data_preprocessor, |
| 27 | + backbone=dict( |
| 28 | + type='PIDNet', |
| 29 | + in_channels=3, |
| 30 | + channels=32, |
| 31 | + ppm_channels=96, |
| 32 | + num_stem_blocks=2, |
| 33 | + num_branch_blocks=3, |
| 34 | + align_corners=False, |
| 35 | + norm_cfg=norm_cfg, |
| 36 | + act_cfg=dict(type='ReLU', inplace=True), |
| 37 | + init_cfg=dict(type='Pretrained', checkpoint=checkpoint_file)), |
| 38 | + decode_head=dict( |
| 39 | + type='PIDHead', |
| 40 | + in_channels=128, |
| 41 | + channels=128, |
| 42 | + num_classes=19, |
| 43 | + norm_cfg=norm_cfg, |
| 44 | + act_cfg=dict(type='ReLU', inplace=True), |
| 45 | + align_corners=True, |
| 46 | + loss_decode=[ |
| 47 | + dict( |
| 48 | + type='CrossEntropyLoss', |
| 49 | + use_sigmoid=False, |
| 50 | + class_weight=class_weight, |
| 51 | + loss_weight=0.4), |
| 52 | + dict( |
| 53 | + type='OhemCrossEntropy', |
| 54 | + thres=0.9, |
| 55 | + min_kept=131072, |
| 56 | + class_weight=class_weight, |
| 57 | + loss_weight=1.0), |
| 58 | + dict(type='BoundaryLoss', loss_weight=20.0), |
| 59 | + dict( |
| 60 | + type='OhemCrossEntropy', |
| 61 | + thres=0.9, |
| 62 | + min_kept=131072, |
| 63 | + class_weight=class_weight, |
| 64 | + loss_weight=1.0) |
| 65 | + ]), |
| 66 | + train_cfg=dict(), |
| 67 | + test_cfg=dict(mode='whole')) |
| 68 | + |
| 69 | +train_pipeline = [ |
| 70 | + dict(type='LoadImageFromFile'), |
| 71 | + dict(type='LoadAnnotations'), |
| 72 | + dict( |
| 73 | + type='RandomResize', |
| 74 | + scale=(2048, 1024), |
| 75 | + ratio_range=(0.5, 2.0), |
| 76 | + keep_ratio=True), |
| 77 | + dict(type='RandomCrop', crop_size=crop_size, cat_max_ratio=0.75), |
| 78 | + dict(type='RandomFlip', prob=0.5), |
| 79 | + dict(type='PhotoMetricDistortion'), |
| 80 | + dict(type='GenerateEdge', edge_width=4), |
| 81 | + dict(type='PackSegInputs') |
| 82 | +] |
| 83 | +train_dataloader = dict(batch_size=6, dataset=dict(pipeline=train_pipeline)) |
| 84 | + |
| 85 | +iters = 120000 |
| 86 | +# optimizer |
| 87 | +optimizer = dict(type='SGD', lr=0.01, momentum=0.9, weight_decay=0.0005) |
| 88 | +optim_wrapper = dict(type='OptimWrapper', optimizer=optimizer, clip_grad=None) |
| 89 | +# learning policy |
| 90 | +param_scheduler = [ |
| 91 | + dict( |
| 92 | + type='PolyLR', |
| 93 | + eta_min=0, |
| 94 | + power=0.9, |
| 95 | + begin=0, |
| 96 | + end=iters, |
| 97 | + by_epoch=False) |
| 98 | +] |
| 99 | +# training schedule for 120k |
| 100 | +train_cfg = dict( |
| 101 | + type='IterBasedTrainLoop', max_iters=iters, val_interval=iters // 10) |
| 102 | +val_cfg = dict(type='ValLoop') |
| 103 | +test_cfg = dict(type='TestLoop') |
| 104 | +default_hooks = dict( |
| 105 | + timer=dict(type='IterTimerHook'), |
| 106 | + logger=dict(type='LoggerHook', interval=50, log_metric_by_epoch=False), |
| 107 | + param_scheduler=dict(type='ParamSchedulerHook'), |
| 108 | + checkpoint=dict( |
| 109 | + type='CheckpointHook', by_epoch=False, interval=iters // 10), |
| 110 | + sampler_seed=dict(type='DistSamplerSeedHook'), |
| 111 | + visualization=dict(type='SegVisualizationHook')) |
| 112 | + |
| 113 | +randomness = dict(seed=304) |
0 commit comments