From 39ae31d50b5650c65be0d040c88e6f56780ec065 Mon Sep 17 00:00:00 2001 From: yhq Date: Fri, 17 Feb 2023 13:11:08 +0800 Subject: [PATCH] Add stdc benchmark & fix mask2former predict bug (#286) * add stdc benchmark & fix mask2former predict bug --- docs/source/model_zoo_seg.md | 1 + easycv/predictors/segmentation.py | 6 ++++-- tests/predictors/test_segmentation.py | 10 ++-------- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/docs/source/model_zoo_seg.md b/docs/source/model_zoo_seg.md index d7bd4142..f13f9d00 100644 --- a/docs/source/model_zoo_seg.md +++ b/docs/source/model_zoo_seg.md @@ -20,6 +20,7 @@ trained on **Cityscapes**. | Algorithm | Config | Params
(backbone/total) | Train memory
(GB) | inference time(V100)
(ms/img) | mIoU | Download | | ---------- | ------------------------------------------------------------ | ------------------------ | ------------------------------------------------------------ | ------------------------------------------------------------ | ------------------------------------------------------------ | ------------------------------------------------------------ | | STDC1 | [stdc1_cityscape_8xb6_e1290](https://github.com/alibaba/EasyCV/tree/master/configs/segmentation/stdc/stdc1_cityscape_8xb6_e1290.py) | 7.7M/8.5M | 4.5 | 11.9ms | 75.4 | [model](http://pai-vision-data-hz.oss-cn-zhangjiakou.aliyuncs.com/EasyCV/modelzoo/segmentation/stdc/stdc1_cityscapes/epoch_1250.pth) - [log](http://pai-vision-data-hz.oss-cn-zhangjiakou.aliyuncs.com/EasyCV/modelzoo/segmentation/stdc/stdc1_cityscapes/20230214_173123.log.json) | +| STDC2 | [stdc2_cityscape_8xb6_e1290](https://github.com/alibaba/EasyCV/tree/master/configs/segmentation/stdc/stdc2_cityscape_8xb6_e1290.py) | 11.6M/12.6M | 5.6 | 15.4ms | 76.6 | [model](http://pai-vision-data-hz.oss-cn-zhangjiakou.aliyuncs.com/EasyCV/modelzoo/segmentation/stdc/stdc2_cityscapes/epoch_1280.pth) - [log](http://pai-vision-data-hz.oss-cn-zhangjiakou.aliyuncs.com/EasyCV/modelzoo/segmentation/stdc/stdc2_cityscapes/20230216_110522.log.json) | ## Mask2former diff --git a/easycv/predictors/segmentation.py b/easycv/predictors/segmentation.py index 6e447e80..14ad6c61 100644 --- a/easycv/predictors/segmentation.py +++ b/easycv/predictors/segmentation.py @@ -229,9 +229,11 @@ class Mask2formerPredictor(SegmentationPredictor): outputs = self.model.forward(**inputs, mode='test', encode=False) return outputs - def show_panoptic(self, img, masks, labels): + def show_panoptic(self, img, masks, labels_ids, **kwargs): palette = np.asarray(self.cfg.PALETTE) - palette = palette[labels % 1000] + # ids have already convert to label in process_single function + # palette = palette[labels_ids % 1000] + palette = palette[labels_ids] panoptic_result = draw_masks(img, masks, palette) return panoptic_result diff --git a/tests/predictors/test_segmentation.py b/tests/predictors/test_segmentation.py index 0655072c..b1251e30 100644 --- a/tests/predictors/test_segmentation.py +++ b/tests/predictors/test_segmentation.py @@ -145,10 +145,7 @@ class Mask2formerPredictorTest(unittest.TestCase): predict_out[0]['labels_ids'].tolist(), [71, 69, 39, 39, 39, 128, 127, 122, 118, 115, 111, 104, 84, 83]) - pan_img = predictor.show_panoptic( - img, - masks=predict_out[0]['masks'], - labels=predict_out[0]['labels_ids']) + pan_img = predictor.show_panoptic(img, **predict_out[0]) cv2.imwrite('pan_out.jpg', pan_img) def test_panoptic_batch(self): @@ -168,10 +165,7 @@ class Mask2formerPredictorTest(unittest.TestCase): self.assertListEqual(predict_out[i]['labels_ids'].tolist(), [ 71, 69, 39, 39, 39, 128, 127, 122, 118, 115, 111, 104, 84, 83 ]) - pan_img = predictor.show_panoptic( - img, - masks=predict_out[i]['masks'], - labels=predict_out[i]['labels_ids']) + pan_img = predictor.show_panoptic(img, **predict_out[i]) cv2.imwrite(save_name, pan_img) def test_instance_single(self):