{"record":{"id":"690c218f21e8b1cb","repo":"keras-team/keras","slug":"if-providing-bounding-boxes-labels-as-a-list","errorCode":null,"errorMessage":"If providing `bounding_boxes['labels']` as a list, it should contain integers labels. Received: bounding_boxes['labels']={labels}","messagePattern":"If providing `bounding_boxes\\['labels'\\]` as a list, it should contain integers labels\\. Received: bounding_boxes\\['labels'\\]=(.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/layers/preprocessing/image_preprocessing/bounding_boxes/validation.py","lineNumber":41,"sourceCode":"\ndef densify_bounding_boxes(\n    bounding_boxes,\n    is_batched=False,\n    max_boxes=None,\n    boxes_default_value=0,\n    labels_default_value=-1,\n    backend=None,\n):\n    validate_bounding_boxes(bounding_boxes)\n    boxes = bounding_boxes[\"boxes\"]\n    labels = bounding_boxes[\"labels\"]\n    backend = backend or current_backend\n    if isinstance(boxes, list):\n        if boxes and isinstance(boxes[0], list):\n            if boxes[0] and isinstance(boxes[0][0], list):\n                # Batched case\n                if not isinstance(labels[0][0], int):\n                    raise ValueError(\n                        \"If providing `bounding_boxes['labels']` as a list, \"\n                        \"it should contain integers labels. Received: \"\n                        f\"bounding_boxes['labels']={labels}\"\n                    )\n                if max_boxes is not None:\n                    max_boxes = max([len(b) for b in boxes])\n                new_boxes = []\n                new_labels = []\n                for b, l in zip(boxes, labels):\n                    if len(b) >= max_boxes:\n                        new_boxes.append(b[:max_boxes])\n                        new_labels.append(l[:max_boxes])\n                    else:\n                        num_boxes_to_add = max_boxes - len(b)\n                        added_boxes = [\n                            [\n                                boxes_default_value,\n                                boxes_default_value,","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/layers/preprocessing/image_preprocessing/bounding_boxes/validation.py#L23-L59","documentation":"densify_bounding_boxes converts ragged (variable-length) box lists into dense padded tensors. When boxes are given as nested Python lists (batched case: list of list of box), the parallel labels structure must contain Python ints at labels[batch][box]. If the first label element is not an int (e.g. a float, string, or tensor), this ValueError is raised.","triggerScenarios":"Calling a preprocessing layer or transform_bounding_boxes with bounding_boxes={'boxes': [[[...],[...]]], 'labels': [[0.0, 1.0]]} - float labels in list-mode input.","commonSituations":"Labels coming from a numpy array of float dtype, a JSON parse that produced floats, or a model output grafted into a list-of-lists structure with tensor elements.","solutions":["Cast labels to Python ints: labels=[[int(l) for l in b] for b in labels].","Convert numpy label arrays with .astype(int).tolist() before passing.","Alternatively pass boxes and labels as tensors/ragged tensors, which skips the int-only list path."],"exampleFix":"# before\nbb = {\"boxes\": [[[0,0,10,10],[5,5,20,20]]], \"labels\": [[0.0, 1.0]]}\nout = densify_bounding_boxes(bb)\n# after\nbb = {\"boxes\": [[[0,0,10,10],[5,5,20,20]]], \"labels\": [[int(0.0), int(1.0)]]}\nout = densify_bounding_boxes(bb)","handlingStrategy":"type-guard","validationCode":"labels = [[int(l) for l in batch] for batch in labels]  # before passing list-mode input","typeGuard":"def labels_are_int_lists(labels):\n    return (\n        isinstance(labels, list)\n        and labels\n        and isinstance(labels[0], list)\n        and bool(labels[0])\n        and isinstance(labels[0][0], int)\n    )\n","tryCatchPattern":null,"preventionTips":["Convert numpy label arrays with .astype(int).tolist() before building the bounding_boxes dict."],"tags":["keras","bounding-boxes","labels","densify","type-error"],"backgroundTag":"invalid-argument-type","analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","schemaVersion":2},"datasetVersion":"2026-08-26T02:17:13.382Z"}