keras-team/keras · error · KeyError
There are unsupported keys in `bounding_boxes`: {list(extra_
Error message
There are unsupported keys in `bounding_boxes`: {list(extra_keys)}. Only `boxes` and `labels` are supported. What it means
MaxNumBoundingBoxes.compute_output_shape only accepts 'boxes' and 'labels' keys inside the bounding_boxes dict. Extra keys such as 'confidence', 'num_classes', or custom metadata raise a KeyError before shape computation.
Source
Thrown at keras/src/layers/preprocessing/image_preprocessing/max_num_bounding_box.py:98
boxes = ops.numpy.reshape(boxes, [batch_size, self.max_number, 4])
labels = ops.numpy.reshape(labels, [batch_size, self.max_number])
bounding_boxes = bounding_boxes.copy()
bounding_boxes["boxes"] = boxes
bounding_boxes["labels"] = labels
return bounding_boxes
def transform_segmentation_masks(
self, segmentation_masks, transformation=None, training=True
):
return self.transform_images(segmentation_masks)
def compute_output_shape(self, input_shape):
if isinstance(input_shape, dict) and "bounding_boxes" in input_shape:
input_keys = set(input_shape["bounding_boxes"].keys())
extra_keys = input_keys - set(("boxes", "labels"))
if extra_keys:
raise KeyError(
"There are unsupported keys in `bounding_boxes`: "
f"{list(extra_keys)}. "
"Only `boxes` and `labels` are supported."
)
boxes_shape = list(input_shape["bounding_boxes"]["boxes"])
boxes_shape[1] = self.max_number
labels_shape = list(input_shape["bounding_boxes"]["labels"])
labels_shape[1] = self.max_number
input_shape["bounding_boxes"]["boxes"] = boxes_shape
input_shape["bounding_boxes"]["labels"] = labels_shape
return input_shape
def get_config(self):
config = super().get_config()
config.update({"max_number": self.max_number})
return config
View on GitHub (pinned to 7a34a03db6)
Solutions
- Strip extra keys before feeding the layer: bbs = {'boxes': bbs['boxes'], 'labels': bbs['labels']}
- Carry auxiliary metadata (scores, difficulty flags) outside the bounding_boxes dict, in a parallel structure
- If you need confidences, fold them into labels or a separate input
Example fix
# before
bbs = {'boxes': boxes, 'labels': labels, 'confidence': confs}
# after
bbs = {'boxes': boxes, 'labels': labels}
confs_outside = confs Defensive patterns
Strategy: validation
Validate before calling
allowed = {'boxes', 'labels'}
extra = set(bbs) - allowed
if extra:
bbs = {k: bbs[k] for k in allowed}
# keep extras separately
extras = {k: v for k, v in bbs_orig.items() if k not in allowed} Type guard
def has_only_supported_keys(bbs):
return set(bbs) <= {'boxes', 'labels'} Prevention
- Keep auxiliary per-box data outside the bounding_boxes dict
- Prune annotation dicts to boxes/labels before model input
When it happens
Trigger: Building a model whose input spec includes {'bounding_boxes': {'boxes': ..., 'labels': ..., 'confidence': ...}} and passing it to this layer's compute_output_shape / model build.
Common situations: Detection pipelines that carry extra per-box metadata alongside labels; converting a COCO-style annotation dict directly to layer input without pruning keys; version changes that tightened accepted keys.
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
- `adapt()` can only be called on a tf.data.Dataset or a dict
- Invalid value for argument `output_mode`. Expected one of {a
- `sparse` may only be true if `output_mode` is `"one_hot"`, `
- The `salt` argument for `Hashing` can only be a tuple of siz
- `height` and `width` must be set if `format='xyxy'`.
AI-assisted analysis of keras-team/keras@7a34a03db6 (2026-08-25).
Data as JSON: /api/errors/90ec55deff41cd85.
Report an issue: GitHub.