{"record":{"id":"df4267796551a983","repo":"huggingface/transformers","slug":"unsupported-input-type-type-bboxes-corners","errorCode":null,"errorMessage":"Unsupported input type {type(bboxes_corners)}","messagePattern":"Unsupported input type (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/transformers/image_transforms.py","lineNumber":608,"sourceCode":"    return bboxes_center\n\n\ndef corners_to_center_format(bboxes_corners: TensorType) -> TensorType:\n    \"\"\"\n    Converts bounding boxes from corners format to center format.\n\n    corners format: contains the coordinates for the top-left and bottom-right corners of the box\n        (top_left_x, top_left_y, bottom_right_x, bottom_right_y)\n    center format: contains the coordinate for the center of the box and its the width, height dimensions\n        (center_x, center_y, width, height)\n    \"\"\"\n    # Inverse function accepts different input types so implemented here too\n    if is_torch_tensor(bboxes_corners):\n        return _corners_to_center_format_torch(bboxes_corners)\n    elif isinstance(bboxes_corners, np.ndarray):\n        return _corners_to_center_format_numpy(bboxes_corners)\n\n    raise ValueError(f\"Unsupported input type {type(bboxes_corners)}\")\n\n\ndef safe_squeeze(\n    tensor: Union[np.ndarray, \"torch.Tensor\"], axis: int | None = None\n) -> Union[np.ndarray, \"torch.Tensor\"]:\n    \"\"\"\n    Squeezes a tensor, but only if the axis specified has dim 1.\n    \"\"\"\n    if axis is None:\n        return tensor.squeeze()\n\n    try:\n        return tensor.squeeze(axis=axis)\n    except ValueError:\n        return tensor\n\n\n# 2 functions below copied from https://github.com/cocodataset/panopticapi/blob/master/panopticapi/utils.py","sourceCodeStart":590,"sourceCodeEnd":626,"githubUrl":"https://github.com/huggingface/transformers/blob/a597f974857b3d92939971296bc0deb93d33d780/src/transformers/image_transforms.py#L590-L626","documentation":"corners_to_center_format is the inverse conversion with the same dispatch rule: only torch tensors and numpy arrays are accepted; lists or other tensor types raise ValueError. It converts (top_left_x, top_left_y, bottom_right_x, bottom_right_y) to (center_x, center_y, width, height).","triggerScenarios":"corners_to_center_format(boxes_list) where boxes_list is a Python list/tuple of corner coordinates, or a non-torch tensor framework object.","commonSituations":"Post-processing detection outputs into COCO-style annotations with plain-list boxes, or feeding API/JSON payloads (which deserialize to lists) into geometry helpers.","solutions":["Wrap with np.asarray(boxes) (or torch.tensor(boxes) if in a torch pipeline).","Keep the tensor type consistent with the rest of the pipeline.","Validate boxes.shape[-1] == 4 before calling."],"exampleFix":"# before\ncenters = corners_to_center_format([[0, 0, 100, 100]])  # raises\n\n# after\nimport numpy as np\ncenters = corners_to_center_format(np.array([[0, 0, 100, 100]]))","handlingStrategy":"type-guard","validationCode":"import numpy as np\nif not (is_torch_tensor(bboxes_corners) or isinstance(bboxes_corners, np.ndarray)):\n    bboxes_corners = np.asarray(bboxes_corners, dtype=float)\nassert bboxes_corners.shape[-1] == 4","typeGuard":"def is_supported_boxes(x) -> bool:\n    import numpy as np\n    from transformers.utils import is_torch_tensor\n    return is_torch_tensor(x) or isinstance(x, np.ndarray)","tryCatchPattern":null,"preventionTips":["Wrap deserialized API payloads in np.asarray before geometry ops.","Validate the last-dim size (4) along with the type."],"tags":["object-detection","bounding-boxes","typeerror","valueerror"],"backgroundTag":null,"analyzedSha":"a597f974857b3d92939971296bc0deb93d33d780","analyzedAt":"2026-08-14T18:24:08.354Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}