【python】numpy “AttributeError:’builtin_function_or_method’ object has no attribute ‘randint’”

使用random.randint遇到此问题。查阅相关博文大多都是因为起的名字与"random"重名,若是因为这个原因将对应的.py文件改名即可。但我并没有重名,而且进入random.py也确实有randint()方法。

 

后来发现是引入出了问题:

原因:使用引入是 from random import *

解决:引入换成 import random

Traceback (most recent call last): File "D:\浏览器下载\unet-pytorch-main\unet-pytorch-main\train.py", line 499, in <module> fit_one_epoch(model_train, model, loss_history, eval_callback, optimizer, epoch, File "D:\浏览器下载\unet-pytorch-main\unet-pytorch-main\utils\utils_fit.py", line 153, in fit_one_epoch eval_callback.on_epoch_end(epoch + 1, model_train) File "D:\浏览器下载\unet-pytorch-main\unet-pytorch-main\utils\callbacks.py", line 186, in on_epoch_end _, IoUs, _, _ = compute_mIoU(gt_dir, pred_dir, self.image_ids, self.num_classes, None) # 执行计算mIoU的函数 File "D:\浏览器下载\unet-pytorch-main\unet-pytorch-main\utils\utils_metrics.py", line 124, in compute_mIoU return np.array(hist, np.int), IoUs, PA_Recall, Precision File "E:\Software\anaconda3\envs\JXW\lib\site-packages\numpy\__init__.py", line 305, in __getattr__ ===> mIoU: 49.42; mPA: 50.0; Accuracy: 98.84 raise AttributeError(__former_attrs__[attr]) AttributeError: module 'numpy' has no attribute 'int'. `np.int` was a deprecated alias for the builtin `int`. To avoid this error in existing code, use `int` by itself. Doing this will not modify any behavior and is safe. When replacing `np.int`, you may wish to use e.g. `np.int64` or `np.int32` to specify the precision. If you wish to review your current use, check the release note link for additional information. 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 进程已结束,退出代码为 1
最新发布
03-24
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值