首页 > 其他分享 >module 'numpy' has no attribute 'bool'

module 'numpy' has no attribute 'bool'

时间:2024-03-15 21:36:27浏览次数:19  
标签:attribute metric py bool home line numpy

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

标签:attribute,metric,py,bool,home,line,numpy
From: https://www.cnblogs.com/benbenlzw/p/18076269

相关文章

  • numpy中random.seed()与random.RandomState()的区别
    1.random.seed()用处:初始化随机数生成器。设置随机数生成器种子后,直接生成随机数即可,无需在随机数生成器条件下运行。2.random.RandomState()作用:获得随机数生成器 比较上面两图可以看出,获取随机数生成器之后,必须在此条件下运行,才可生成相同的随机数,若不在此条件下运行,随......
  • LoggerMessageAttribute 高性能的日志记录
    .NET6引入了LoggerMessageAttribute类型。使用时,它会以source-generators的方式生成高性能的日志记录API。source-generators可在编译代码时,可以提供其他源代码作为编译的输入。LoggerMessageAttribute依赖于ILogger接口和LoggerMessage.Define功能。在partial日......
  • 【ArcPy】矢量数据与Numpy数组互转
    代码importarcpyinputshp=r"C:\Users\admin\Desktop\excelfile\0.shp"outputshp=r"C:\Users\admin\Desktop\excelfile\copy02.shp"spatial_ref=arcpy.Describe(inputshp).spatialReferencearr=arcpy.da.FeatureClassToNumPyArray(in......
  • c++函数SetConsoleTextAttribute
    前言正文1.作用:2.函数格式(重点):3.参数(重点):前言实用(真的)正文1.作用:更改cmd的背景色与字体颜色2.函数格式(重点):SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),10进制参数);3.参数(重点): ......
  • numpy中比较两个数字的断言函数
    比如在比较torch模型输出和onnxruntime输出,importonnxruntimeort_session=onnxruntime.InferenceSession("super_resolution.onnx",providers=["CPUExecutionProvider"])defto_numpy(tensor):returntensor.detach().cpu().numpy()iftensor.requires_g......
  • Failed to populate field: ‘String‘ object has no attribute
    ROS2中我们使用编译topicpub如上报错时,可以考虑检查一下命令行是否书写错误,这里我的问题是ros2topicpub/chatterstd_msgs/msg/String'data:"123"':和"之间少打了一个空格发生报错,改正后可以正常打印,问题解决ros2topicpubarg手动发布命令......
  • 超详细的Numpy基础教程!!!
    Numpy是一个开源的Python库,用于支持大型多维数组和矩阵运算,同时提供了大量的数学函数库。它是科学计算中非常重要的工具。Numpy在数据科学中非常重要,因为它提供了高效的数组处理能力和广泛的数学函数库,这对于处理大规模数据集、进行科学计算和机器学习等任务至关重要。一、安......
  • Attribute GetCustomAttribute via method info of type
    [AttributeUsage(AttributeTargets.Method)]publicsealedclassTestAttribute:Attribute{publicintRepetitions;publicstringFailureMessage;publicTestAttribute():this(1){}publicTestAttribute(intrepetitions){......
  • 09-NumPy-基础
    一.NumPy介绍1.介绍NumPy(NumericalPython)是Python的一个开源的数值计算库。可用来存储和处理大型矩阵,比Python自身的嵌套列表结构要高效的多,支持大量的维度数组与矩阵运算,此外也针对数组运算提供大量的数学函数库,包括数学、逻辑、形状操作、排序、选择、输入输出、离散......
  • day02_homework_while循环_bool值计算
    !/usr/bin/envpython--coding:utf-8--@File:day02_homework.py猜数字,设定一个理想数字比如:66,让用户输入数字,如果比66大,则显示猜测的结果大了;如果比66小,则显示猜测的结果小了;只有等于66,显示猜测结果正确,然后退出循环。实现功能1"""luck_number=66whileTrue:guass......