TrickyGo / Dive-into-DL-TensorFlow2.0

本项目将《动手学深度学习》(Dive into Deep Learning)原书中的MXNet实现改为TensorFlow 2.0实现,项目已得到李沐老师的认可
https://trickygo.github.io/Dive-into-DL-TensorFlow2.0/#/
Apache License 2.0
3.79k stars 820 forks source link

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

Open lihua7351 opened 3 years ago

lihua7351 commented 3 years ago

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 commented 3 years ago

` 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 commented 3 years ago

Which chapter is this question about ?

lihua7351 commented 3 years ago

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

lihua7351 commented 3 years ago

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