def decode_labels(mask, num_images=1, num_classes=20):
    'Decode batch of segmentation masks.\n\n    Args:\n      mask: result of inference after taking argmax.\n      num_images: number of images to decode from the batch.\n      num_classes: number of classes to predict (including background).\n\n    Returns:\n      A batch with num_images RGB images of the same size as the input.\n    '
    (n, h, w) = mask.shape
    assert (n >= num_images), ('Batch size %d should be greater or equal than number of images to save %d.' % (n, num_images))
    outputs = np.zeros((num_images, h, w, 3), dtype=np.uint8)
    for i in range(num_images):
        img = Image.new('RGB', (len(mask[(i, 0)]), len(mask[i])))
        pixels = img.load()
        for (j_, j) in enumerate(mask[i, :, :]):
            for (k_, k) in enumerate(j):
                if (k < num_classes):
                    pixels[(k_, j_)] = label_colours[k]
        outputs[i] = np.array(img)
    return outputs
Decode batch of segmentation masks.

Args:
  mask: result of inference after taking argmax.
  num_images: number of images to decode from the batch.
  num_classes: number of classes to predict (including background).

Returns:
  A batch with num_images RGB images of the same size as the input.
def decode_labels(mask, num_images=1, num_classes=20):
    'Decode batch of segmentation masks.\n\n    Args:\n      mask: result of inference after taking argmax.\n      num_images: number of images to decode from the batch.\n      num_classes: number of classes to predict (including background).\n\n    Returns:\n      A batch with num_images RGB images of the same size as the input.\n    '
    (n, h, w) = mask.shape
    assert (n >= num_images), ('Batch size %d should be greater or equal than number of images to save %d.' % (n, num_images))
    outputs = np.zeros((num_images, h, w, 3), dtype=np.uint8)
    for i in range(num_images):
        img = Image.new('RGB', (len(mask[(i, 0)]), len(mask[i])))
        pixels = img.load()
        for (j_, j) in enumerate(mask[i, :, :]):
            for (k_, k) in enumerate(j):
                if (k < num_classes):
                    pixels[(k_, j_)] = label_colours[k]
        outputs[i] = np.array(img)
    return outputs