open-mmlab/mmdetection · error · ValueError
box_list should not be a empty list.
Error message
box_list should not be a empty list.
What it means
BaseBoxes.cat concatenates box instances along an existing dim; an empty input list has no boxes to concatenate and no way to infer the box type/shape, so it raises ValueError immediately.
Source
Thrown at mmdet/structures/bbox/base_boxes.py:335
assert dim != -1 and dim != self.tensor.dim()
return type(self)(self.tensor.unsqueeze(dim), clone=False)
@classmethod
def cat(cls: Type[T], box_list: Sequence[T], dim: int = 0) -> T:
"""Cancatenates a box instance list into one single box instance.
Similar to ``torch.cat``.
Args:
box_list (Sequence[T]): A sequence of box instances.
dim (int): The dimension over which the box are concatenated.
Defaults to 0.
Returns:
T: Concatenated box instance.
"""
assert isinstance(box_list, Sequence)
if len(box_list) == 0:
raise ValueError('box_list should not be a empty list.')
assert dim != -1 and dim != box_list[0].dim() - 1
assert all(isinstance(boxes, cls) for boxes in box_list)
th_box_list = [boxes.tensor for boxes in box_list]
return cls(torch.cat(th_box_list, dim=dim), clone=False)
@classmethod
def stack(cls: Type[T], box_list: Sequence[T], dim: int = 0) -> T:
"""Concatenates a sequence of tensors along a new dimension. Similar to
``torch.stack``.
Args:
box_list (Sequence[T]): A sequence of box instances.
dim (int): Dimension to insert. Defaults to 0.
Returns:
T: Concatenated box instance.View on GitHub (pinned to cfd5d3a985)
Solutions
- Guard with 'if not box_list: return' or create an empty box instance: cls(torch.zeros(0, 4))
- Check upstream filters that may legitimately produce zero detections before calling cat
- Use the dataloader's default collate which handles empty samples
Example fix
# before
all_boxes = HorizontalBoxes.cat(box_list)
# after
all_boxes = (HorizontalBoxes.cat(box_list) if box_list
else HorizontalBoxes(torch.zeros(0, 4))) Defensive patterns
Strategy: validation
Validate before calling
assert isinstance(box_list, (list, tuple)) and len(box_list) > 0
Type guard
def can_cat_boxes(bl) -> bool:
return hasattr(bl, '__len__') and len(bl) > 0 Try / catch
from mmdet.structures.bbox import HorizontalBoxes import torch merged = HorizontalBoxes.cat(box_list) if box_list else HorizontalBoxes(torch.zeros(0, 4))
Prevention
- Guard aggregation loops that can produce zero items
- Return typed empty boxes instead of calling cat on []
When it happens
Trigger: Calling HorizontalBoxes.cat([]) (or via batch collate of zero samples), e.g. looping over per-image boxes in a loop that may execute zero times.
Common situations: Data loaders yielding an empty batch, filter loops removing all boxes, or aggregating detections across an empty frame list in video inference.
Related errors
- boxes should be Tensor, ndarray, or Sequence, but got {type(
- LoadImageFromFile is not found in the test pipeline
- Visualization needs the "visualizer" termdefined in the conf
- Unsupported input type: {type(single_input)}
- panopticapi is not installed, please install it by: pip inst
AI-assisted analysis of open-mmlab/mmdetection@cfd5d3a985 (2026-08-27).
Data as JSON: /api/errors/6edb6e6d4c063af4.
Report an issue: GitHub.