bodokaiser / piwise

Pixel-wise segmentation on VOC2012 dataset using pytorch.
BSD 3-Clause "New" or "Revised" License
383 stars 86 forks source link

Is there some question in transform.py? #18

Open mshmoon opened 6 years ago

mshmoon commented 6 years ago

def colormap(n): cmap=np.zeros([n, 3]).astype(np.uint8)

for i in np.arange(n):
    r, g, b = np.zeros(3)

    for j in np.arange(8):
        r = r + (1<<(7-j))*((i&(1<<(3*j))) >> (3*j))
        g = g + (1<<(7-j))*((i&(1<<(3*j+1))) >> (3*j+1))
        b = b + (1<<(7-j))*((i&(1<<(3*j+2))) >> (3*j+2))

    cmap[i,:] = np.array([r, g, b])

return cmap

I do not understand the function,please help me... I use your main code to run a new network, but I can not decode a image from output

bodokaiser commented 6 years ago

Hey,

It is basically a python implementation of the Matlab class color function provided by the Pascal VOC project

https://gist.github.com/wllhf/a4533e0adebe57e3ed06d4b50c8419ae https://gist.github.com/wllhf/a4533e0adebe57e3ed06d4b50c8419ae

What it does is convert the labels (0, 1, …, 21 I think) to a more distinct RGB color code so that you can visualize how the network labeled objects.

Am 06.04.2018 um 13:32 schrieb mshmoon notifications@github.com:

def colormap(n): cmap=np.zeros([n, 3]).astype(np.uint8)

for i in np.arange(n): r, g, b = np.zeros(3)

for j in np.arange(8):
    r = r + (1<<(7-j))*((i&(1<<(3*j))) >> (3*j))
    g = g + (1<<(7-j))*((i&(1<<(3*j+1))) >> (3*j+1))
    b = b + (1<<(7-j))*((i&(1<<(3*j+2))) >> (3*j+2))

cmap[i,:] = np.array([r, g, b])

return cmap I do not understand the function,please help me... I use your main code to run a new network, but I can not decode a image from output

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/bodokaiser/piwise/issues/18, or mute the thread https://github.com/notifications/unsubscribe-auth/ABsq8u-TXv10gfRKrsDjp5amIwL2VIo_ks5tl1JhgaJpZM4TJ6IQ.

mshmoon commented 6 years ago

Sorry,this code have a trouble def call(self, gray_image): size = gray_image.size() print(gray_image) colorimage = torch.ByteTensor(3, size[0], size[1]).fill(0)

bodokaiser commented 6 years ago

You can also index over np.array as far as I know. What is the problem with for?

InstantWindy commented 6 years ago

index over np.array is not work ,beacause it appears other error,"TypeError: Performing basic indexing on a tensor and encountered an error indexing dim 0 with an object of type numpy.ndarray. "I don't know how to do ,can you answer me?Thank you