{"record":{"id":"6edb6e6d4c063af4","repo":"open-mmlab/mmdetection","slug":"box-list-should-not-be-a-empty-list","errorCode":null,"errorMessage":"box_list should not be a empty list.","messagePattern":"box_list should not be a empty list\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"mmdet/structures/bbox/base_boxes.py","lineNumber":335,"sourceCode":"        assert dim != -1 and dim != self.tensor.dim()\n        return type(self)(self.tensor.unsqueeze(dim), clone=False)\n\n    @classmethod\n    def cat(cls: Type[T], box_list: Sequence[T], dim: int = 0) -> T:\n        \"\"\"Cancatenates a box instance list into one single box instance.\n        Similar to ``torch.cat``.\n\n        Args:\n            box_list (Sequence[T]): A sequence of box instances.\n            dim (int): The dimension over which the box are concatenated.\n                Defaults to 0.\n\n        Returns:\n            T: Concatenated box instance.\n        \"\"\"\n        assert isinstance(box_list, Sequence)\n        if len(box_list) == 0:\n            raise ValueError('box_list should not be a empty list.')\n\n        assert dim != -1 and dim != box_list[0].dim() - 1\n        assert all(isinstance(boxes, cls) for boxes in box_list)\n\n        th_box_list = [boxes.tensor for boxes in box_list]\n        return cls(torch.cat(th_box_list, dim=dim), clone=False)\n\n    @classmethod\n    def stack(cls: Type[T], box_list: Sequence[T], dim: int = 0) -> T:\n        \"\"\"Concatenates a sequence of tensors along a new dimension. Similar to\n        ``torch.stack``.\n\n        Args:\n            box_list (Sequence[T]): A sequence of box instances.\n            dim (int): Dimension to insert. Defaults to 0.\n\n        Returns:\n            T: Concatenated box instance.","sourceCodeStart":317,"sourceCodeEnd":353,"githubUrl":"https://github.com/open-mmlab/mmdetection/blob/cfd5d3a985b0249de009b67d04f37263e11cdf3d/mmdet/structures/bbox/base_boxes.py#L317-L353","documentation":"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.","triggerScenarios":"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.","commonSituations":"Data loaders yielding an empty batch, filter loops removing all boxes, or aggregating detections across an empty frame list in video inference.","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"],"exampleFix":"# before\nall_boxes = HorizontalBoxes.cat(box_list)\n# after\nall_boxes = (HorizontalBoxes.cat(box_list) if box_list\n             else HorizontalBoxes(torch.zeros(0, 4)))","handlingStrategy":"validation","validationCode":"assert isinstance(box_list, (list, tuple)) and len(box_list) > 0","typeGuard":"def can_cat_boxes(bl) -> bool:\n    return hasattr(bl, '__len__') and len(bl) > 0","tryCatchPattern":"from mmdet.structures.bbox import HorizontalBoxes\nimport torch\nmerged = HorizontalBoxes.cat(box_list) if box_list else HorizontalBoxes(torch.zeros(0, 4))","preventionTips":["Guard aggregation loops that can produce zero items","Return typed empty boxes instead of calling cat on []"],"tags":["mmdetection","bbox","empty-input"],"backgroundTag":"empty-collection-argument","analyzedSha":"cfd5d3a985b0249de009b67d04f37263e11cdf3d","analyzedAt":"2026-08-27T20:54:20.183Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}