#1904·YOLOX

`VOCDetection._write_voc_results_file` crashes with numpy 2.x: `ValueError: operands could not be broadcast together with shapes (1,5) (0,)`

Author: HikeAndMapCreated Aug 29, 2026Updated Aug 29, 2026

_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

python
dets = all_boxes[cls_ind][im_ind]
if dets == []:
    continue

dets 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 of main
  • 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

  1. Train on any VOC-format dataset with numpy>=2.0 installed.
  2. Let training reach an evaluation epoch where at least one detection is produced.
  3. 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:

python
dets = all_boxes[cls_ind][im_ind]
if len(dets) == 0:
    continue

Verified 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