Documentation
Search…
wandb.data_types.BoundingBoxes2D
Format images with 2D bounding box overlays for logging to W&B.
1
BoundingBoxes2D(
2
val: dict,
3
key: str
4
) -> None
Copied!
Arguments
Text
val
(dictionary) A dictionary of the following form: box_data: (list of dictionaries) One dictionary for each bounding box, containing: position: (dictionary) the position and size of the bounding box, in one of two formats Note that boxes need not all use the same format. {"minX", "minY", "maxX", "maxY"}: (dictionary) A set of coordinates defining the upper and lower bounds of the box (the bottom left and top right corners) {"middle", "width", "height"}: (dictionary) A set of coordinates defining the center and dimensions of the box, with "middle" as a list [x, y] for the center point and "width" and "height" as numbers domain: (string) One of two options for the bounding box coordinate domain null: By default, or if no argument is passed, the coordinate domain is assumed to be relative to the original image, expressing this box as a fraction or percentage of the original image. This means all coordinates and dimensions passed into the "position" argument are floating point numbers between 0 and 1. "pixel": (string literal) The coordinate domain is set to the pixel space. This means all coordinates and dimensions passed into "position" are integers within the bounds of the image dimensions. class_id: (integer) The class label id for this box scores: (dictionary of string to number, optional) A mapping of named fields to numerical values (float or int), can be used for filtering boxes in the UI based on a range of values for the corresponding field box_caption: (string, optional) A string to be displayed as the label text above this box in the UI, often composed of the class label, class name, and/or scores class_labels: (dictionary, optional) A map of integer class labels to their readable class names
key
(string) The readable name or id for this set of bounding boxes (e.g. predictions, ground_truth)

Examples:

Log bounding boxes for a single image

1
import numpy as np
2
import wandb
3
4
wandb.init()
5
image = np.random.randint(low=0, high=256, size=(200, 300, 3))
6
7
class_labels = {
8
0: "person",
9
1: "car",
10
2: "road",
11
3: "building"
12
}
13
14
img = wandb.Image(image, boxes={
15
"predictions": {
16
"box_data": [
17
{
18
# one box expressed in the default relative/fractional domain
19
"position": {
20
"minX": 0.1,
21
"maxX": 0.2,
22
"minY": 0.3,
23
"maxY": 0.4
24
},
25
"class_id" : 1,
26
"box_caption": class_labels[1],
27
"scores" : {
28
"acc": 0.2,
29
"loss": 1.2
30
}
31
},
32
{
33
# another box expressed in the pixel domain
34
"position": {
35
"middle": [150, 20],
36
"width": 68,
37
"height": 112
38
},
39
"domain" : "pixel",
40
"class_id" : 3,
41
"box_caption": "a building",
42
"scores" : {
43
"acc": 0.5,
44
"loss": 0.7
45
}
46
},
47
# Log as many boxes an as needed
48
],
49
"class_labels": class_labels
50
}
51
})
52
53
wandb.log({"driving_scene": img})
Copied!

Log a bounding box overlay to a Table

1
import numpy as np
2
import wandb
3
4
wandb.init()
5
image = np.random.randint(low=0, high=256, size=(200, 300, 3))
6
7
class_labels = {
8
0: "person",
9
1: "car",
10
2: "road",
11
3: "building"
12
}
13
14
class_set = wandb.Classes([
15
{"name" : "person", "id" : 0},
16
{"name" : "car", "id" : 1},
17
{"name" : "road", "id" : 2},
18
{"name" : "building", "id" : 3}
19
])
20
21
img = wandb.Image(image, boxes={
22
"predictions": {
23
"box_data": [
24
{
25
# one box expressed in the default relative/fractional domain
26
"position": {
27
"minX": 0.1,
28
"maxX": 0.2,
29
"minY": 0.3,
30
"maxY": 0.4
31
},
32
"class_id" : 1,
33
"box_caption": class_labels[1],
34
"scores" : {
35
"acc": 0.2,
36
"loss": 1.2
37
}
38
},
39
{
40
# another box expressed in the pixel domain
41
"position": {
42
"middle": [150, 20],
43
"width": 68,
44
"height": 112
45
},
46
"domain" : "pixel",
47
"class_id" : 3,
48
"box_caption": "a building",
49
"scores" : {
50
"acc": 0.5,
51
"loss": 0.7
52
}
53
},
54
# Log as many boxes an as needed
55
],
56
"class_labels": class_labels
57
}
58
}, classes=class_set)
59
60
table = wandb.Table(columns=["image"])
61
table.add_data(img)
62
wandb.log({"driving_scene": table})
Copied!

Methods

type_name

1
@classmethod
2
type_name() -> str
Copied!

validate

1
validate(
2
val: dict
3
) -> bool
Copied!