facebookresearch/detectron2 · error · NotImplementedError
Conversion from BoxMode {} to {} is not supported yet
Error message
Conversion from BoxMode {} to {} is not supported yet What it means
BoxMode.convert implements only XYXY_ABS<->XYWH_ABS and to/from XYWHA_REL (partial) conversions. Any other pair, notably anything involving XYWHA_ABS or XYWHA_REL with absolute inputs in unsupported directions, raises NotImplementedError.
Source
Thrown at detectron2/structures/boxes.py:116
arr[:, 3] = arr[:, 1] + new_h
arr = arr[:, :4].to(dtype=original_dtype)
elif from_mode == BoxMode.XYWH_ABS and to_mode == BoxMode.XYWHA_ABS:
original_dtype = arr.dtype
arr = arr.double()
arr[:, 0] += arr[:, 2] / 2.0
arr[:, 1] += arr[:, 3] / 2.0
angles = torch.zeros((arr.shape[0], 1), dtype=arr.dtype)
arr = torch.cat((arr, angles), axis=1).to(dtype=original_dtype)
else:
if to_mode == BoxMode.XYXY_ABS and from_mode == BoxMode.XYWH_ABS:
arr[:, 2] += arr[:, 0]
arr[:, 3] += arr[:, 1]
elif from_mode == BoxMode.XYXY_ABS and to_mode == BoxMode.XYWH_ABS:
arr[:, 2] -= arr[:, 0]
arr[:, 3] -= arr[:, 1]
else:
raise NotImplementedError(
"Conversion from BoxMode {} to {} is not supported yet".format(
from_mode, to_mode
)
)
if single_box:
return original_type(arr.flatten().tolist())
if is_numpy:
return arr.numpy()
else:
return arr
class Boxes:
"""
This structure stores a list of boxes as a Nx4 torch.Tensor.
It supports some common methods about boxes
(`area`, `clip`, `nonempty`, etc),View on GitHub (pinned to a2f4a8771a)
Solutions
- Convert manually (e.g. with shapely or box_ops) for the unsupported pair
- Convert to an intermediate supported mode (XYXY_ABS or XYWH_ABS) in two steps if direction is the issue
- Use detectron2.structures.rotated_boxes.rotated_box_to_aligned_box for XYWHA_ABS -> XYXY_ABS
Example fix
# before boxes_xyxy = BoxMode.convert(boxes, BoxMode.XYWHA_ABS, BoxMode.XYXY_ABS) # after from detectron2.structures.rotated_boxes import rotated_box_to_aligned_box boxes_xyxy = rotated_box_to_aligned_box(boxes)
Defensive patterns
Strategy: fallback
Validate before calling
from detectron2.structures import BoxMode
supported = {(BoxMode.XYXY_ABS, BoxMode.XYWH_ABS), (BoxMode.XYWH_ABS, BoxMode.XYXY_ABS), (BoxMode.XYXY_ABS, BoxMode.XYWHA_REL), (BoxMode.XYWHA_REL, BoxMode.XYXY_ABS), (BoxMode.XYWH_ABS, BoxMode.XYWHA_REL)}
assert (from_mode, to_mode) in supported, 'unsupported BoxMode conversion' Type guard
def can_convert(f, t) -> bool:
return (f, t) in {(BoxMode.XYXY_ABS, BoxMode.XYWH_ABS), (BoxMode.XYWH_ABS, BoxMode.XYXY_ABS), (BoxMode.XYXY_ABS, BoxMode.XYWHA_REL), (BoxMode.XYWHA_REL, BoxMode.XYXY_ABS), (BoxMode.XYWH_ABS, BoxMode.XYWHA_REL)} Try / catch
try:
out = BoxMode.convert(b, f, t)
except NotImplementedError:
out = manual_convert(b, f, t) # e.g. rotated_box_to_aligned_box Prevention
- Normalize all boxes to XYXY_ABS/XYWH_ABS at load time
- Use rotated_boxes utilities for XYWHA conversions
When it happens
Trigger: Calling BoxMode.convert(boxes, from_mode=BoxMode.XYWHA_ABS, to_mode=BoxMode.XYXY_ABS); the rotated-box branch only handles a subset of direction/mode pairs.
Common situations: Rotated detection (RRPN/Rotated BBox datasets like DOTA) converting rotated annotations to axis-aligned boxes; mixing REL and ABS conventions across datasets.
Related errors
- Cannot match one checkpoint key to multiple keys in the mode
- Class with @configurable must have a 'from_config' classmeth
- {name} must take 'cfg' as the first argument!
- target of LazyCall must be a callable or defines a callable!
- deletion is not yet a supported override
AI-assisted analysis of facebookresearch/detectron2@a2f4a8771a (2026-08-27).
Data as JSON: /api/errors/097661428ecffa15.
Report an issue: GitHub.