SimonVandenhende / Multi-Task-Learning-PyTorch

PyTorch implementation of multi-task learning architectures, incl. MTI-Net (ECCV2020).
Other
780 stars 113 forks source link

Image visualizations #3

Closed sborse3 closed 4 years ago

sborse3 commented 4 years ago

Hi @SimonVandenhende , could you let me know if there's a tool in this repo which would help generate colorful pascal images?

Thanks!

SimonVandenhende commented 4 years ago

Hi. Its currently not available, but I will add it when updating the repository in December. For now, you can try using the following excerpt. This will give you a similar visualization for the segmentation maps as in the MTI-Net paper. If you need help with the other tasks, please let me know.

def color_map(N=256, normalized=False):
    def bitget(byteval, idx):
        return ((byteval & (1 << idx)) != 0)

    dtype = 'float32' if normalized else 'uint8'
    cmap = np.zeros((N, 3), dtype=dtype)
    for i in range(N):
        r = g = b = 0
        c = i
        for j in range(8):
            r = r | (bitget(c, 0) << 7-j)
            g = g | (bitget(c, 1) << 7-j)
            b = b | (bitget(c, 2) << 7-j)
            c = c >> 3

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

    cmap = cmap/255 if normalized else cmap
    return cmap 

# Semseg
mask = np.array(Image.open(semseg_filename))[:,:,np.newaxis]
cmap = color_map()[:,np.newaxis,:]
semseg_rgb = np.dot(mask == 0, cmap[0])
for i in range(1, cmap.shape[0]):
    semseg_rgb += np.dot(mask == i, cmap[i])

semseg_rgb = Image.fromarray(new_im.astype(np.uint8))
semseg_rgb_blend= Image.blend(Image.open(rgb_filename), semseg_rgb, alpha = 0.8)
sborse3 commented 4 years ago

Thanks! I was able to get this one for the semseg labels, how about human parts?

SimonVandenhende commented 4 years ago

You can reuse the code excerpt from above. I think the cmap was the same for semantic segmentation and human parts segmentation. Just replacing the semseg_filename with human_parts_filename should do the trick I believe.

sborse3 commented 4 years ago

Haha okay, thanks! I thought the parts and seg were from different datasets.

HarborYuan commented 2 years ago

Hi, could you please share the details (or links) about how to visualize the "sal", "normals", "edge"?

Thanks a lot! @SimonVandenhende