Dive-into-DL-TensorFlow2.0 icon indicating copy to clipboard operation
Dive-into-DL-TensorFlow2.0 copied to clipboard

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

Open lihua7351 opened this issue 4 years ago • 4 comments

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 avatar Dec 22 '20 08:12 lihua7351

` 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]`

lihua7351 avatar Dec 22 '20 08:12 lihua7351

Which chapter is this question about ?

SwordFaith avatar Dec 22 '20 13:12 SwordFaith

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

lihua7351 avatar Dec 23 '20 05:12 lihua7351

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

lihua7351 avatar Dec 23 '20 05:12 lihua7351