diff --git a/configs/mmseg/segmentation_ncnn-int8_static-1024x2048.py b/configs/mmseg/segmentation_ncnn-int8_static-1024x2048.py new file mode 100644 index 000000000..9dc64ee02 --- /dev/null +++ b/configs/mmseg/segmentation_ncnn-int8_static-1024x2048.py @@ -0,0 +1,3 @@ +_base_ = ['./segmentation_static.py', '../_base_/backends/ncnn-int8.py'] + +onnx_config = dict(input_shape=[2048, 1024]) diff --git a/docs/en/03-benchmark/quantization.md b/docs/en/03-benchmark/quantization.md index 8e3d101fe..6e9cbab00 100644 --- a/docs/en/03-benchmark/quantization.md +++ b/docs/en/03-benchmark/quantization.md @@ -47,3 +47,14 @@ Note: MMPose models are tested with `flip_test` explicitly set to `False` in mod | :-----------------------------------------------------------------------------------------------------------------: | :-----: | :------------: | :------------: | | [EDSRx2](https://github.com/open-mmlab/mmediting/blob/master/configs/restorers/edsr/edsr_x2c64b16_g1_300k_div2k.py) | Set5 | 35.7733/0.9365 | 35.4266/0.9334 | | [EDSRx4](https://github.com/open-mmlab/mmediting/blob/master/configs/restorers/edsr/edsr_x4c64b16_g1_300k_div2k.py) | Set5 | 30.2194/0.8498 | 29.9340/0.8409 | + +### mmseg + +| model | dataset | fp32 mIoU | int8 mIoU | +| :----------------------------------------------------------------------------------------------------------------------------: | :--------: | :-------: | :-------: | +| [Fast-SCNN](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/fastscnn/fast_scnn_lr0.12_8x4_160k_cityscapes.py) | cityscapes | 70.96 | 70.24 | + +Note: + +- Int8 models of the Fast-SCNN requires ncnnoptimize. +- NCNN will extract 512 images from the train as a calibration dataset diff --git a/docs/zh_cn/03-benchmark/quantization.md b/docs/zh_cn/03-benchmark/quantization.md index ee6a8c06c..a4ff31b13 100644 --- a/docs/zh_cn/03-benchmark/quantization.md +++ b/docs/zh_cn/03-benchmark/quantization.md @@ -47,3 +47,14 @@ | :-----------------------------------------------------------------------------------------------------------------: | :-----: | :------------: | :------------: | | [EDSR](https://github.com/open-mmlab/mmediting/blob/master/configs/restorers/edsr/edsr_x2c64b16_g1_300k_div2k.py) | Set5 | 35.7733/0.9365 | 35.4266/0.9334 | | [EDSRx4](https://github.com/open-mmlab/mmediting/blob/master/configs/restorers/edsr/edsr_x4c64b16_g1_300k_div2k.py) | Set5 | 30.2194/0.8498 | 29.9340/0.8409 | + +### 语义分割任务 + +| model | dataset | fp32 mIoU | int8 mIoU | +| :----------------------------------------------------------------------------------------------------------------------------: | :--------: | :-------: | :-------: | +| [Fast-SCNN](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/fastscnn/fast_scnn_lr0.12_8x4_160k_cityscapes.py) | cityscapes | 70.96 | 70.24 | + +备注: + +- Fast-SCNN 的int8模型需要使用ncnnoptimize优化。 +- NCNN将会从train中抽取512张图片作为校准集。 diff --git a/mmdeploy/pytorch/functions/interpolate.py b/mmdeploy/pytorch/functions/interpolate.py index 253b59316..9cc016ed8 100644 --- a/mmdeploy/pytorch/functions/interpolate.py +++ b/mmdeploy/pytorch/functions/interpolate.py @@ -22,13 +22,16 @@ def interpolate__ncnn(ctx, """Rewrite `interpolate` for ncnn backend. ncnn require `size` should be constant in ONNX Node. We use `scale_factor` - instead of `size` to avoid dynamic size. + instead of `size` to avoid dynamic size. To avoid rounding errors, add a + small number when `scale_factor` is not an integer """ input_size = input.shape if scale_factor is None: scale_factor = [ - s_out / s_in for s_out, s_in in zip(size, input_size[2:]) + s_out / s_in if int(s_out / s_in) == s_out / s_in else + (s_out / s_in + 0.00001) + for s_out, s_in in zip(size, input_size[2:]) ] return ctx.origin_func( diff --git a/mmdeploy/pytorch/ops/adaptive_pool.py b/mmdeploy/pytorch/ops/adaptive_pool.py index d27049576..340cbccd4 100644 --- a/mmdeploy/pytorch/ops/adaptive_pool.py +++ b/mmdeploy/pytorch/ops/adaptive_pool.py @@ -10,4 +10,8 @@ def adaptive_avg_pool2d__ncnn(ctx, g, x, output_size): Align symbolic of adaptive_avg_pool2d in ncnn. """ - return g.op('mmdeploy::AdaptiveAvgPool2d', x, output_size) + size = getattr(output_size.node(), 't')('value').tolist() + if size != [1, 1]: + return g.op('mmdeploy::AdaptiveAvgPool2d', x, output_size) + else: + return g.op('GlobalAveragePool', x)