Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The funtion of colormap2label may not be effective , the converted label does not correspond. #75

Open
lihua7351 opened this issue Dec 22, 2020 · 4 comments

Comments

@lihua7351
Copy link

test-rgb2label.pdf
The result for [0,0,128] should be labeled as 4, but got the 0. Hope to get your reply, thank you!
The input image from VOC2012\SegmentationClass\2007_000061.png
2007_000061

@lihua7351
Copy link
Author

`
import os
import json
#import cv2
from tqdm import tqdm
import numpy as np
from glob import glob
import tensorflow as tf
import matplotlib.pyplot as plt
import skimage.io as io
from tensorflow.keras.callbacks import Callback
from tensorflow.keras.callbacks import TensorBoard, ModelCheckpoint, EarlyStopping, LearningRateScheduler
print('TensorFlow', tf.version)

img1 = tf.io.read_file("C:/Users/eadhaw/Desktop/1221/5.png")
img1 = tf.image.decode_png(img1)
print(img1.shape)

VOC_COLORMAP = [[0, 0, 0], [128, 0, 0], [0, 128, 0], [128, 128, 0],
[0, 0, 128], [128, 0, 128], [0, 128, 128], [128, 128, 128],
[64, 0, 0], [192, 0, 0], [64, 128, 0], [192, 128, 0],
[64, 0, 128], [192, 0, 128], [64, 128, 128], [192, 128, 128],
[0, 64, 0], [128, 64, 0], [0, 192, 0], [128, 192, 0],
[0, 64, 128]]
colormap2label = np.zeros(256 ** 3, dtype=np.uint8)

for i, colormap in enumerate(VOC_COLORMAP):
colormap2label[(colormap[0] * 256 + colormap[1]) * 256 + colormap[2]] = i
colormap2label = tf.convert_to_tensor(colormap2label)
def voc_label_indices(colormap, colormap2label):
"""
convert colormap (tf image) to colormap2label (uint8 tensor).
"""
colormap = tf.cast(colormap, dtype=tf.int32)
idx = tf.add(tf.multiply(colormap[:, :, 0], 256), colormap[:, :, 1])
idx = tf.add(tf.multiply(idx, 256), colormap[:, :, 2])
idx = tf.add(idx, colormap[:, :, 2])
return tf.gather_nd(colormap2label, tf.expand_dims(idx, -1))

y = voc_label_indices(img1, colormap2label)

img1[230:240,325:330,:]

y[230:240,325:330]`

@SwordFaith
Copy link
Collaborator

Which chapter is this question about ?

@lihua7351
Copy link
Author

chapter09_computer-vision/9.9_semantic-segmentation-and-dataset.ipynb/def voc_label_indices(colormap, colormap2label):

@lihua7351
Copy link
Author

这个问题是关于哪一章的?
Chapter09_computer-vision / 9.9_semantic-segmentation-and-dataset.ipynb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants