keras-team/keras · error · ValueError

Expected `bounding_boxes` agurment to be a dict with keys 'b

Error message

Expected `bounding_boxes` agurment to be a dict with keys 'boxes' and 'labels'. Received: bounding_boxes={bounding_boxes}

What it means

validate_bounding_boxes is the shared sanity check that the bounding_boxes argument is a dict containing both required keys: 'boxes' and 'labels'. If the argument is not a dict at all, or is missing either key, this ValueError is raised (note the typo 'agurment' in the message).

Source

Thrown at keras/src/layers/preprocessing/image_preprocessing/bounding_boxes/validation.py:124

            default_value=labels_default_value,
            shape=_classes_shape(
                is_batched, bounding_boxes["labels"].shape, max_boxes
            ),
        )
        return bounding_boxes

    bounding_boxes["boxes"] = backend.convert_to_tensor(boxes, dtype="float32")
    bounding_boxes["labels"] = backend.convert_to_tensor(labels)
    return bounding_boxes


def validate_bounding_boxes(bounding_boxes):
    if (
        not isinstance(bounding_boxes, dict)
        or "labels" not in bounding_boxes
        or "boxes" not in bounding_boxes
    ):
        raise ValueError(
            "Expected `bounding_boxes` agurment to be a "
            "dict with keys 'boxes' and 'labels'. Received: "
            f"bounding_boxes={bounding_boxes}"
        )
    boxes = bounding_boxes["boxes"]
    labels = bounding_boxes["labels"]
    if isinstance(boxes, list):
        if not isinstance(labels, list):
            raise ValueError(
                "If `bounding_boxes['boxes']` is a list, then "
                "`bounding_boxes['labels']` must also be a list."
                f"Received: bounding_boxes['labels']={labels}"
            )
        if len(boxes) != len(labels):
            raise ValueError(
                "If `bounding_boxes['boxes']` and "
                "`bounding_boxes['labels']` are both lists, "
                "they must have the same length. Received: "

View on GitHub (pinned to 7a34a03db6)

Solutions

  1. Wrap the data as a dict with both keys: bounding_boxes={'boxes': boxes, 'labels': labels}.
  2. Ensure the labels key is present even if all labels are dummy values (e.g. -1 padding labels).
  3. Check for singular/plural key typos ('box'/'label') in dicts built from JSON.

Example fix

# before
out = densify_bounding_boxes(boxes_array)
# after
out = densify_bounding_boxes({"boxes": boxes_array, "labels": labels_array})
Defensive patterns

Strategy: type-guard

Validate before calling

assert isinstance(bounding_boxes, dict) and {"boxes", "labels"} <= bounding_boxes.keys(), "bounding_boxes must be a dict with 'boxes' and 'labels'"

Type guard

def is_valid_bounding_boxes_dict(bb):
    return isinstance(bb, dict) and "boxes" in bb and "labels" in bb

Prevention

When it happens

Trigger: Passing a plain array of boxes, a dict with only {'boxes': ...}, or {'box': ..., 'label': ...} (singular keys) to densify_bounding_boxes or validate_bounding_boxes.

Common situations: Feeding detector output (often a list or tuple) directly into preprocessing layers; key-name drift between serialization formats and the expected API.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


AI-assisted analysis of keras-team/keras@7a34a03db6 (2026-08-25). Data as JSON: /api/errors/084dd9d3d110a20d. Report an issue: GitHub.