在使用medpy包计算HD距离时, 报错
from medpy.metric import binary
hd95 = binary.hd95(img_predict, img_label) # img_predict 和 img_label 是预测和GT mask
# 报错如下
File "/data/demo/anaconda3/envs/py39/lib/python3.9/site-packages/medpy/metric/binary.py", line 396, in hd95hd1 = __surface_distances(result, reference, voxelspacing, connectivity)File "/data/demo/anaconda3/envs/py39/lib/python3.9/site-packages/medpy/metric/binary.py", line 1200, in __surface_distancesresult = numpy.atleast_1d(result.astype(numpy.bool))File "/data/demo/anaconda3/envs/py39/lib/python3.9/site-packages/numpy/__init__.py", line 305, in __getattr__raise AttributeError(__former_attrs__[attr])
AttributeError: module 'numpy' has no attribute 'bool'.
`np.bool` was a deprecated alias for the builtin `bool`. To avoid this error in existing code, use `bool` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.bool_` here.
The aliases was originally deprecated in NumPy 1.20; for more details and guidance see the original release note at:https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
解决办法:
跳转到报错代码result = numpy.atleast_1d(result.astype(numpy.bool))中, 修改代码如下即可:
“”“
原先报错代码
result = numpy.atleast_1d(result.astype(numpy.bool))
reference = numpy.atleast_1d(reference.astype(numpy.bool))
”“”# 修改后代码
result = numpy.atleast_1d(result.astype(numpy.bool_))
reference = numpy.atleast_1d(reference.astype(numpy.bool_))