Labels, boxes, masks and groups
Models that tag a row with several labels, find objects in a picture, give every pixel a class, or put a row in a group: what a prediction of each is, and what applies to them.
Four tasks answer with a structure of their own. The client works each out from the model (see what Kaimei works out), or takes it as task=.
| task | The model's output | A prediction is |
|---|---|---|
multilabel_classification | A score for each of outputs.labels, through a sigmoid (head.link): each label its own yes or no. | {kind: "labels", labels, predicted, threshold, probabilities}: every label's probability, most likely first, and which are at or above the threshold (0.5 unless outputs.threshold says) |
object_detection | A fixed number of boxes, each with the scores of every class, or a score and a class. A PyTorch model's boxes and scores are joined into one output by the client. | {kind: "detections", detections, count, threshold, image}: the boxes that score 0.3 or more, best first and at most 100, each {label, class_index, score, box}, with box as [x0, y0, x1, y1] in pixels of the picture |
segmentation | Class scores for every pixel, or a class number for each. | {kind: "mask", shape, mask, classes, image}: the class of every pixel, one byte a cell, at most 256 cells a side, and each class's share of the picture, largest first |
clustering | The distance to each group's centre (a KMeans), or each group's probability (a Gaussian mixture). | {kind: "cluster", cluster, label, distances, distance}, or similarities and similarity |
#Reading the answers
- One line for every list. Each also has
label,class_indexandvalue, so lists, logs and older clients have something to show: the most likely label and how many are predicted; the best box and how many were found; the largest class that is not the background (outputs.background) and its share; the group. - Detectors. A Hugging Face detector (DETR, YOLOS, and their deformable and real-time kin) says how its boxes and scores are read. For any other PyTorch detector pass
output={"boxes": …, "scores": …, "classes": …, "box_format": "cxcywh", "normalized": True, "score_link": "softmax"}: names, or positions among whatforwardreturns. The model has to give a fixed number of boxes: one that cuts them down with non-maximum suppression inside the graph is drawn, not run. - Masks.
mask.datais base64, one byte a cell holding its class, so a segmentation may have 256 classes; a mask larger than 256 cells a side is sampled down to it. The dashboard draws boxes and masks over the picture. - Where a segmentation's classes are. The client reads the class axis off the model's graph: it follows the scores back from the output to the step that makes the classes (a convolution's channels, a linear layer's last axis), and an argmax on the way makes the output class numbers. When the graph does not say,
labels=does (the one axis as long as the labels), and then the shape. An output none of these settles is refused: passmask_layout="chw","hwc"or"indices". A model with several outputs is read from its first output of floats that can hold a mask (torchvision'sout, not itsaux);output=reads another. In a structure, the head says it:head.layout. A model that gives one score for each pixel is cut where its own probability is one half: at 0.5 when it ends in a sigmoid, at 0 when it gives raw scores, read off the graph, and off the model's own values when no step says. The head carries the cut (head.threshold, in the model's own numbers) and the structure's summary says it.threshold=says where to cut instead. - Heads are checked at upload. Every field a detector's, a segmenter's or a clustering's head is read with has to be what it says it is (columns inside the row, a box of four columns, thresholds on probabilities from 0 to 1): one that is not is
400 invalid_structure, withparamnaming it. A model run by its agent or its endpoint is read as its structure's head says, when one is uploaded, and otherwise as its registeredoutputssay. - What applies. A multi-label model is explained label by label, as a yes-or-no classifier of that label: the most likely one, unless
options.target_classnames another. Its counterfactual is the smallest change that takes that label acrossoutputs.threshold, whatever the other labels do. Detections, masks and groups have nothing one number of them can be attributed to, so theirexplain_methodsis empty. Analyses, insights and performance against outcomes need one class or one number for each row, and answer422 not_applicable_for_taskfor all four.
client.models.predict("photo-tags", input={"x0": 0.126, "x1": -0.132, "x2": 0.64,
"x3": 0.105, "x4": -0.536, "x5": 0.362})
client.models.predict("pet-finder", input={"image": picture}) # 64 × 64 × 3
client.models.predict("customer-groups", input={"spend": 0.4, "visits": -1.2, "tenure": 0.3})outputseveral labels
{
"kind": "labels",
"labels": [
{
"label": "night",
"index": 2,
"probability": 0.561518,
"predicted": true
},
{
"label": "people",
"index": 1,
"probability": 0.483665,
"predicted": false
},
…
],
"predicted": ["night"],
"threshold": 0.5,
"label": "night",
"class_index": 2,
"probability": 0.561518,
"value": 1,
"probabilities": {
"night": 0.561518,
"people": 0.483665,
"text": 0.451012,
"indoor": 0.447795
}
}outputboxes
{
"kind": "detections",
"detections": [
{
"label": "dog",
"class_index": 1,
"score": 0.367798,
"box": [15.99, 15.99, 48.0, 48.0]
},
…
],
"count": 6,
"threshold": 0.3,
"label": "dog",
"class_index": 1,
"probability": 0.367798,
"value": 6,
"image": {"feature": "image", "height": 64, "width": 64}
}outputa mask
{
"kind": "mask",
"shape": [16, 16],
"mask": {
"shape": [16, 16],
"encoding": "u8",
"data": "AgICAQICAQECAgIBAQICAQIB…",
"classes": 3
},
"classes": [
{"label": "cat", "index": 1, "share": 0.757813},
{"label": "dog", "index": 2, "share": 0.242188}
],
"label": "cat",
"class_index": 1,
"probability": 0.757813,
"value": 0.757813,
"image": {"feature": "image", "height": 32, "width": 32}
}outputa group
{
"kind": "cluster",
"cluster": 3,
"label": "cluster 3",
"class_index": 3,
"value": 3,
"distances": [1.290954, 2.118037, 2.363097, 0.980857],
"distance": 0.980857
}