[Fix] Fix visualizor (#3154)

## Motivation

**Current visualize result**


![rs-dev](https://github.com/open-mmlab/mmsegmentation/assets/15952744/147ea3f7-f632-457b-b257-031199320825)

**Fixed the visualization result**



![rs-fix](https://github.com/open-mmlab/mmsegmentation/assets/15952744/98a86025-5a1e-4c2b-83e0-653dd659ba79)


## Modification

remove mmengine `draw_binary_masks` api
This commit is contained in:
谢昕辰 2023-07-03 09:43:00 +08:00 committed by GitHub
parent cc74c5c3fe
commit 8806b4e548
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 13 deletions

View File

@ -21,7 +21,6 @@
"outputs": [], "outputs": [],
"source": [ "source": [
"import torch\n", "import torch\n",
"import mmcv\n",
"import matplotlib.pyplot as plt\n", "import matplotlib.pyplot as plt\n",
"from mmengine.model.utils import revert_sync_batchnorm\n", "from mmengine.model.utils import revert_sync_batchnorm\n",
"from mmseg.apis import init_model, inference_model, show_result_pyplot" "from mmseg.apis import init_model, inference_model, show_result_pyplot"
@ -48,7 +47,7 @@
"outputs": [], "outputs": [],
"source": [ "source": [
"# build the model from a config file and a checkpoint file\n", "# build the model from a config file and a checkpoint file\n",
"model = init_model(config_file, checkpoint_file, device='cuda:0')" "model = init_model(config_file, checkpoint_file, device='cpu')"
] ]
}, },
{ {
@ -71,8 +70,8 @@
"outputs": [], "outputs": [],
"source": [ "source": [
"# show the results\n", "# show the results\n",
"vis_result = show_result_pyplot(model, img, result)\n", "vis_result = show_result_pyplot(model, img, result, show=False)\n",
"plt.imshow(mmcv.bgr2rgb(vis_result))" "plt.imshow(vis_result)"
] ]
}, },
{ {
@ -99,7 +98,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.10.9" "version": "3.10.11"
}, },
"pycharm": { "pycharm": {
"stem_cell": { "stem_cell": {

View File

@ -187,7 +187,7 @@ def show_result_pyplot(model: BaseSegmentor,
if hasattr(model, 'module'): if hasattr(model, 'module'):
model = model.module model = model.module
if isinstance(img, str): if isinstance(img, str):
image = mmcv.imread(img) image = mmcv.imread(img, channel_order='rgb')
else: else:
image = img image = img
if save_dir is not None: if save_dir is not None:

View File

@ -108,14 +108,14 @@ class SegLocalVisualizer(Visualizer):
colors = [palette[label] for label in labels] colors = [palette[label] for label in labels]
self.set_image(image) mask = np.zeros_like(image, dtype=np.uint8)
# draw semantic masks
for label, color in zip(labels, colors): for label, color in zip(labels, colors):
self.draw_binary_masks( mask[sem_seg[0] == label, :] = color
sem_seg == label, colors=[color], alphas=self.alpha)
return self.get_image() color_seg = (image * (1 - self.alpha) + mask * self.alpha).astype(
np.uint8)
self.set_image(color_seg)
return color_seg
def set_dataset_meta(self, def set_dataset_meta(self,
classes: Optional[List] = None, classes: Optional[List] = None,
@ -226,6 +226,6 @@ class SegLocalVisualizer(Visualizer):
self.show(drawn_img, win_name=name, wait_time=wait_time) self.show(drawn_img, win_name=name, wait_time=wait_time)
if out_file is not None: if out_file is not None:
mmcv.imwrite(mmcv.bgr2rgb(drawn_img), out_file) mmcv.imwrite(mmcv.rgb2bgr(drawn_img), out_file)
else: else:
self.add_image(name, drawn_img, step) self.add_image(name, drawn_img, step)