jpg_file = image_file.numpy().decode(‘utf-8’)
bmp_file = jpg_file.replace(‘.jpg’, ‘.bmp’)
png_file = jpg_file.replace(‘.jpg’, ‘.png’)
image = np.array(Image.open(jpg_file))/127.5-1
map = np.array(Image.open(png_file))/127.5-1
labels = np.array(Image.open(bmp_file), dtype=np.uint8)
h,w,_ = image.shape
n_class = 12
mask = np.zeros((h,w,n_class),dtype=np.float32)
for i in range(n_class):
one_hot[labels==i,i] = 1
return map, image, mask
[mask, image, label] = tf.py_function(load_data, [image_file], [tf.float32, tf.float32, tf.float32])
了解了独热编码的语义分割掩码的格式后,我们将使用TensorFlow2
实现SPADE
。
实现SPADE
实例归一化
已在图像生成中非常流行,但是它往往会削弱分割蒙版的语义:假设输入图像仅包含一个分割标签;例如,假设整个图像都是天空,由于输入具有统一的值,因此输出在通过卷积层后