`VOCDetection._write_voc_results_file` crashes with numpy 2.x: `ValueError: operands could not be broadcast together with shapes (1,5) (0,)`
_write_voc_results_file in yolox/data/datasets/voc.py crashes during evaluation whenever any image actually has a detection for a class, when running under numpy 2.x.
Root cause
dets = all_boxes[cls_ind][im_ind]
if dets == []:
continuedets is either a Python list [] (no detections) or a numpy array of shape (n, 5) (detections present). Comparing a numpy array to a Python list via == is an ambiguous elementwise/broadcast comparison. Older numpy silently returned False for shape-mismatched comparisons (with a DeprecationWarning); numpy 2.x tightened this and raises a hard error instead when the shapes aren't broadcastable - e.g. (1,5) against the empty list's implicit (0,).
Environment
- numpy: 2.5.2
- YOLOX: installed via
pip install -e .from a fresh clone ofmain - Triggered during a normal training run's periodic evaluation (
eval_interval), as soon as at least one image in the val set has at least one prediction for a class
Steps to reproduce
- Train on any VOC-format dataset with numpy>=2.0 installed.
- Let training reach an evaluation epoch where at least one detection is produced.
- Traceback:
File ".../yolox/data/datasets/voc.py", line 264, in _write_voc_results_file
if dets == []:
ValueError: operands could not be broadcast together with shapes (1,5) (0,)Suggested fix
Check length instead of equality, which works uniformly for both a Python list and a numpy array of any shape:
dets = all_boxes[cls_ind][im_ind]
if len(dets) == 0:
continueVerified this resolves the crash (tested against list, empty-array, and non-empty-array inputs).
Note: this and the earlier self.root + "/" path-splitting bug both live in the same file, yolox/data/datasets/voc.py
Source: Megvii-BaseDetection/YOLOX