{"record":{"id":"e5e251089be0990b","repo":"huggingface/transformers","slug":"unsupported-input-type-type-bboxes-center","errorCode":null,"errorMessage":"Unsupported input type {type(bboxes_center)}","messagePattern":"Unsupported input type (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/transformers/image_transforms.py","lineNumber":565,"sourceCode":"\n\n# 2 functions below inspired by https://github.com/facebookresearch/detr/blob/master/util/box_ops.py\ndef center_to_corners_format(bboxes_center: TensorType) -> TensorType:\n    \"\"\"\n    Converts bounding boxes from center format to corners format.\n\n    center format: contains the coordinate for the center of the box and its width, height dimensions\n        (center_x, center_y, width, height)\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    \"\"\"\n    # Function is used during model forward pass, so we use torch if relevant, without converting to numpy\n    if is_torch_tensor(bboxes_center):\n        return _center_to_corners_format_torch(bboxes_center)\n    elif isinstance(bboxes_center, np.ndarray):\n        return _center_to_corners_format_numpy(bboxes_center)\n\n    raise ValueError(f\"Unsupported input type {type(bboxes_center)}\")\n\n\ndef _corners_to_center_format_torch(bboxes_corners: \"torch.Tensor\") -> \"torch.Tensor\":\n    top_left_x, top_left_y, bottom_right_x, bottom_right_y = bboxes_corners.unbind(-1)\n    b = [\n        (top_left_x + bottom_right_x) / 2,  # center x\n        (top_left_y + bottom_right_y) / 2,  # center y\n        (bottom_right_x - top_left_x),  # width\n        (bottom_right_y - top_left_y),  # height\n    ]\n    return torch.stack(b, dim=-1)\n\n\ndef _corners_to_center_format_numpy(bboxes_corners: np.ndarray) -> np.ndarray:\n    top_left_x, top_left_y, bottom_right_x, bottom_right_y = bboxes_corners.T\n    bboxes_center = np.stack(\n        [\n            (top_left_x + bottom_right_x) / 2,  # center x","sourceCodeStart":547,"sourceCodeEnd":583,"githubUrl":"https://github.com/huggingface/transformers/blob/a597f974857b3d92939971296bc0deb93d33d780/src/transformers/image_transforms.py#L547-L583","documentation":"center_to_corners_format dispatches on input type: torch tensors go to the torch kernel, numpy arrays to the numpy kernel; anything else (lists, tuples) raises ValueError. Used in detection forward passes, so it avoids silent device round-trips by refusing unknown types.","triggerScenarios":"center_to_corners_format([[50, 50, 100, 100]]) with a plain Python list, or passing a tf.Tensor / jax array.","commonSituations":"Feeding model outputs or config values that are plain lists into detection postprocessing (e.g. post_process_object_detection outputs are fine, but hand-built boxes are not), or mixing frameworks.","solutions":["Convert lists to np.ndarray: np.asarray(boxes).","Keep boxes as whatever your framework kernel produced (torch tensors stay torch).","Ensure shape is (..., 4) center format before converting."],"exampleFix":"# before\ncorners = center_to_corners_format([[50.0, 50.0, 100.0, 100.0]])  # raises\n\n# after\nimport numpy as np\ncorners = center_to_corners_format(np.array([[50.0, 50.0, 100.0, 100.0]]))","handlingStrategy":"type-guard","validationCode":"import numpy as np\nif not (is_torch_tensor(bboxes_center) or isinstance(bboxes_center, np.ndarray)):\n    bboxes_center = np.asarray(bboxes_center, dtype=float)\nassert bboxes_center.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":["Convert JSON/list boxes to np.asarray at ingestion.","Keep boxes in the tensor type your postprocessing kernel emits."],"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"}