【已解决】AttributeError: module ‘numpy‘ has no attribute ‘int‘.

小明 2025-05-02 09:32:55 7

文章目录

  • 问题详情
  • 问题原因
  • 解决方法
  • 专栏目录:神经网络精讲与实战
  • AlexNet
  • VGGNet
  • GoogLeNet
  • Inception V2——V4
  • ResNet
  • DenseNet
  • SE-ResNet

    问题详情

    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.

    Traceback (most recent call last):
      File "/home/wh/projects/DenseNet_Demo/train_resnet.py", line 17, in 
        from torchtoolbox.transform import Cutout
      File "/home/wh/anaconda3/envs/pytorch39/lib/python3.9/site-packages/torchtoolbox/transform/__init__.py", line 5, in 
        from .autoaugment import *
      File "/home/wh/anaconda3/envs/pytorch39/lib/python3.9/site-packages/torchtoolbox/transform/autoaugment.py", line 194, in 
        Compose([Posterize(0.4, 8), Rotate(0.6, 9)]),
      File "/home/wh/anaconda3/envs/pytorch39/lib/python3.9/site-packages/torchtoolbox/transform/autoaugment.py", line 104, in __init__
        ranges = np.round(np.linspace(8, 4, 10), 0).astype(np.int)
      File "/home/wh/anaconda3/envs/pytorch39/lib/python3.9/site-packages/numpy/__init__.py", line 305, in __getattr__
        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
    

    问题原因

    新版本的numpy里面没有np.int了。

    解决方法

    第一种,降低numpy版本,安装1.20以下的版本。

    pip uninstall numpy
    pip install numpy==1.19.0
    

    第二种,修改源码。

    ranges = np.round(np.linspace(8, 4, 10), 0).astype(np.int)
    

    修改为:

    ranges = np.round(np.linspace(8, 4, 10), 0).astype(int)
    

    如果,对降低numpy版本后,影响到其他的库,可以采用第二种方法。

    专栏目录:神经网络精讲与实战

    这篇文章,是对专栏的总目录,方便大家查看文章。这个专栏我计划整理一些经典常用的主干网络模型,对其进行讲解和实战。由浅入深,逐步增加深度,让大家更容易接受。

    PDF版的文章和实战代码以及数据集,我会放到网盘上,大家在文章的末尾可以看到。

    AlexNet

    第一篇 AlexNet——论文翻译

    第二篇 AlexNet——模型精讲

    第三篇 制作数据集

    第四篇 AlexNet——网络实战

    VGGNet

    第五篇 VGGNet——论文翻译

    第六篇 VGGNet——模型精讲

    第七篇 图像分类的评价指标

    第八篇 VGGNet——网络实战

    GoogLeNet

    第九篇 GoogLeNet——论文翻译

    第十篇 GoogLeNet——模型精讲

    第十一篇 绘图matplotlib.pyplot的使用

    第十二篇 GoogLeNet——网络实战

    Inception V2——V4

    第十三篇 Inception V2——论文翻译

    第十四篇 Inception V3——论文翻译

    第十五篇 Inception V4——论文翻译

    第十六篇 Inception V2、Inception V3、Inception V4模型详解

    第十七篇 PyTorch学习率调整策略

    第十八篇 InceptionV3实战

    ResNet

    第十九篇 ResNet——论文翻译

    第二十篇 ResNet——模型讲解

    第二十一篇 数据增强

    第二十二篇 ResNet实战

    DenseNet

    第二十三篇 DenseNet——论文翻译

    第二十四篇 DenseNet——模型讲解

    第二十五篇 argparse模块

    第二十六篇 DenseNet实战

    SE-ResNet

    第二十七篇 SeNet——论文翻译

    第二十八篇 SeNet模型解析

The End
微信