【yolo系列:运行报错AttributeError: module ‘torch.nn‘ has no attribute ‘Mish‘】

最近运行yolov7报错AttributeError: module ‘torch.nn‘ has no attribute ‘Mish‘

网上搜罗了一系列的报错方法但是都不怎么好解决,那么在这里给出具体解决方法,以及一些别人的参考文章。

这里先解释自己的,然后再给出别人的相对应的报错。

错误原因:
这个问题的原因是这个版本的torch中的torch.nn函数表里面没有这个Mish函数,需要更高版本的torch,在官方的文档中我们就可以查看这个版本里有没有包含这个模块。这里先教大家如何查看。

首先使用win+r,然后cmd进入管理

在这里面使用你的命令进入自己的虚拟环境
进入的就是你在pycharm解释器里面设置的那个,依次输入以下命令。

activate your_env_name
python
import torch
print(torch.__version__)

【yolo系列:运行报错AttributeError: module ‘torch.nn‘ has no attribute ‘Mish‘】_第1张图片
这样就可以知道自己的torch的版本了,我这里是1.8.1。知道了版本,我们就去官网查看自己的版本是否具有这个模块。
pytorch官网
【yolo系列:运行报错AttributeError: module ‘torch.nn‘ has no attribute ‘Mish‘】_第2张图片
点击左上角的1.13的倒三角
【yolo系列:运行报错AttributeError: module ‘torch.nn‘ has no attribute ‘Mish‘】_第3张图片
选择自己的版本
【yolo系列:运行报错AttributeError: module ‘torch.nn‘ has no attribute ‘Mish‘】_第4张图片
点击进去之后,左上角就会变成1.8.1
【yolo系列:运行报错AttributeError: module ‘torch.nn‘ has no attribute ‘Mish‘】_第5张图片
开始搜索自己报错不存在的模块,比如我这是AttributeError: module ‘torch.nn‘ has no attribute ‘Mish‘我们就搜索什么,然后开始在右边空白处按住ctrl+f,搜索mish,但是这里显示没有,说明torch1.8.1没有mish的模块,于是换torch。
【yolo系列:运行报错AttributeError: module ‘torch.nn‘ has no attribute ‘Mish‘】_第6张图片
搜索1.12.0版本具有mish,所以这里推荐下载1.12.0版本的,也可以下载其他版本,具体的得看你自己缺少的是什么模块,其次就是自己的cuda一定要对应上。
【yolo系列:运行报错AttributeError: module ‘torch.nn‘ has no attribute ‘Mish‘】_第7张图片
这里建议新建一个新的yolo环境,可以参考这个
【yolov系列:小白yolov7跑数据集建立环境】
参考上文自行配置,如果和我的配置一样,可以选择上述文章新建环境,或者是在当前数据环境下,直接安装。
建议新建环境。

pip install torch==1.12.0+cu113 torchvision==0.13.0+cu113 --extra-index-url https://download.pytorch.org/whl/cu113 

然后重新运行即可。

这里也给出其他的同样错误但是不同模块的参考。

AttributeError: module ‘torch.nn‘ has no attribute ‘module‘这篇文章是添加新模块但是字母拼写错误,只要把代码里的nn.module改成nn.Module就好了。

AttributeError: module ‘torch.nn’ has no attribute ‘relu’这篇文章和yolo无关,是调用的错误,没有正确的调用模块。

AttributeError: module ‘torch.nn‘ has no attribute ‘SiLU‘这个文章和我们的错误一样,也是版本错误,具体可以做参考。

AttributeError: module ‘torch.nn’ has no attribute 'LocalResponseNorm’这个也是需要更新torch的版本。
给出更新命令,记录如下。
进入环境

pip3 install http://download.pytorch.org/whl/cpu/torch-0.4.0-cp35-cp35m-win_amd64.whl
pip3 install torchvision

你可能感兴趣的:(yolo系列,#,学习笔记,人工智能,YOLO,深度学习,pytorch)