huggingface/transformers · error · ValueError
Unsupported input type {type(bboxes_corners)}
Error message
Unsupported input type {type(bboxes_corners)} What it means
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).
Source
Thrown at src/transformers/image_transforms.py:608
return bboxes_center
def corners_to_center_format(bboxes_corners: TensorType) -> TensorType:
"""
Converts bounding boxes from corners format to center format.
corners format: contains the coordinates for the top-left and bottom-right corners of the box
(top_left_x, top_left_y, bottom_right_x, bottom_right_y)
center format: contains the coordinate for the center of the box and its the width, height dimensions
(center_x, center_y, width, height)
"""
# Inverse function accepts different input types so implemented here too
if is_torch_tensor(bboxes_corners):
return _corners_to_center_format_torch(bboxes_corners)
elif isinstance(bboxes_corners, np.ndarray):
return _corners_to_center_format_numpy(bboxes_corners)
raise ValueError(f"Unsupported input type {type(bboxes_corners)}")
def safe_squeeze(
tensor: Union[np.ndarray, "torch.Tensor"], axis: int | None = None
) -> Union[np.ndarray, "torch.Tensor"]:
"""
Squeezes a tensor, but only if the axis specified has dim 1.
"""
if axis is None:
return tensor.squeeze()
try:
return tensor.squeeze(axis=axis)
except ValueError:
return tensor
# 2 functions below copied from https://github.com/cocodataset/panopticapi/blob/master/panopticapi/utils.pyView on GitHub (pinned to a597f97485)
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.
Example fix
# before centers = corners_to_center_format([[0, 0, 100, 100]]) # raises # after import numpy as np centers = corners_to_center_format(np.array([[0, 0, 100, 100]]))
Defensive patterns
Strategy: type-guard
Validate before calling
import numpy as np
if not (is_torch_tensor(bboxes_corners) or isinstance(bboxes_corners, np.ndarray)):
bboxes_corners = np.asarray(bboxes_corners, dtype=float)
assert bboxes_corners.shape[-1] == 4 Type guard
def is_supported_boxes(x) -> bool:
import numpy as np
from transformers.utils import is_torch_tensor
return is_torch_tensor(x) or isinstance(x, np.ndarray) Prevention
- Wrap deserialized API payloads in np.asarray before geometry ops.
- Validate the last-dim size (4) along with the type.
When it happens
Trigger: corners_to_center_format(boxes_list) where boxes_list is a Python list/tuple of corner coordinates, or a non-torch tensor framework object.
Common situations: Post-processing detection outputs into COCO-style annotations with plain-list boxes, or feeding API/JSON payloads (which deserialize to lists) into geometry helpers.
Related errors
- Unsupported input type {type(bboxes_center)}
- `axis_value` for `HQQ` backend has to be one of [`0`, `1`] b
- You can construct a Cache either from a list `layers` of all
- You should provide exactly one of `layers` or `layer_class_t
- Cannot call `update_conv_state` on a non-LinearAttention lay
AI-assisted analysis of huggingface/transformers@a597f97485 (2026-08-14).
Data as JSON: /api/errors/df4267796551a983.
Report an issue: GitHub.