module 'numpy' has no attribute 'bool'

module 'numpy' has no attribute 'bool'

问题:

Traceback (most recent call last):
File "/home/test.py", line 138, in <module>
inference(args, net, test_save_path)
File "/home/test.py", line 54, in inference
metric_i = test_single_volume(image, label, model, classes=args.num_classes, patch_size=[args.img_size, args.img_size],
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/utils.py", line 90, in test_single_volume
metric_list.append(calculate_metric_percase(prediction == i, label == i))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/utils.py", line 52, in calculate_metric_percase
dice = metric.binary.dc(pred, gt)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/anaconda3/envs/python311/lib/python3.11/site-packages/medpy/metric/binary.py", line 68, in dc
result = numpy.atleast_1d(result.astype(numpy.bool))
^^^^^^^^^^
File "/home/anaconda3/envs/python311/lib/python3.11/site-packages/numpy/__init__.py", line 324, 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. Did you mean: 'bool_'?

原因:

不推荐使用np.boolnp.int等内置类型。在Numpy1.24.0 中不推荐的类型已经完全移除。当使用旧版本的时候就会出现这个问题。

解决:

使用未移除前的版本诸如numpy==1.23.2

pip install numpy==1.23.2
posted @   ben犇  阅读(289)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 一文读懂知识蒸馏
· 终于写完轮子一部分:tcp代理 了,记录一下
点击右上角即可分享
微信分享提示