Skip to content

Commit 89f8a6a

Browse files
authored
[Bug fix] fixed fp16 inference (#497)
* fixed fp16 * update fps
1 parent 5b33faa commit 89f8a6a

7 files changed

+21
-6
lines changed

configs/fp16/README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
| Method | Backbone | Crop Size | Lr schd | Mem (GB) | Inf time (fps) | mIoU | mIoU(ms+flip) | config | download |
2121
| ---------- | -------- | --------- | ------: | -------- | -------------- | ----: | ------------: | ------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
22-
| FCN | R-101-D8 | 512x1024 | 80000 | 5.50 | 2.66 | 76.80 | - | [config](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/fp16/fcn_r101-d8_512x1024_80k_fp16_cityscapes.py) | [model](https://download.openmmlab.com/mmsegmentation/v0.5/fp16/fcn_r101-d8_512x1024_80k_fp16_cityscapes/fcn_r101-d8_512x1024_80k_fp16_cityscapes-50245227.pth) | [log](https://download.openmmlab.com/mmsegmentation/v0.5/fp16/fcn_r101-d8_512x1024_80k_fp16_cityscapes/fcn_r101-d8_512x1024_80k_fp16_cityscapes_20200717_230921.log.json) |
23-
| PSPNet | R-101-D8 | 512x1024 | 80000 | 5.47 | 2.68 | 79.46 | - | [config](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/fp16/pspnet_r101-d8_512x1024_80k_fp16_cityscapes.py) | [model](https://download.openmmlab.com/mmsegmentation/v0.5/fp16/pspnet_r101-d8_512x1024_80k_fp16_cityscapes/pspnet_r101-d8_512x1024_80k_fp16_cityscapes-ade37931.pth) | [log](https://download.openmmlab.com/mmsegmentation/v0.5/fp16/pspnet_r101-d8_512x1024_80k_fp16_cityscapes/pspnet_r101-d8_512x1024_80k_fp16_cityscapes_20200717_230919.log.json) |
24-
| DeepLabV3 | R-101-D8 | 512x1024 | 80000 | 5.91 | 1.93 | 80.48 | - | [config](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/fp16/deeplabv3_r101-d8_512x1024_80k_fp16_cityscapes.py) | [model](https://download.openmmlab.com/mmsegmentation/v0.5/fp16/deeplabv3_r101-d8_512x1024_80k_fp16_cityscapes/deeplabv3_r101-d8_512x1024_80k_fp16_cityscapes-bc86dc84.pth) | [log](https://download.openmmlab.com/mmsegmentation/v0.5/fp16/deeplabv3_r101-d8_512x1024_80k_fp16_cityscapes/deeplabv3_r101-d8_512x1024_80k_fp16_cityscapes_20200717_230920.log.json) |
25-
| DeepLabV3+ | R-101-D8 | 512x1024 | 80000 | 6.46 | 2.60 | 80.46 | - | [config](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/fp16/deeplabv3plus_r101-d8_512x1024_80k_fp16_cityscapes.py) | [model](https://download.openmmlab.com/mmsegmentation/v0.5/fp16/deeplabv3plus_r101-d8_512x1024_80k_fp16_cityscapes/deeplabv3plus_r101-d8_512x1024_80k_fp16_cityscapes-cc58bc8d.pth) | [log](https://download.openmmlab.com/mmsegmentation/v0.5/fp16/deeplabv3plus_r101-d8_512x1024_80k_fp16_cityscapes/deeplabv3plus_r101-d8_512x1024_80k_fp16_cityscapes_20200717_230920.log.json) |
22+
| FCN | R-101-D8 | 512x1024 | 80000 | 5.37 | 8.64 | 76.80 | - | [config](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/fp16/fcn_r101-d8_512x1024_80k_fp16_cityscapes.py) | [model](https://download.openmmlab.com/mmsegmentation/v0.5/fp16/fcn_r101-d8_512x1024_80k_fp16_cityscapes/fcn_r101-d8_512x1024_80k_fp16_cityscapes-50245227.pth) | [log](https://download.openmmlab.com/mmsegmentation/v0.5/fp16/fcn_r101-d8_512x1024_80k_fp16_cityscapes/fcn_r101-d8_512x1024_80k_fp16_cityscapes_20200717_230921.log.json) |
23+
| PSPNet | R-101-D8 | 512x1024 | 80000 | 5.34 | 8.77 | 79.46 | - | [config](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/fp16/pspnet_r101-d8_512x1024_80k_fp16_cityscapes.py) | [model](https://download.openmmlab.com/mmsegmentation/v0.5/fp16/pspnet_r101-d8_512x1024_80k_fp16_cityscapes/pspnet_r101-d8_512x1024_80k_fp16_cityscapes-ade37931.pth) | [log](https://download.openmmlab.com/mmsegmentation/v0.5/fp16/pspnet_r101-d8_512x1024_80k_fp16_cityscapes/pspnet_r101-d8_512x1024_80k_fp16_cityscapes_20200717_230919.log.json) |
24+
| DeepLabV3 | R-101-D8 | 512x1024 | 80000 | 5.75 | 3.86 | 80.48 | - | [config](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/fp16/deeplabv3_r101-d8_512x1024_80k_fp16_cityscapes.py) | [model](https://download.openmmlab.com/mmsegmentation/v0.5/fp16/deeplabv3_r101-d8_512x1024_80k_fp16_cityscapes/deeplabv3_r101-d8_512x1024_80k_fp16_cityscapes-bc86dc84.pth) | [log](https://download.openmmlab.com/mmsegmentation/v0.5/fp16/deeplabv3_r101-d8_512x1024_80k_fp16_cityscapes/deeplabv3_r101-d8_512x1024_80k_fp16_cityscapes_20200717_230920.log.json) |
25+
| DeepLabV3+ | R-101-D8 | 512x1024 | 80000 | 6.35 | 7.87 | 80.46 | - | [config](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/fp16/deeplabv3plus_r101-d8_512x1024_80k_fp16_cityscapes.py) | [model](https://download.openmmlab.com/mmsegmentation/v0.5/fp16/deeplabv3plus_r101-d8_512x1024_80k_fp16_cityscapes/deeplabv3plus_r101-d8_512x1024_80k_fp16_cityscapes-cc58bc8d.pth) | [log](https://download.openmmlab.com/mmsegmentation/v0.5/fp16/deeplabv3plus_r101-d8_512x1024_80k_fp16_cityscapes/deeplabv3plus_r101-d8_512x1024_80k_fp16_cityscapes_20200717_230920.log.json) |
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
_base_ = '../deeplabv3/deeplabv3_r101-d8_512x1024_80k_cityscapes.py'
22
# fp16 settings
33
optimizer_config = dict(type='Fp16OptimizerHook', loss_scale=512.)
4+
# fp16 placeholder
5+
fp16 = dict()
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
_base_ = '../deeplabv3plus/deeplabv3plus_r101-d8_512x1024_80k_cityscapes.py'
22
# fp16 settings
33
optimizer_config = dict(type='Fp16OptimizerHook', loss_scale=512.)
4+
# fp16 placeholder
5+
fp16 = dict()
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
_base_ = '../fcn/fcn_r101-d8_512x1024_80k_cityscapes.py'
22
# fp16 settings
33
optimizer_config = dict(type='Fp16OptimizerHook', loss_scale=512.)
4+
# fp16 placeholder
5+
fp16 = dict()
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
_base_ = '../pspnet/pspnet_r101-d8_512x1024_80k_cityscapes.py'
22
# fp16 settings
33
optimizer_config = dict(type='Fp16OptimizerHook', loss_scale=512.)
4+
# fp16 placeholder
5+
fp16 = dict()

tools/benchmark.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import torch
55
from mmcv import Config
66
from mmcv.parallel import MMDataParallel
7-
from mmcv.runner import load_checkpoint
7+
from mmcv.runner import load_checkpoint, wrap_fp16_model
88

99
from mmseg.datasets import build_dataloader, build_dataset
1010
from mmseg.models import build_segmentor
@@ -42,6 +42,9 @@ def main():
4242
# build the model and load checkpoint
4343
cfg.model.train_cfg = None
4444
model = build_segmentor(cfg.model, test_cfg=cfg.get('test_cfg'))
45+
fp16_cfg = cfg.get('fp16', None)
46+
if fp16_cfg is not None:
47+
wrap_fp16_model(model)
4548
load_checkpoint(model, args.checkpoint, map_location='cpu')
4649

4750
model = MMDataParallel(model, device_ids=[0])

tools/test.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
import mmcv
55
import torch
66
from mmcv.parallel import MMDataParallel, MMDistributedDataParallel
7-
from mmcv.runner import get_dist_info, init_dist, load_checkpoint
7+
from mmcv.runner import (get_dist_info, init_dist, load_checkpoint,
8+
wrap_fp16_model)
89
from mmcv.utils import DictAction
910

1011
from mmseg.apis import multi_gpu_test, single_gpu_test
@@ -117,6 +118,9 @@ def main():
117118
# build the model and load checkpoint
118119
cfg.model.train_cfg = None
119120
model = build_segmentor(cfg.model, test_cfg=cfg.get('test_cfg'))
121+
fp16_cfg = cfg.get('fp16', None)
122+
if fp16_cfg is not None:
123+
wrap_fp16_model(model)
120124
checkpoint = load_checkpoint(model, args.checkpoint, map_location='cpu')
121125
model.CLASSES = checkpoint['meta']['CLASSES']
122126
model.PALETTE = checkpoint['meta']['PALETTE']

0 commit comments

Comments
 (0)