wandb.data_types.ImageMask

View source on GitHub

Wandb class for image masks or overlays, useful for tasks like semantic segmentation.

ImageMask(
val: dict,
key: str
) -> None

Arguments

val

(dictionary) One of these two keys to represent the image: mask_data : (2D numpy array) The mask containing an integer class label for each pixel in the image path : (string) The path to a saved image file of the mask class_labels : (dictionary of integers to strings, optional) A mapping of the integer class labels in the mask to readable class names. These will default to class_0, class_1, class_2, etc.

key

(string) The readable name or id for this mask type (e.g. predictions, ground_truth)

Examples:

Log a mask overlay for a given image

predicted_mask = np.array([[1, 2, 2, ... , 3, 2, 1], ...])
ground_truth_mask = np.array([[1, 1, 1, ... , 2, 3, 1], ...])
class_labels = {
0: "person",
1: "tree",
2: "car",
3: "road"
}
masked_image = wandb.Image(image, masks={
"predictions": {
"mask_data": predicted_mask,
"class_labels": class_labels
},
"ground_truth": {
"mask_data": ground_truth_mask,
"class_labels": class_labels
}
}
wandb.log({"img_with_masks" : masked_image})

Prepare an image mask to be added to a wandb.Table

raw_image_path = "sample_image.png"
predicted_mask_path = "predicted_mask.png"
class_set = wandb.Classes([
{"name" : "person", "id" : 0},
{"name" : "tree", "id" : 1},
{"name" : "car", "id" : 2},
{"name" : "road", "id" : 3}
])
masked_image = wandb.Image(raw_image_path, classes=class_set,
masks={"prediction" : {"path" : predicted_mask_path}})

Methods

type_name

View source

@classmethod
type_name() -> str

validate

View source

validate(
val: dict
) -> bool