hendrycks / anomaly-seg

The Combined Anomalous Object Segmentation (CAOS) Benchmark
MIT License
154 stars 20 forks source link

About ground truth Semantic Segmentation images #26

Closed JackyLin7414 closed 2 years ago

JackyLin7414 commented 2 years ago

[[[Hey so you can use the script below to undo the conversion from uint back to colors. The main difference that I had forgotten was that the counter starts at 1. The semantic segmentation pytorch code ignores the index 0 and this was our hack to get the code to learn the background class. I attached one of the examples below to demonstrate it working in converting back to the original colors.

import numpy as np
from PIL import Image as image
import os
root = "annotations/test/t5/" 
test_images = os.listdir(root) 
#StreetHazards colors 
colors = np.array([[ 0,   0,   0], # // unlabeled     =   0,
[ 70,  70,  70], # // building      =   1,
[190, 153, 153], # // fence         =   2, 
[250, 170, 160], # // other         =   3,
[220,  20,  60], # // pedestrian    =   4, 
[153, 153, 153], # // pole          =   5,
[157, 234,  50], # // road line     =   6, 
[128,  64, 128], # // road          =   7,
[244,  35, 232], # // sidewalk      =   8,
[107, 142,  35], # // vegetation    =   9, 
[  0,   0, 142], # // car           =  10,
[102, 102, 156], # // wall          =  11, 
[220, 220,   0], # // traffic sign  =  12,
[ 60, 250, 240], # // anomaly       =  13,
]) 
for im_path in test_images: 
    im = image.open(root+im_path)
    pic = np.array(im)
    new_img = np.zeros((720, 1280, 3))
    for index, color in enumerate(colors):
        new_img[pic==(index+1)] = colors[index]
        new_img = image.fromarray(new_img.astype('uint8'), 'RGB')
        new_img.save(root+"rgb_"+str(im_path))

Example 300 converted back into standard RGB colors. rgb_300

Hope you find the dataset helpful :)

Originally posted by @xksteven in https://github.com/hendrycks/anomaly-seg/issues/15#issuecomment-890300278](https://github.com/hendrycks/anomaly-seg/issues/15#issuecomment-890300278)](https://github.com/hendrycks/anomaly-seg/issues/15#issuecomment-890300278)](https://github.com/hendrycks/anomaly-seg/issues/15#issuecomment-890300278)

Hi, @xksteven I don't know where to run this code. Can you tell me.

Thank you. I appreciate it. Jacky

xksteven commented 2 years ago

Hey could you be more specific as to what you're question is?

The file is called create_dataset.py and it replaces data/color150.mat so it should be run in the semantic-segmentation-pytorch folder. Not sure if that answers your question?

JackyLin7414 commented 2 years ago

Hi, @xksteven Thank you for the quick response. So if I put this code in the semantic-segmentation-pytorch folder and run. I will get the pictures like you attached in annotations/test/t5/ folder?

If I have data/coler150.mat. I can just run create_dataset.py and unblock line 15-36 to get Semantic Segmentation pictures?

Thank you. I appreciate it. Jacky

xksteven commented 2 years ago

That's correct. To get the pictures to be exact same colors I believe you'll need to add another entry into the array. Specifically another [0,0,0] in the beginning but I haven't tested it.

Let me know if you run into any issues.

JackyLin7414 commented 2 years ago

Hi, @xksteven Thank you for the quick response. Your answer is exactly what i want. I appreciate it.

Jacky