open-mmlab / mmsegmentation

OpenMMLab Semantic Segmentation Toolbox and Benchmark.
https://mmsegmentation.readthedocs.io/en/main/
Apache License 2.0
7.98k stars 2.57k forks source link

usually the segmentation map is 2D, but got 3D #3526

Open jhaggle opened 8 months ago

jhaggle commented 8 months ago

I have searched related issues but cannot get the expected help.

I follow this tutorial:

https://github.com/open-mmlab/mmsegmentation/blob/main/demo/MMSegmentation_Tutorial.ipynb

I use my own images but in the same format as the images in the tutorial except for the size.

When I run this cell:

# start training
runner.train()

I get this warning:

/mmsegmentation/mmseg/datasets/transforms/formatting.py:81: UserWarning: Please pay attention your ground truth segmentation map, usually the segmentation map is 2D, but got (264, 360, 3)

And the resulting plots indicates that the training did not work at all. What could be wrong here?

jinqin-99 commented 7 months ago

Well,I have the same problem, do you find any solutions?

jhaggle commented 7 months ago

Yes found the solution in an issue here actually. You have to do it as below. First convert to grayscale ("L"). Then apply a PIL.palette and then save the images in a new directory. Then it should work. If you don't know PIL.palette you can read about in PIL documentation.

for file in mmengine.scandir(os.path.join(data_root, ann_dir), suffix='.png'):
    seg_map = np.array(Image.open(os.path.join(data_root, ann_dir, file)).convert('L'))
    seg_img = Image.fromarray(seg_map).convert('P')
    seg_img.putpalette(np.array(palette, dtype=np.uint8))
    seg_img.save(os.path.join(data_root, new_dir, file))
jinqin-99 commented 7 months ago

Your solution is very useful! Thanks for your help!

2962313771 commented 7 months ago

Yes found the solution in an issue here actually. You have to do it as below. First convert to grayscale ("L"). Then apply a PIL.palette and then save the images in a new directory. Then it should work. If you don't know PIL.palette you can read about in PIL documentation.

for file in mmengine.scandir(os.path.join(data_root, ann_dir), suffix='.png'):
    seg_map = np.array(Image.open(os.path.join(data_root, ann_dir, file)).convert('L'))
    seg_img = Image.fromarray(seg_map).convert('P')
    seg_img.putpalette(np.array(palette, dtype=np.uint8))
    seg_img.save(os.path.join(data_root, new_dir, file))

Hello, in which folder is your code modified?

2962313771 commented 7 months ago

您的解决方案非常有用!感谢您的帮助!

Hello, in which folder is your code modified?

2962313771 commented 7 months ago

image 你们是在运行demo出现的错误,我实在运行 python tools/train.py configs/danet/danet_r50-d8_4xb4-160k_ade20k-512x512.py出现的错误我应该没有用到那个demo文件夹