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

module 'numpy' has no attribute 'bool'的更多相关文章

  1. 【Python 数据分析】module 'numpy' has no attribute 'array'

    安装好Numpy模块后,开始做了几个小测试都可以运行,但是当我创建numpy.py这个文件后 numpy.py import numpy y = numpy.array([[11,4,2],[2,6, ...

  2. Pytorch:module 'torch' has no attribute 'bool'

    Pytorch:module 'torch' has no attribute 'bool' 这个应该是有些版本的Pytorch会遇到这个问题,我用0.4.0版本测试发现torch.bool是有的,但 ...

  3. AttributeError: module 'numpy' has no attribute 'num'

    AttributeError: module 'numpy' has no attribute 'num' 写在前面 总的来说,先看看自己用的计算方式是不是写对了先,多个一起使用的话记得都看看 通过想 ...

  4. Python基础学习-'module' object has no attribute 'urlopen'解决方法

    import numpy as npimport urlliburl = "http://archive.ics.uci.edu/ml/machine-learning-databases/ ...

  5. 解决:pipenv shell报错:AttributeError: 'module' object has no attribute 'run'

    利用pipenv shell切换到虚拟环境时,显示报错:AttributeError: 'module' object has no attribute 'run' 可以看到是d:\program\p ...

  6. module 'cv2' has no attribute 'KNearest_create'

    python版本:3.6.5 opencv版本:3.2.0 使用的是jupyter notebook 源代码如下: import cv2 import numpy as np import matpl ...

  7. python中引入包的时候报错AttributeError: module 'sys' has no attribute 'setdefaultencoding'解决方法?

    python中引入包的时候报错:import unittestimport smtplibimport timeimport osimport sysimp.reload(sys)sys.setdef ...

  8. Python脚本报错AttributeError: ‘module’ object has no attribute’xxx’解决方法

    最近在编写Python脚本过程中遇到一个问题比较奇怪:Python脚本完全正常没问题,但执行总报错"AttributeError: 'module' object has no attrib ...

  9. attributeError:'module' object has no attribute ** 解决办法

    写了一个小脚本,执行的时候报错: Traceback (most recent call last): File "F:/test/qrcode.py", line 109, in ...

  10. AttributeError: 'module' object has no attribute 'TornadoAsyncNotifier'

    /*************************************************************************** * AttributeError: 'modu ...

随机推荐

  1. 【Android】使用AIDL实现进程间传递对象案例

    1 前言 ​ 在 Android--使用AIDL实现进程间通讯简单案例 中介绍了使用 AIDL 在进程间传递字符串,对于8种基本数据类型( byte.short.int.long.float.doub ...

  2. SpringCloud Config配置中心实战

    介绍 本文以理论结合实践编写,篇幅较长,各位看官保持耐心:),部分内容引用自网络. 什么是配置中心? 当微服务过多的时候,每个微服务的配置很难集中管理.SpringCloud Config通过git代 ...

  3. Java并发编程实例--14.在一个同步类中安排独立属性

    当你使用synchronized关键字去保护一个代码块时,你必须传入一个对象的引用. 正常来讲,你讲使用this关键字去引用执行这个方法的对象,但是你可以使用其他对象的引用. 通常的,这些对象将会是专 ...

  4. Java并发编程实例--20.使用Semaphores(信号量)控制资源的并发读取

    前面我们介绍了2种同步机制: 1)使用synchronized关键字 2)使用Lock接口及其实现类: ReentrantLock,ReentrantReadWriteLock.ReadLock, a ...

  5. pycharm—flask创建简单web项目

    1.系统 系统 版本 OS win 10 pycharm 专业版2022.3.1 2.引入flask包 pip install flask 3.项目目录展示.代码.浏览器访问 from flask i ...

  6. MASM32 - PlaySound的实现

    MASM安装教程: https://blog.csdn.net/u010486308/article/details/105495848 代码参考: .model flat, stdcall opti ...

  7. RAID 10磁盘阵列实践

    RAID概述 RAID技术通过把多个硬盘设备组合成一个容量更大.安全性更好的磁盘阵列,利用分散读写技术来提升磁盘阵列整体的性能,同时把多个重要数据的副本同步到不同的物理硬盘设备上,从而起到了非常好的数 ...

  8. OkHttp 拦截器的一些操作

    OkHttp 拦截器的一些操作  转自:  https://blog.csdn.net/songzi1228/article/details/116782794

  9. 项目实战:Qt+OSG三维点云引擎(支持原点,缩放,单独轴或者组合多轴拽拖旋转,支持导入点云文件)

    需求   开发基于osg的三维点云引擎模块.  1.基于x,y,z坐标轴.  2.可设置原点,设置缩放比例.  3.可设置y轴和z轴单位.  4.三轴中,XY为2D图的水平.竖直方向:Z轴,对应高度图 ...

  10. linux下MariaDB安装

    一条命令安装Mariadb 首先在/etc/yum.repos.d下创建一个MariaDB.repo文件 vim /etc/yum.repos.d/MariaDB.repo 添加以下配置 [maria ...