报错 raise AttributeError(__former_attrs__[attr], name=None) AttributeError: module ‘numpy‘ has no att
报错raise AttributeError(former_attrs[attr], nameNone)AttributeError: module ‘numpy’ has no attribute ‘int’.np.intwas a deprecated alias for the builtinint. To avoid this error in existing code, useintby itself. Doing this will not modify any behavior and is safe. When replacingnp.int, you may wish to use e.g.np.int64ornp.int32to 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原因在 NumPy 1.20 版本之后np.int 被正式弃用了而在 NumPy 2.0 之后这个属性被彻底移除了。代码中使用的 np.int 实际上就是 Python 原生的 int。解决方法修改文件中报错的那几行代码我的是在datasets.py中报错。将bi_rgb np.floor(np.arange(n_rgb) / batch_size).astype(np.int) # batch index改为bi_rgb np.floor(np.arange(n_rgb) / batch_size).astype(int) # 或者用 np.int64可以直接查找.astype(np.int)替换为 .astype(int).astype(np.float) 替换为.astype(float).astype(np.bool) 替换为.astype(bool)注像np.int16, np.int32, np.int64, np.float32, np.uint8这种带有数字后缀的类型全部保留不用修改。只有单独的 np.int, np.float, np.bool 才需要改成 int, float, bool。因为np.int 这种简写被废弃了。而 np.int16 属于 NumPy 的明确精度类型Explicit Precision Types。np.int (报错): 这是 Python 内置 int 的别名NumPy 2.0 删除了它要求直接用 int。np.int16 (正常): 这是 NumPy 特有的 16 位整数类型它在处理图像数据比如像素值 0-255时非常常用在所有 NumPy 版本中都是合法且推荐的。