Affected File
lib/utils/data_utils.py:410-411
Current Code
def inter_from_mask(pred, gt):
pred = pred.astype(np.bool)
gt = gt.astype(np.bool)
intersection = np.logical_and(gt, pred).sum()
return intersection
Root Cause
np.bool was deprecated in NumPy 1.20 and fully removed in NumPy 1.24 (2022-12). In NumPy >= 1.24, using np.bool raises:
AttributeError: module 'numpy' has no attribute 'bool'
np.bool was an alias for Python's built-in bool.
Impact
- Severity: High — hard crash at runtime on NumPy >= 1.24
- Affects the
inter_from_mask utility function used for intersection computation between prediction and ground-truth masks
Dependency Chain
Although requirements.txt does not list numpy directly, it is pulled in transitively by every declared dependency:
| Package |
Requires numpy |
scikit-image==0.19.0 |
numpy>=1.24 |
opencv-python |
numpy>=2 (Python 3.9+) |
kornia |
numpy<3 (dev extra) |
imgaug |
numpy>=1.15 |
lpips |
numpy>=1.14.3 |
imageio==2.27.0 |
numpy |
plyfile |
numpy>=2.0 |
tensorboardX |
numpy |
The resolver takes the tightest constraints: numpy>=2.0 (from plyfile and opencv-python). Any numpy >= 2.0 has already removed np.bool, so this issue is guaranteed to trigger.
Solution
# Before:
pred = pred.astype(np.bool)
gt = gt.astype(np.bool)
# After:
pred = pred.astype(bool)
gt = gt.astype(bool)
Python's built-in bool is the canonical replacement. np.bool_ can also be used if NumPy scalar type is explicitly required.
References
Affected File
lib/utils/data_utils.py:410-411Current Code
Root Cause
np.boolwas deprecated in NumPy 1.20 and fully removed in NumPy 1.24 (2022-12). In NumPy >= 1.24, usingnp.boolraises:np.boolwas an alias for Python's built-inbool.Impact
inter_from_maskutility function used for intersection computation between prediction and ground-truth masksDependency Chain
Although
requirements.txtdoes not list numpy directly, it is pulled in transitively by every declared dependency:scikit-image==0.19.0numpy>=1.24opencv-pythonnumpy>=2(Python 3.9+)kornianumpy<3(dev extra)imgaugnumpy>=1.15lpipsnumpy>=1.14.3imageio==2.27.0numpyplyfilenumpy>=2.0tensorboardXnumpyThe resolver takes the tightest constraints:
numpy>=2.0(fromplyfileandopencv-python). Any numpy >= 2.0 has already removednp.bool, so this issue is guaranteed to trigger.Solution
Python's built-in
boolis the canonical replacement.np.bool_can also be used if NumPy scalar type is explicitly required.References